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
Question: Who and why uses Blob on Node.JS #835
Comments
You can, for example, request binary files like images as blobs. |
@Richienb Yeah, I can image some examples, but I'm looking for real-world applications, as an open-source library, etc... |
Guess there isn't really any huge real-world use for it today, have seen someone using it doe. Deno have it built in but it is mostly just a wrapper around some arraybuffer i guess The purpose of having a blob is mostly just to
I recommend you to read this There is also some feature request about implementing blob & blobStorage in node. Understanding the usefulness of Blobs and how they really work under the hood can boost your performance
fetch-blob isn't perfect either, there is actually many parts it dose "wrong", if you want to slice a blob then you shouldn't really allocate a new buffer with the new data. the underlying source should not be one buffer, it should really be an array of blob parts with new offsets. more like this File-like http reader having blob's in formdata with a pointer to the filesystem makes a tremendous memory boost and helps us read/serialize data in a "standard" way when you make request. |
imagine how you would go about solving this: const File = require('fetch-file') // creates a FIle-like IDL wrapper around fs
const Blob = require('fetch-blob')
const file = File.from('./package.json')
new Blob([ file ]) the blob's constructor spec says:
2.3 don't say read the the blob and copy the content to a new instance. Beside the fetch-blob can't read the content of the File in a synchronous way to be able to successfully handle the blob parts. so the slicing method is also wrong, it should not when you take 2x2 GiB of files from a |
@jimmywarting That said, current |
Mostly yes, but not entirely - there is room for improvements to make it more useful but it would be best if we got native support for blob/files instead to get a "single source of truth" Those who use it now days just want to be Isomorphic There could be a other blob polyfill that could handle
There is also the lack of ObjectURLs in node. you can't display them in some image or video tag. but they can still be useful for workers: eg like node-fetch can't read objectURL's either since BlobStore don't exist. |
@Gozala @mattlubner @avaer maybe wants to share what they use blobs for, they have asked us to expose the blob class |
I'm using e.g. we have some functions that returns res.writeHead(200, { 'Content-Type': blob.type })
blob.stream().pipe(res) |
You can see this comment on #392, which explains my use case. tl;dr: We need the exact constructor used by In general, I feel that all libraries which return objects that extend internally-defined classes aught to export those classes in some manner, if for no other reason than to support robust testing. Btw, I'm pretty sure @Gozala's use case can be inferred from this comment. |
if we got FetchEvent implemented (#370) and some kind of simplified server then i would have started to use blob's in node a lite bit more. almost like @LinusU did something in lines of this const File = require('fetch-file')
// A reusable blob that don't hold anything in memory
// but is re-readable thanks to the new .stream()
const index = File.from('./static/index.html')
globalThis.onfetch(event => {
// content-type, content-length all taken care of by node-fetch
event.respondWith(new Response(index))
})
http.createServer((req, res) => {
dispatch_to_nodeFetch_as_fetch_event(req, res)
}) Essentially creating a little mini service worker |
I don't like something sticking with Node.JS const store = asyncLocalStorage.getStore();
store.onfetch(event => {
/*.. */
}); |
I have no exact idea of how we go about register a listener to the not sure how AsyncLocalStorage fits in...? I'm also wondering a bit about what would happen if two modules uses node-fetch and it dose request, would you want to listen to all request that are going on or would you want to instantiate something by calling Anyhow, lets move the discussion about FetchEvent into #370 |
Hello,
I'm trying to find a real-world example of using Blob response type in Node.JS project/library.
Does anybody know any example of existing library or project that benefits of Blob in Node?
The text was updated successfully, but these errors were encountered: