feat: web idl like features
undici is considering using busboy as a mean to decode multipart formdata payloads as a way to resolve body.formData(),
I have made the FileStream behave almost the same way a standard window.File object to make working with files much more easier, by giving the FileStream some extra features.
FileStream.prototype.nameto resemble what webFile.prototype.nameidl class looks likeFileStream.prototype.typeto resemble what webFile.prototype.typeidl class looks likeFileStream.prototype.stream()to resemble what webFile.prototype.stream()idl class looks likeFileStream.prototype.text()to resemble what webFile.prototype.stream()idl class looks like
it will decode the file pretty much the same way asresponse.text()&file.text()(by also removing BOM)FileStream.prototype.blob( optional_blob_class )returns a promise solving to a blob \w typeFileStream.prototype.file( optional_file_class )returns a promise solving to a file \w type & filename
with this we can now do something like:
bb.on('file', async (fieldName, fileStream) => {
await fileStream.text()
await fileStream.arrayBuffer()
await fileStream.blob( optionalBlobClass )
await fileStream.file( optionalFileClass )
fileStream.stream() // returns a web stream
fileStream.name // the file name
fileStream.type // the mime type
})
Accepting this changes would help us at undici and node-fetch tremendously by bringing await body.formData() to life in in a much more easier way. You would not only be helping a few ppl by accepting this. I think you could take proud in that it would also land in NodeJS core and node-fetch that is downloaded by million of other users every week
this kindof closes my wishes over at #228
more and more ppl are asking for a decoder builtin to fetch itself: https://togithub.com/nodejs/undici/issues/974 (you should read this)
I'm not really interested in adding and maintaining this kind of "web compatibility" at this time. If downstream users of busboy want to add that on top, then more power to them.