busboy icon indicating copy to clipboard operation
busboy copied to clipboard

feat: web idl like features

Open jimmywarting opened this issue 3 years ago • 1 comments

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.name to resemble what web File.prototype.name idl class looks like
  • FileStream.prototype.type to resemble what web File.prototype.type idl class looks like
  • FileStream.prototype.stream() to resemble what web File.prototype.stream() idl class looks like
  • FileStream.prototype.text() to resemble what web File.prototype.stream() idl class looks like
    it will decode the file pretty much the same way as response.text() & file.text() (by also removing BOM)
  • FileStream.prototype.blob( optional_blob_class ) returns a promise solving to a blob \w type
  • FileStream.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

jimmywarting avatar Jul 14 '22 15:07 jimmywarting

more and more ppl are asking for a decoder builtin to fetch itself: https://togithub.com/nodejs/undici/issues/974 (you should read this)

jimmywarting avatar Aug 09 '22 16:08 jimmywarting

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.

mscdex avatar Apr 08 '23 15:04 mscdex