jaydenseric / extract-files

A function to recursively extract files and their object paths within a value, replacing them with null in a deep clone without mutating the original value. FileList instances are treated as File instance arrays. Files are typically File and Blob instances.
https://npm.im/extract-files
MIT License
56 stars 23 forks source link

Add blob support #27

Closed azimgd closed 2 years ago

jaydenseric commented 2 years ago

Thanks for your interest in contributing to this project :)

Adding Buffer to the list of extractables is not something we'll do out of the box, for now at least. People are able to make their own function isExtractable for use with the function extractFiles to match Buffer instances, or any other custom things.

airhorns commented 2 years ago

Hey @jaydenseric what makes Buffer unsuitable for inclusion by default? It makes extract-files that much more compatible with node which is a positive in my mind! Is there some key downside that merits making users customize the isExtractable function when in node all the time?

jaydenseric commented 2 years ago

@airhorns

It's good to align as much as possible to a universal JavaScript philosophy and stick to standard globals like Blob, File, etc.

airhorns commented 2 years ago

Right, I understand! Node doesn't have a File global but it does have a Blob global as of v16, though I think the vast majority of the code that works with files in node will work with them using Buffers. I see the minimalism argument you're making, and yeah by coupling to the browser env you get automatic Deno compatability, but, there sure are a lot of node users out there already. It seems annoying to make those server side users spend their time running into this issue, discover how to customize, and succeed at the customization to save a few bytes and to call node out on its decidedly not-browser-esque API. I think if you wanted, I could probably code golf the change into fewer bytes than are used on master right now, but I get the sense that's not the biggest issue, I am just a maximalist I guess!