Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport FileAPI to 16.x #45763

Closed
ThisIsMissEm opened this issue Dec 6, 2022 · 7 comments
Closed

Backport FileAPI to 16.x #45763

ThisIsMissEm opened this issue Dec 6, 2022 · 7 comments
Labels
feature request Issues that request new features to be added to Node.js. stale

Comments

@ThisIsMissEm
Copy link

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.js needs the Blob constructor set on globalThis to pass.
  • Some unusual arguments to File don't work, due to them also not working with Blob in 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)

@ThisIsMissEm ThisIsMissEm added the feature request Issues that request new features to be added to Node.js. label Dec 6, 2022
@ThisIsMissEm
Copy link
Author

I've opened a draft pull request showing this being backported to v16.x here: #45764

@KhafraDev
Copy link
Member

As an alternative, undici exports a spec compliant File class. The only difference is that setting a type is stricter than Blob or node's File.

const { File } = require('undici')

@ThisIsMissEm
Copy link
Author

@KhafraDev oh! I didn't know about this! I must've missed it at some point.

@ThisIsMissEm
Copy link
Author

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
Copy link
Member

We should definitely document it.

@github-actions
Copy link
Contributor

github-actions bot commented 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.

@github-actions github-actions bot added the stale label Jun 6, 2023
@ThisIsMissEm
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. stale
Projects
Status: Pending Triage
Development

No branches or pull requests

2 participants