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
+6-48
Original file line number
Diff line number
Diff line change
@@ -22,10 +22,8 @@ npm install fetch-blob
22
22
- internal Buffer.from was replaced with TextEncoder/Decoder
23
23
- internal buffers was replaced with Uint8Arrays
24
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
-
(Read "Differences from other blobs" for more info.)
27
-
28
-
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
25
+
- The node stream returned by calling `blob.stream()` was replaced with whatwg streams
26
+
- (Read "Differences from other blobs" for more info.)
29
27
30
28
</details>
31
29
@@ -36,48 +34,12 @@ npm install fetch-blob
36
34
- This blob version is more arbitrary, it can be constructed with blob parts that isn't a instance of itself
37
35
it has to look and behave as a blob to be accepted as a blob part.
38
36
- The benefit of this is that you can create other types of blobs that don't contain any internal data that has to be read in other ways, such as the `BlobDataItem` created in `from.js` that wraps a file path into a blob-like item and read lazily (nodejs plans to [implement this][fs-blobs] as well)
39
-
- The `blob.stream()` is the most noticeable differences. It returns a AsyncGeneratorFunction that yields Uint8Arrays
40
-
41
-
The reasoning behind `Blob.prototype.stream()` is that NodeJS readable stream
42
-
isn't spec compatible with whatwg streams and we didn't want to import the hole whatwg stream polyfill for node
43
-
or browserify NodeJS streams for the browsers and picking any flavor over the other. So we decided to opted out
44
-
of any stream and just implement the bear minium of what both streams have in common which is the asyncIterator
45
-
that both yields Uint8Array. this is the most isomorphic way with the use of `for-await-of` loops.
46
-
It would be redundant to convert anything to whatwg streams and than convert it back to
47
-
node streams since you work inside of Node.
48
-
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
49
-
equivalent for `Readable.from(iterable)`<sup>[2](https://github.com/whatwg/streams/issues/1018)</sup>
50
-
51
-
But for now if you really need a Node Stream then you can do so using this transformation
37
+
- The `blob.stream()` is the most noticeable differences. It returns a WHATWG stream now. to keep it as a node stream you would have to do:
38
+
52
39
```js
53
40
import {Readable} from'stream'
54
41
conststream=Readable.from(blob.stream())
55
42
```
56
-
But if you don't need it to be a stream then you can just use the asyncIterator part of it that is isomorphic.
57
-
```js
58
-
forawait (constchunkofblob.stream()) {
59
-
console.log(chunk) // uInt8Array
60
-
}
61
-
```
62
-
If you need to make some feature detection to fix this different behavior
63
-
```js
64
-
if (Blob.prototype.stream?.constructor?.name==='AsyncGeneratorFunction') {
65
-
// not spec compatible, monkey patch it...
66
-
// (Alternative you could extend the Blob and use super.stream())
thrownewDOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.','NotReadableError');
0 commit comments