-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Implement File class #39015
Copy link
Copy link
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I think a File class would be useful to implement also, it's a quite simple class that only extends Blob with two properties
nameandlastModified, it dose not have to do much else beside also being transferable.File is a fundamental building block for aligning with more Web Platform APIs such as FormData, native File System Access and even
node:fsitself... the simplast solution to save it beingawait fsPromises.writeFile(path, blob.stream())as it supports async iterable streamsA step in appending a blob to FormData is to convert blobs to a File instance (to give it a name) and make it possible to serialize the FormData when you iterate over all entries. Or getting a entry with
formData.get(field)FormData is a desired tool for all those folks who wants to see support for window.fetch in core
fetch-blob just added a File class as well, we saw many ppl extending fetch-blob with a own File class and wanted to remove that burdan for everyone so everybody could use the same instances instead.
Therefore we also added a utility fn that could create a File from a path. fileFrom(path, [mimetype]) and fileFromSync(path, [mimetype]) which i hope to see being implemented into
fsone day (#37340).(in fetch-blob it first create a BlobDataItem (that is similar to what a Blob looks like but don't read anything into memory, it backed up by the filesystem instead) and then wrap it with a File class
new File([BlobDataItem], name, { type }))