Repository navigation
Backport FileAPI to 16.x #45763
Description
What is the problem this feature will solve?
In 16.x we have the Blob constructor, and in #45139, support for the File API was introduced. It'd be wonderful if this could be backported to v16.x, this would help us by meaning we could not use a polyfill on Node.js 16.x (we'd have to polyfill of shim at the moment).
From what I can tell, the backport is possible, but with a few minor caveats:
- Blob isn't yet global in v16.x, so the
test/wpt/test-file.jsneeds theBlobconstructor set onglobalThisto pass. - Some unusual arguments to
Filedon't work, due to them also not working withBlobin v16.x (see below)
Unusual arguments: The file at test/wpt/status/FileAPI/file.json needed the following expected failures added, as these are also expected failures in the Blob WPT in v16.x
"File-constructor.any.js": {
"fail": {
"note": "Depends on Blob API",
"expected": [
"Unusual but valid property bag: null",
"Unusual but valid property bag: 1,2,3",
"Unusual but valid property bag: function() {}"
]
}
},
What is the feature you are proposing to solve the problem?
This is a backport of a new feature in 19.x to 16.x, and would provide an new API that would be usable with undici's fetch in 16.x (we've a module that shims node.js 18's fetch and undici's fetch on 16.x, but also need the File constructor to simplify our API which current has to accept either a Buffer or a Blob, and those constructors behave pretty differently.
What alternatives have you considered?
We could also shim the File API in 16.x, just like we shim the fetch API, though the File constructor doesn't really exist as a good third-party/user-land module (due to how it extends built-ins)
Activity
ThisIsMissEm commentedon Dec 6, 2022
I've opened a draft pull request showing this being backported to v16.x here: #45764
KhafraDev commentedon Dec 7, 2022
As an alternative, undici exports a spec compliant File class. The only difference is that setting a
typeis stricter than Blob or node's File.ThisIsMissEm commentedon Dec 7, 2022
@KhafraDev oh! I didn't know about this! I must've missed it at some point.
ThisIsMissEm commentedon Dec 7, 2022
Looks like it's not explicitly documented, so I'd be a little hesitant to use it. But maybe that's just a docs fix for undici
KhafraDev commentedon Dec 7, 2022
We should definitely document it.
github-actions commentedon Jun 6, 2023
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
ThisIsMissEm commentedon Jun 6, 2023
I'm gunna close this out since I no longer work for the company that had the problem and I believe they've found another way.