You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+64-13Lines changed: 64 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -13,18 +13,66 @@ A Blob implementation in Node.js, originally from [node-fetch](https://github.co
13
13
npm install fetch-blob
14
14
```
15
15
16
+
<details>
17
+
<summary>Upgrading from 2x to 3x</summary>
18
+
19
+
Updating from 2 to 3 should be a breeze since there is not many changes to the blob specification.
20
+
The major cause of a major release is coding standards.
21
+
- internal WeakMaps was replaced with private fields
22
+
- internal Buffer.from was replaced with TextEncoder/Decoder
23
+
- internal buffers was replaced with Uint8Arrays
24
+
- CommonJS was replaced with ESM
25
+
- The node stream returned by calling `blob.stream()` was replaced with a simple generator function that yields Uint8Array (Breaking change)
26
+
27
+
The reasoning behind `Blob.prototype.stream()` is that node readable stream
28
+
isn't spec compatible with whatwg stream and we didn't want to import a hole whatwg stream polyfill for node
29
+
or browserify hole node-stream for browsers and picking any flavor over the other. So we decided to opted out
30
+
of any stream and just implement the bear minium of what both streams have in common which is the asyncIterator
31
+
that both yields Uint8Array. It would be redundant to convert anything to whatwg streams and than convert it back to
32
+
node streams since you work inside of Node.
33
+
It will probably stay like this until nodejs get native support for whatwg<sup>[1][https://github.com/nodejs/whatwg-stream]</sup> streams and whatwg stream add the node
34
+
equivalent for `Readable.from(iterable)`<sup>[2](https://github.com/whatwg/streams/issues/1018)</sup>
35
+
36
+
But for now if you really want/need a Node Stream then you can do so using this transformation
37
+
```js
38
+
import {Readable} from'stream'
39
+
conststream=Readable.from(blob.stream())
40
+
```
41
+
But if you don't need it to be a stream then you can just use the asyncIterator part of it that both whatwg stream and node stream have in common
42
+
```js
43
+
forawait (constchunkofblob.stream()) {
44
+
console.log(chunk) // uInt8Array
45
+
}
46
+
```
47
+
48
+
All of this changes have made it dependency free of any core node modules, so it would be possible to just import it using http-import from a CDN without any bundling
0 commit comments