-
-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read blob in nodejs #437
Comments
Hmm, i quite like what you are doing but i would like a un-opinionated layer of the magic number - kind of how mime-db is to mime. mime-db is just pure JSON and dose not contain any logic to remain as un-opinionated as possible. and mime adds a api layer on top of it. Not saying you have to go and make some new npm module called magic-db or something - just a json file within your project would also be enough so one could do |
As you also correctly indicated, at the very beginning in the dependency tree: Borewit/token-types#245, I propose to investigate the suggestion starting from there.
Sounds interesting as well.
That would suite those file type detections based on simple magic number. |
Nodejs have introduced buffer.Blob and we are about to get them from fs soon also
but they have not introduced the FileReader and likely never will. cuz there are some new file reading methods on the blob now with
.stream()
,.arrayBuffer()
, and.text()
that can return promisesso i was thinking maybe you could replace this hole function and just use
blob.arrayBuffer()
instead and maybe polyfillblob.prototype.arrayBuffer()
if it dose not existfile-type/browser.js
Lines 18 to 45 in 2cc0869
I have also another concern, is it really necessary to read the hole blob into memory?
isn't the first and last 1000 bytes or something only needed?
it would seem more efficient to do something like:
I would aslo suggest that you use Uint8Array, ArrayBuffer and DataView instead of using nodes Buffer as that would lower the browser bundle and not drag in any of nodes core modules.
I would also suggest that you make your
fromStream
method acceptable of a AsyncIterator that yields Uint8Arrays instead of relying on either node streams or whatwg streams or nodes EventEmitter since it could lower the bundle even a lot furthersince node stream are already async iterable. and whatwg streams are too but no browser have implemented it.
The text was updated successfully, but these errors were encountered: