Skip to content

Backport FileAPI to 16.x #45763

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)

Activity

  1. ThisIsMissEm commented on Dec 6, 2022

    @ThisIsMissEm
    Author

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

  2. KhafraDev commented on Dec 7, 2022

    @KhafraDev
    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')
  3. ThisIsMissEm commented on Dec 7, 2022

    @ThisIsMissEm
    Author

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

  4. ThisIsMissEm commented on Dec 7, 2022

    @ThisIsMissEm
    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

  5. KhafraDev commented on Dec 7, 2022

    @KhafraDev
    Member

    We should definitely document it.

  6. github-actions commented on Jun 6, 2023

    @github-actions
    Contributor

    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.

  7. added
    staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.
    on Jun 6, 2023
  8. ThisIsMissEm commented on Jun 6, 2023

    @ThisIsMissEm
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions