@yume-chan/stream-extra 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +33 -21
- package/CHANGELOG.md +8 -2
- package/README.md +1 -1
- package/esm/buffered-transform.d.ts +11 -10
- package/esm/buffered-transform.d.ts.map +1 -1
- package/esm/buffered-transform.js +55 -55
- package/esm/buffered-transform.js.map +1 -1
- package/esm/buffered.d.ts +29 -27
- package/esm/buffered.d.ts.map +1 -1
- package/esm/buffered.js +128 -123
- package/esm/buffered.js.map +1 -1
- package/esm/chunk.d.ts +7 -4
- package/esm/chunk.d.ts.map +1 -1
- package/esm/chunk.js +48 -7
- package/esm/chunk.js.map +1 -1
- package/esm/consumable.d.ts +53 -0
- package/esm/consumable.d.ts.map +1 -0
- package/esm/consumable.js +178 -0
- package/esm/consumable.js.map +1 -0
- package/esm/decode-utf8.d.ts +4 -4
- package/esm/decode-utf8.js +11 -11
- package/esm/distribution.d.ts +24 -0
- package/esm/distribution.d.ts.map +1 -0
- package/esm/distribution.js +99 -0
- package/esm/distribution.js.map +1 -0
- package/esm/duplex.d.ts +48 -47
- package/esm/duplex.d.ts.map +1 -1
- package/esm/duplex.js +90 -92
- package/esm/duplex.js.map +1 -1
- package/esm/gather-string.d.ts +6 -6
- package/esm/gather-string.d.ts.map +1 -1
- package/esm/gather-string.js +15 -13
- package/esm/gather-string.js.map +1 -1
- package/esm/index.d.ts +16 -15
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +16 -15
- package/esm/index.js.map +1 -1
- package/esm/inspect.d.ts +4 -4
- package/esm/inspect.js +11 -11
- package/esm/pipe-from.d.ts +12 -11
- package/esm/pipe-from.d.ts.map +1 -1
- package/esm/pipe-from.js +23 -25
- package/esm/pipe-from.js.map +1 -1
- package/esm/push-readable.d.ts +19 -18
- package/esm/push-readable.d.ts.map +1 -1
- package/esm/push-readable.js +61 -61
- package/esm/push-readable.js.map +1 -1
- package/esm/split-string.d.ts +4 -4
- package/esm/split-string.d.ts.map +1 -1
- package/esm/split-string.js +24 -24
- package/esm/split-string.js.map +1 -1
- package/esm/stream.d.ts +25 -24
- package/esm/stream.d.ts.map +1 -1
- package/esm/stream.js +26 -26
- package/esm/stream.js.map +1 -1
- package/esm/struct-deserialize.d.ts +6 -6
- package/esm/struct-deserialize.d.ts.map +1 -1
- package/esm/struct-deserialize.js +8 -8
- package/esm/struct-serialize.d.ts +5 -5
- package/esm/struct-serialize.js +10 -10
- package/esm/trace.d.ts +3 -3
- package/esm/wrap-readable.d.ts +21 -20
- package/esm/wrap-readable.d.ts.map +1 -1
- package/esm/wrap-readable.js +56 -56
- package/esm/wrap-readable.js.map +1 -1
- package/esm/wrap-writable.d.ts +14 -12
- package/esm/wrap-writable.d.ts.map +1 -1
- package/esm/wrap-writable.js +62 -52
- package/esm/wrap-writable.js.map +1 -1
- package/package.json +7 -6
- package/src/buffered-transform.ts +5 -10
- package/src/buffered.ts +7 -5
- package/src/consumable.ts +281 -0
- package/src/distribution.ts +113 -0
- package/src/duplex.ts +15 -16
- package/src/gather-string.ts +5 -3
- package/src/index.ts +16 -15
- package/src/inspect.ts +1 -1
- package/src/pipe-from.ts +8 -6
- package/src/push-readable.ts +3 -7
- package/src/split-string.ts +5 -2
- package/src/stream.ts +1 -1
- package/src/struct-deserialize.ts +1 -1
- package/src/wrap-readable.ts +5 -5
- package/src/wrap-writable.ts +16 -4
- package/tsconfig.build.tsbuildinfo +1 -1
- package/src/chunk.ts +0 -15
package/CHANGELOG.json
CHANGED
|
@@ -1,23 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
2
|
+
"name": "@yume-chan/stream-extra",
|
|
3
|
+
"entries": [
|
|
4
|
+
{
|
|
5
|
+
"version": "0.0.19",
|
|
6
|
+
"tag": "@yume-chan/stream-extra_v0.0.19",
|
|
7
|
+
"date": "Sun, 09 Apr 2023 05:55:33 GMT",
|
|
8
|
+
"comments": {
|
|
9
|
+
"none": [
|
|
10
|
+
{
|
|
11
|
+
"comment": "Add an option to combine small chunks into target size in `ChunkStream`, and rename it to `DistributionStream`"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"version": "0.0.18",
|
|
18
|
+
"tag": "@yume-chan/stream-extra_v0.0.18",
|
|
19
|
+
"date": "Wed, 25 Jan 2023 21:33:49 GMT",
|
|
20
|
+
"comments": {
|
|
21
|
+
"none": [
|
|
22
|
+
{
|
|
23
|
+
"comment": "Change to load native Web Streams API implementation from `globalThis` if available"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"version": "0.0.17",
|
|
30
|
+
"tag": "@yume-chan/stream-extra_v0.0.17",
|
|
31
|
+
"date": "Tue, 18 Oct 2022 09:32:30 GMT",
|
|
32
|
+
"comments": {}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
23
35
|
}
|
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
# Change Log - @yume-chan/stream-extra
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Sun, 09 Apr 2023 05:55:33 GMT and should not be manually modified.
|
|
4
|
+
|
|
5
|
+
## 0.0.19
|
|
6
|
+
Sun, 09 Apr 2023 05:55:33 GMT
|
|
7
|
+
|
|
8
|
+
### Updates
|
|
9
|
+
|
|
10
|
+
- Add an option to combine small chunks into target size in `ChunkStream`, and rename it to `DistributionStream`
|
|
4
11
|
|
|
5
12
|
## 0.0.18
|
|
6
13
|
Wed, 25 Jan 2023 21:33:49 GMT
|
|
@@ -13,4 +20,3 @@ Wed, 25 Jan 2023 21:33:49 GMT
|
|
|
13
20
|
Tue, 18 Oct 2022 09:32:30 GMT
|
|
14
21
|
|
|
15
22
|
_Initial release_
|
|
16
|
-
|
package/README.md
CHANGED
|
@@ -40,4 +40,4 @@ web-streams-polyfill package's `ReadableStream#pipeTo` only uses public methods,
|
|
|
40
40
|
|
|
41
41
|
Allowing reading specified amount of data by buffering incoming data.
|
|
42
42
|
|
|
43
|
-
It's not a Web
|
|
43
|
+
It's not a Web Streams API `ReadableStream`, because `ReadableStream` doesn't allow hinting the desired read size (except using BYOB readable, but causes extra allocations for small reads).
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BufferedReadableStream } from "./buffered.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
2
|
+
import { BufferedReadableStream } from "./buffered.js";
|
|
3
|
+
import type { ReadableWritablePair } from "./stream.js";
|
|
4
|
+
import { ReadableStream, WritableStream } from "./stream.js";
|
|
5
|
+
export declare class BufferedTransformStream<T> implements ReadableWritablePair<T, Uint8Array> {
|
|
6
|
+
private _readable;
|
|
7
|
+
get readable(): ReadableStream<T>;
|
|
8
|
+
private _writable;
|
|
9
|
+
get writable(): WritableStream<Uint8Array>;
|
|
10
|
+
constructor(transform: (stream: BufferedReadableStream) => ValueOrPromise<T>);
|
|
11
|
+
}
|
|
11
12
|
//# sourceMappingURL=buffered-transform.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered-transform.d.ts","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"buffered-transform.d.ts","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACH,sBAAsB,EAEzB,MAAM,eAAe,CAAC;AAGvB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7D,qBAAa,uBAAuB,CAAC,CAAC,CAClC,YAAW,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC;IAE9C,OAAO,CAAC,SAAS,CAAoB;IACrC,IAAW,QAAQ,sBAElB;IAED,OAAO,CAAC,SAAS,CAA6B;IAC9C,IAAW,QAAQ,+BAElB;gBAGG,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,cAAc,CAAC,CAAC,CAAC;CA8CvE"}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { BufferedReadableStream, BufferedReadableStreamEndedError, } from "./buffered.js";
|
|
2
|
-
import { PushReadableStream
|
|
3
|
-
import { ReadableStream, WritableStream
|
|
4
|
-
// TODO: BufferedTransformStream: find better implementation
|
|
5
|
-
export class BufferedTransformStream {
|
|
6
|
-
_readable;
|
|
7
|
-
get readable() {
|
|
8
|
-
return this._readable;
|
|
9
|
-
}
|
|
10
|
-
_writable;
|
|
11
|
-
get writable() {
|
|
12
|
-
return this._writable;
|
|
13
|
-
}
|
|
14
|
-
constructor(transform) {
|
|
15
|
-
// Convert incoming chunks to a `BufferedReadableStream`
|
|
16
|
-
let sourceStreamController;
|
|
17
|
-
const buffered = new BufferedReadableStream(new PushReadableStream((controller) => {
|
|
18
|
-
sourceStreamController = controller;
|
|
19
|
-
}));
|
|
20
|
-
this._readable = new ReadableStream({
|
|
21
|
-
async pull(controller) {
|
|
22
|
-
try {
|
|
23
|
-
const value = await transform(buffered);
|
|
24
|
-
controller.enqueue(value);
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
// Treat `BufferedReadableStreamEndedError` as a normal end.
|
|
28
|
-
// If the `transform` method doesn't have enough data to return a value,
|
|
29
|
-
// it should throw another error to indicate that.
|
|
30
|
-
if (e instanceof BufferedReadableStreamEndedError) {
|
|
31
|
-
controller.close();
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
throw e;
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
cancel: (reason) => {
|
|
38
|
-
// Propagate cancel to the source stream
|
|
39
|
-
// So future writes will be rejected
|
|
40
|
-
return buffered.cancel(reason);
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
this._writable = new WritableStream({
|
|
44
|
-
async write(chunk) {
|
|
45
|
-
await sourceStreamController.enqueue(chunk);
|
|
46
|
-
},
|
|
47
|
-
abort() {
|
|
48
|
-
sourceStreamController.close();
|
|
49
|
-
},
|
|
50
|
-
close() {
|
|
51
|
-
sourceStreamController.close();
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
1
|
+
import { BufferedReadableStream, BufferedReadableStreamEndedError, } from "./buffered.js";
|
|
2
|
+
import { PushReadableStream } from "./push-readable.js";
|
|
3
|
+
import { ReadableStream, WritableStream } from "./stream.js";
|
|
4
|
+
// TODO: BufferedTransformStream: find better implementation
|
|
5
|
+
export class BufferedTransformStream {
|
|
6
|
+
_readable;
|
|
7
|
+
get readable() {
|
|
8
|
+
return this._readable;
|
|
9
|
+
}
|
|
10
|
+
_writable;
|
|
11
|
+
get writable() {
|
|
12
|
+
return this._writable;
|
|
13
|
+
}
|
|
14
|
+
constructor(transform) {
|
|
15
|
+
// Convert incoming chunks to a `BufferedReadableStream`
|
|
16
|
+
let sourceStreamController;
|
|
17
|
+
const buffered = new BufferedReadableStream(new PushReadableStream((controller) => {
|
|
18
|
+
sourceStreamController = controller;
|
|
19
|
+
}));
|
|
20
|
+
this._readable = new ReadableStream({
|
|
21
|
+
async pull(controller) {
|
|
22
|
+
try {
|
|
23
|
+
const value = await transform(buffered);
|
|
24
|
+
controller.enqueue(value);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// Treat `BufferedReadableStreamEndedError` as a normal end.
|
|
28
|
+
// If the `transform` method doesn't have enough data to return a value,
|
|
29
|
+
// it should throw another error to indicate that.
|
|
30
|
+
if (e instanceof BufferedReadableStreamEndedError) {
|
|
31
|
+
controller.close();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
throw e;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
cancel: (reason) => {
|
|
38
|
+
// Propagate cancel to the source stream
|
|
39
|
+
// So future writes will be rejected
|
|
40
|
+
return buffered.cancel(reason);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
this._writable = new WritableStream({
|
|
44
|
+
async write(chunk) {
|
|
45
|
+
await sourceStreamController.enqueue(chunk);
|
|
46
|
+
},
|
|
47
|
+
abort() {
|
|
48
|
+
sourceStreamController.close();
|
|
49
|
+
},
|
|
50
|
+
close() {
|
|
51
|
+
sourceStreamController.close();
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
56
|
//# sourceMappingURL=buffered-transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered-transform.js","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,sBAAsB,EACtB,gCAAgC,GACnC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"buffered-transform.js","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,sBAAsB,EACtB,gCAAgC,GACnC,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7D,4DAA4D;AAC5D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B,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/esm/buffered.d.ts
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare class BufferedReadableStreamEndedError extends Error {
|
|
3
|
-
constructor();
|
|
4
|
-
}
|
|
5
|
-
export declare class BufferedReadableStream {
|
|
6
|
-
private buffered;
|
|
7
|
-
private bufferedOffset;
|
|
8
|
-
private bufferedLength;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";
|
|
2
|
+
export declare class BufferedReadableStreamEndedError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
export declare class BufferedReadableStream {
|
|
6
|
+
private buffered;
|
|
7
|
+
private bufferedOffset;
|
|
8
|
+
private bufferedLength;
|
|
9
|
+
private _position;
|
|
10
|
+
get position(): number;
|
|
11
|
+
protected readonly stream: ReadableStream<Uint8Array>;
|
|
12
|
+
protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
13
|
+
constructor(stream: ReadableStream<Uint8Array>);
|
|
14
|
+
private readSource;
|
|
15
|
+
private readAsync;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param length
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
read(length: number): Uint8Array | Promise<Uint8Array>;
|
|
22
|
+
/**
|
|
23
|
+
* Return a readable stream with unconsumed data (if any) and
|
|
24
|
+
* all data from the wrapped stream.
|
|
25
|
+
* @returns A `ReadableStream`
|
|
26
|
+
*/
|
|
27
|
+
release(): ReadableStream<Uint8Array>;
|
|
28
|
+
cancel(reason?: unknown): Promise<void>;
|
|
29
|
+
}
|
|
28
30
|
//# sourceMappingURL=buffered.d.ts.map
|
package/esm/buffered.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE/E,qBAAa,gCAAiC,SAAQ,KAAK;;CAO1D;AAED,qBAAa,sBAAsB;IAC/B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,cAAc,CAAK;IAC3B,OAAO,CAAC,cAAc,CAAK;IAE3B,OAAO,CAAC,SAAS,CAAK;IACtB,IAAW,QAAQ,WAElB;IAED,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;gBAEhD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;YAKvC,UAAU;YASV,SAAS;IAmDvB;;;;OAIG;IACI,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAoB7D;;;;OAIG;IACI,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IAuBrC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO;CAGjC"}
|
package/esm/buffered.js
CHANGED
|
@@ -1,124 +1,129 @@
|
|
|
1
|
-
import { PushReadableStream } from "./push-readable.js";
|
|
2
|
-
export class BufferedReadableStreamEndedError extends Error {
|
|
3
|
-
constructor() {
|
|
4
|
-
super("Stream ended");
|
|
5
|
-
// Fix Error's prototype chain when compiling to ES5
|
|
6
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export class BufferedReadableStream {
|
|
10
|
-
buffered;
|
|
11
|
-
bufferedOffset = 0;
|
|
12
|
-
bufferedLength = 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
1
|
+
import { PushReadableStream } from "./push-readable.js";
|
|
2
|
+
export class BufferedReadableStreamEndedError extends Error {
|
|
3
|
+
constructor() {
|
|
4
|
+
super("Stream ended");
|
|
5
|
+
// Fix Error's prototype chain when compiling to ES5
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class BufferedReadableStream {
|
|
10
|
+
buffered;
|
|
11
|
+
bufferedOffset = 0;
|
|
12
|
+
bufferedLength = 0;
|
|
13
|
+
_position = 0;
|
|
14
|
+
get position() {
|
|
15
|
+
return this._position;
|
|
16
|
+
}
|
|
17
|
+
stream;
|
|
18
|
+
reader;
|
|
19
|
+
constructor(stream) {
|
|
20
|
+
this.stream = stream;
|
|
21
|
+
this.reader = stream.getReader();
|
|
22
|
+
}
|
|
23
|
+
async readSource() {
|
|
24
|
+
const { done, value } = await this.reader.read();
|
|
25
|
+
if (done) {
|
|
26
|
+
throw new BufferedReadableStreamEndedError();
|
|
27
|
+
}
|
|
28
|
+
this._position += value.byteLength;
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
async readAsync(length, initial) {
|
|
32
|
+
let result;
|
|
33
|
+
let index;
|
|
34
|
+
if (initial) {
|
|
35
|
+
result = new Uint8Array(length);
|
|
36
|
+
result.set(initial);
|
|
37
|
+
index = initial.byteLength;
|
|
38
|
+
length -= initial.byteLength;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const array = await this.readSource();
|
|
42
|
+
if (array.byteLength === length) {
|
|
43
|
+
return array;
|
|
44
|
+
}
|
|
45
|
+
if (array.byteLength > length) {
|
|
46
|
+
this.buffered = array;
|
|
47
|
+
this.bufferedOffset = length;
|
|
48
|
+
this.bufferedLength = array.byteLength - length;
|
|
49
|
+
return array.subarray(0, length);
|
|
50
|
+
}
|
|
51
|
+
result = new Uint8Array(length);
|
|
52
|
+
result.set(array);
|
|
53
|
+
index = array.byteLength;
|
|
54
|
+
length -= array.byteLength;
|
|
55
|
+
}
|
|
56
|
+
while (length > 0) {
|
|
57
|
+
const array = await this.readSource();
|
|
58
|
+
if (array.byteLength === length) {
|
|
59
|
+
result.set(array, index);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
if (array.byteLength > length) {
|
|
63
|
+
this.buffered = array;
|
|
64
|
+
this.bufferedOffset = length;
|
|
65
|
+
this.bufferedLength = array.byteLength - length;
|
|
66
|
+
result.set(array.subarray(0, length), index);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
result.set(array, index);
|
|
70
|
+
index += array.byteLength;
|
|
71
|
+
length -= array.byteLength;
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @param length
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
read(length) {
|
|
81
|
+
// PERF: Add a synchronous path for reading from internal buffer
|
|
82
|
+
if (this.buffered) {
|
|
83
|
+
const array = this.buffered;
|
|
84
|
+
const offset = this.bufferedOffset;
|
|
85
|
+
if (this.bufferedLength > length) {
|
|
86
|
+
// PERF: `subarray` is slow
|
|
87
|
+
// don't use it until absolutely necessary
|
|
88
|
+
this.bufferedOffset += length;
|
|
89
|
+
this.bufferedLength -= length;
|
|
90
|
+
return array.subarray(offset, offset + length);
|
|
91
|
+
}
|
|
92
|
+
this.buffered = undefined;
|
|
93
|
+
return this.readAsync(length, array.subarray(offset));
|
|
94
|
+
}
|
|
95
|
+
return this.readAsync(length);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Return a readable stream with unconsumed data (if any) and
|
|
99
|
+
* all data from the wrapped stream.
|
|
100
|
+
* @returns A `ReadableStream`
|
|
101
|
+
*/
|
|
102
|
+
release() {
|
|
103
|
+
if (this.buffered) {
|
|
104
|
+
return new PushReadableStream(async (controller) => {
|
|
105
|
+
// Put the remaining data back to the stream
|
|
106
|
+
await controller.enqueue(this.buffered);
|
|
107
|
+
// Manually pipe the stream
|
|
108
|
+
while (true) {
|
|
109
|
+
const { done, value } = await this.reader.read();
|
|
110
|
+
if (done) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
await controller.enqueue(value);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Simply release the reader and return the stream
|
|
121
|
+
this.reader.releaseLock();
|
|
122
|
+
return this.stream;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
cancel(reason) {
|
|
126
|
+
return this.reader.cancel(reason);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
124
129
|
//# sourceMappingURL=buffered.js.map
|
package/esm/buffered.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered.js","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"buffered.js","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,OAAO,gCAAiC,SAAQ,KAAK;IACvD;QACI,KAAK,CAAC,cAAc,CAAC,CAAC;QAEtB,oDAAoD;QACpD,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACtD,C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AC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;CACJ"}
|
package/esm/chunk.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { TransformStream } from "
|
|
2
|
-
export declare class
|
|
3
|
-
|
|
1
|
+
import { TransformStream } from "../src/stream.js";
|
|
2
|
+
export declare class DistributionStream extends TransformStream<
|
|
3
|
+
Uint8Array,
|
|
4
|
+
Uint8Array
|
|
5
|
+
> {
|
|
6
|
+
constructor(size: number, combine?: boolean);
|
|
4
7
|
}
|
|
5
|
-
//# sourceMappingURL=chunk.d.ts.map
|
|
8
|
+
//# sourceMappingURL=chunk.d.ts.map
|
package/esm/chunk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../src/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,qBAAa,
|
|
1
|
+
{"version":3,"file":"chunk.d.ts","sourceRoot":"","sources":["../src/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,qBAAa,kBAAmB,SAAQ,eAAe,CACnD,UAAU,EACV,UAAU,CACb;gBACsB,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ;CA+DnD"}
|