Skip to content

Backport FileAPI to 16.x #45763

Closed
Closed
@ThisIsMissEm

Description

@ThisIsMissEm

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.stale

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions