Title: Support async Blob sources · Issue #37338 · nodejs/node · GitHub
Open Graph Title: Support async Blob sources · Issue #37338 · nodejs/node
X Title: Support async Blob sources · Issue #37338 · nodejs/node
Description: The terminology "async Blob source" was mention earlier[1] I think it means in chromes world a "BlobDataItem" BlobDataItem: This is a primitive element that can basically be a File, Bytes, or another Blob. It also stores an offset and si...
Open Graph Description: The terminology "async Blob source" was mention earlier[1] I think it means in chromes world a "BlobDataItem" BlobDataItem: This is a primitive element that can basically be a File, Bytes, or anoth...
X Description: The terminology "async Blob source" was mention earlier[1] I think it means in chromes world a "BlobDataItem" BlobDataItem: This is a primitive element that can basically be a F...
Opengraph URL: https://github.com/nodejs/node/issues/37338
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support async Blob sources","articleBody":"The terminology \"async Blob source\" was mention earlier\u003csup>[[1]](https://github.com/nodejs/node/issues/19393#issuecomment-777580429)\u003c/sup> I think it means in chromes world a \"BlobDataItem\"\r\n\r\n> **BlobDataItem**: This is a primitive element that can basically be a File, Bytes, or another Blob. It also stores an offset and size, so this can be a part of a file. (This can also represent a “future” file and “future” bytes, which is used to signify a bytes or file item that has not been transported yet).\u003cbr>https://chromium.googlesource.com/chromium/src/+/master/storage/browser/blob/README.md\r\n\r\n- In simple terms it can be a Blob that comes from other places like the filesystem that don't have the data (source) in the memory.\r\n- It's basically a dummy blob that have a point reference to some file on the hard drive with an offset of where to start and stop reading from\r\n- Or it can be a slice of another blob, with a new offset.\r\n\r\n---\r\n\r\n```js\r\n// if you create a blob\r\nconst blobA = new Blob([new ArrayBuffer(20_000)])\r\n// and slice it\r\nconst blobB = blobA.slice(0, 10_000)\r\n```\r\n- ...Then we shouldn't create a new blob and allocated 30.000 bytes for both `blobA` and `blobB` it should still only be 20.000 bytes\r\n- `blobB` should be a reference to `blobA` with another offset from 0 to 10_000 and shouldn't allocate any new buffer\r\n - so when we are reading blobB then it creates a readable stream on blobA that reads bytes 0-10000\r\n\r\n---\r\n\r\nAnd if we create a 3rd blob `blobC = new Blob([blobB, blobB])`\r\n- Then `blobC` will just have two reference to blobB (witch actually refers to two slices of blobA). And reading this blobC will be like if we created two readable streams and read them one after the other\u003cbr>`blobC.stream() === [blobB.stream(), blobB.stream()]`\r\n```js\r\n// this pseudo code can be a bit off (wrong) but it can explain what i mean\r\nblobB.stream = () => new streams.Readable.from(function* () {\r\n yield* blobA[kSource].slice(0, 10000)\r\n})\r\n\r\nblobC.stream = () => new streams.Readable.from(function* () {\r\n yield* blobB.stream()\r\n yield* blobB.stream()\r\n})\r\n\r\n// A better way is if blobC can have direct reference to the internal\r\n// blob parts to blobA so blobB can be garbage collected\r\n```\r\n\r\nin this case both `blobB` and `BlobC` would not have any underlying source that holds the data in memory. this would only be (nested) references to blobA\r\n\r\nGuess this is some important steps towards solving async blob sources and mixing both blobs that could come from the `fs` and mixed with blobs constructed with data from the memory\r\n\r\nI created something like this async sources in [fetch-blob](https://github.com/node-fetch/fetch-blob/blob/master/index.js) and also a kind of [BlobDataItem](https://github.com/node-fetch/fetch-blob/blob/master/from.js) that was backed up by the filesystem and didn't hold anything in the memory. I have totally manage to solve this slicing stuff in a synchronous way and also constructing new blobs with other parts. the only thing that is async is how it reads the data. My blob is constructed with a sequence of blob parts (with offsets of other parts) (not a single source like a full ArrayBuffer containing all data). \r\n\r\nThat is how it can manage to take any other instance of a Blob class that isn't our own and knowing nothing about the internal source of the other blob. So you can construct fetch-blob with something that looks and behaves like any other Blob. it could for instance accept a BlobDataItem from the `fs` and also `buffer.Blob`\r\n\r\nnote that a blob from fs should keep track of last modified time and if it isn't the same when you are reading, then the internal stream should throw a error","author":{"url":"https://github.com/jimmywarting","@type":"Person","name":"jimmywarting"},"datePublished":"2021-02-12T23:28:03Z","url":"https://github.com/nodejs/node/issues/37338"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f3c448eb-7d31-9ff6-27ee-f9f5c56d5b79 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C75A:3CEA01:1C15834:24C9FC0:6B0987BC |
| html-safe-nonce | 0987c88ad91b86ac24e587ab4f43e043f827e7774373f462f06f62dc5d668031 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzVBOjNDRUEwMToxQzE1ODM0OjI0QzlGQzA6NkIwOTg3QkMiLCJ2aXNpdG9yX2lkIjoiOTA3NzU2MzQxNzk4NDMzNzg1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2c86549af1bea6eaab1852e1771ec6a12caefa691efdf67442ee1348f2796814 |
| hovercard-subject-tag | issue:807611971 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/37338/issue_layout |
| twitter:image | https://opengraph.githubassets.com/587144a31f305b31ac34076cf0502de24a9fea592ad4b6262382b6a397634ed5/nodejs/node/issues/37338 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/587144a31f305b31ac34076cf0502de24a9fea592ad4b6262382b6a397634ed5/nodejs/node/issues/37338 |
| og:image:alt | The terminology "async Blob source" was mention earlier[1] I think it means in chromes world a "BlobDataItem" BlobDataItem: This is a primitive element that can basically be a File, Bytes, or anoth... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jimmywarting |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7979c7f5a22f0d2888cd797df0df5d946c8c8609941ab6be35588d3fff39c86e |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d82818ecaa19047a8735708a7f4ba2ab4eb8df16 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width