Description
I think a File class would be useful to implement also, it's a quite simple class that only extends Blob with two properties name
and lastModified
, 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:fs
itself... the simplast solution to save it being await fsPromises.writeFile(path, blob.stream())
as it supports async iterable streams
A 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 fs
one 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 })
)