@yume-chan/stream-extra 0.0.23 → 1.0.0
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.md +32 -2
- package/LICENSE +1 -1
- package/esm/buffered-transform.d.ts +3 -3
- package/esm/buffered-transform.d.ts.map +1 -1
- package/esm/buffered-transform.js.map +1 -1
- package/esm/buffered.d.ts +3 -6
- package/esm/buffered.d.ts.map +1 -1
- package/esm/buffered.js +87 -75
- package/esm/buffered.js.map +1 -1
- package/esm/concat.d.ts +4 -3
- package/esm/concat.d.ts.map +1 -1
- package/esm/concat.js +6 -4
- package/esm/concat.js.map +1 -1
- package/esm/consumable.d.ts +36 -43
- package/esm/consumable.d.ts.map +1 -1
- package/esm/consumable.js +74 -125
- package/esm/consumable.js.map +1 -1
- package/esm/distribution.d.ts +3 -2
- package/esm/distribution.d.ts.map +1 -1
- package/esm/distribution.js +22 -18
- package/esm/distribution.js.map +1 -1
- package/esm/duplex.d.ts +2 -2
- package/esm/duplex.d.ts.map +1 -1
- package/esm/duplex.js +2 -6
- package/esm/duplex.js.map +1 -1
- package/esm/encoding.d.ts +21 -0
- package/esm/encoding.d.ts.map +1 -0
- package/esm/encoding.js +4 -0
- package/esm/encoding.js.map +1 -0
- package/esm/index.d.ts +4 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +4 -1
- package/esm/index.js.map +1 -1
- package/esm/maybe-consumable-ns.d.ts +16 -0
- package/esm/maybe-consumable-ns.d.ts.map +1 -0
- package/esm/maybe-consumable-ns.js +44 -0
- package/esm/maybe-consumable-ns.js.map +1 -0
- package/esm/maybe-consumable.d.ts +4 -0
- package/esm/maybe-consumable.d.ts.map +1 -0
- package/esm/maybe-consumable.js +2 -0
- package/esm/maybe-consumable.js.map +1 -0
- package/esm/push-readable.d.ts +16 -2
- package/esm/push-readable.d.ts.map +1 -1
- package/esm/push-readable.js +176 -17
- package/esm/push-readable.js.map +1 -1
- package/esm/stream.d.ts +7 -7
- package/esm/stream.d.ts.map +1 -1
- package/esm/stream.js +54 -5
- package/esm/stream.js.map +1 -1
- package/esm/struct-deserialize.d.ts +3 -4
- package/esm/struct-deserialize.d.ts.map +1 -1
- package/esm/struct-deserialize.js.map +1 -1
- package/esm/struct-serialize.d.ts +2 -2
- package/esm/struct-serialize.d.ts.map +1 -1
- package/esm/struct-serialize.js.map +1 -1
- package/esm/task.d.ts +5 -0
- package/esm/task.d.ts.map +1 -0
- package/esm/task.js +9 -0
- package/esm/task.js.map +1 -0
- package/esm/try-close.d.ts +10 -0
- package/esm/try-close.d.ts.map +1 -0
- package/esm/try-close.js +19 -0
- package/esm/try-close.js.map +1 -0
- package/esm/types.d.ts +34 -35
- package/esm/types.d.ts.map +1 -1
- package/esm/wrap-readable.d.ts +5 -4
- package/esm/wrap-readable.d.ts.map +1 -1
- package/esm/wrap-readable.js +14 -9
- package/esm/wrap-readable.js.map +1 -1
- package/esm/wrap-writable.d.ts +2 -2
- package/esm/wrap-writable.d.ts.map +1 -1
- package/esm/wrap-writable.js +4 -6
- package/esm/wrap-writable.js.map +1 -1
- package/package.json +11 -15
- package/src/buffered-transform.ts +2 -2
- package/src/buffered.ts +107 -83
- package/src/concat.ts +6 -4
- package/src/consumable.ts +132 -213
- package/src/distribution.ts +30 -20
- package/src/duplex.ts +4 -7
- package/src/encoding.ts +39 -0
- package/src/index.ts +4 -1
- package/src/maybe-consumable-ns.ts +75 -0
- package/src/maybe-consumable.ts +5 -0
- package/src/push-readable.ts +213 -19
- package/src/stream.ts +69 -9
- package/src/struct-deserialize.ts +4 -7
- package/src/struct-serialize.ts +3 -3
- package/src/task.ts +21 -0
- package/src/try-close.ts +44 -0
- package/src/types.ts +34 -34
- package/src/wrap-readable.ts +20 -14
- package/src/wrap-writable.ts +6 -9
- package/tsconfig.build.tsbuildinfo +1 -1
- package/CHANGELOG.json +0 -86
- package/esm/decode-utf8.d.ts +0 -5
- package/esm/decode-utf8.d.ts.map +0 -1
- package/esm/decode-utf8.js +0 -12
- package/esm/decode-utf8.js.map +0 -1
- package/src/decode-utf8.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
1
|
# Change Log - @yume-chan/stream-extra
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 53688d3: Use PNPM workspace and Changesets to manage the monorepo.
|
|
8
|
+
|
|
9
|
+
Because Changesets doesn't support alpha versions (`0.x.x`), this version is `1.0.0`. Future versions will follow SemVer rules, for example, breaking API changes will introduce a new major version.
|
|
10
|
+
|
|
11
|
+
- ea5002b: Polyfill `ReadableStream.from` and `ReadableStream.prototype.values`
|
|
12
|
+
- Updated dependencies [53688d3]
|
|
13
|
+
- Updated dependencies [db8466f]
|
|
14
|
+
- Updated dependencies [db8466f]
|
|
15
|
+
- @yume-chan/struct@1.0.1
|
|
16
|
+
|
|
17
|
+
This log was last generated on Tue, 18 Jun 2024 02:49:43 GMT and should not be manually modified.
|
|
18
|
+
|
|
19
|
+
## 0.0.24
|
|
20
|
+
|
|
21
|
+
Tue, 18 Jun 2024 02:49:43 GMT
|
|
22
|
+
|
|
23
|
+
### Updates
|
|
24
|
+
|
|
25
|
+
- Add `MaybeConsumable` type. It's also a namespace containing related types.
|
|
26
|
+
- Re-export global `TextDecoderStream` to replace `DecodeUtf8Stream` which doesn't work correctly in stream mode
|
|
27
|
+
- Move `Consumable` related types to the `Consumable` namespace. In future, more types will be moved to namespaces.
|
|
4
28
|
|
|
5
29
|
## 0.0.23
|
|
30
|
+
|
|
6
31
|
Thu, 21 Mar 2024 03:15:10 GMT
|
|
7
32
|
|
|
8
33
|
### Updates
|
|
@@ -12,11 +37,13 @@ Thu, 21 Mar 2024 03:15:10 GMT
|
|
|
12
37
|
- Remove web-streams-polyfill dependency. The runtime must have global stream implementations (or you can add a polyfill yourself).
|
|
13
38
|
|
|
14
39
|
## 0.0.22
|
|
40
|
+
|
|
15
41
|
Wed, 13 Dec 2023 05:57:27 GMT
|
|
16
42
|
|
|
17
43
|
_Version update only_
|
|
18
44
|
|
|
19
45
|
## 0.0.21
|
|
46
|
+
|
|
20
47
|
Fri, 25 Aug 2023 14:05:18 GMT
|
|
21
48
|
|
|
22
49
|
### Updates
|
|
@@ -24,6 +51,7 @@ Fri, 25 Aug 2023 14:05:18 GMT
|
|
|
24
51
|
- Replace `GatherStringStream` with `ConcatStringStream` which can be treated as a Promise
|
|
25
52
|
|
|
26
53
|
## 0.0.20
|
|
54
|
+
|
|
27
55
|
Mon, 05 Jun 2023 02:51:41 GMT
|
|
28
56
|
|
|
29
57
|
### Updates
|
|
@@ -32,6 +60,7 @@ Mon, 05 Jun 2023 02:51:41 GMT
|
|
|
32
60
|
- Use ECMAScript private class fields syntax (supported by Chrome 74, Firefox 90, Safari 14.1 and Node.js 12.0.0).
|
|
33
61
|
|
|
34
62
|
## 0.0.19
|
|
63
|
+
|
|
35
64
|
Sun, 09 Apr 2023 05:55:33 GMT
|
|
36
65
|
|
|
37
66
|
### Updates
|
|
@@ -39,6 +68,7 @@ Sun, 09 Apr 2023 05:55:33 GMT
|
|
|
39
68
|
- Add an option to combine small chunks into target size in `ChunkStream`, and rename it to `DistributionStream`
|
|
40
69
|
|
|
41
70
|
## 0.0.18
|
|
71
|
+
|
|
42
72
|
Wed, 25 Jan 2023 21:33:49 GMT
|
|
43
73
|
|
|
44
74
|
### Updates
|
|
@@ -46,7 +76,7 @@ Wed, 25 Jan 2023 21:33:49 GMT
|
|
|
46
76
|
- Change to load native Web Streams API implementation from `globalThis` if available
|
|
47
77
|
|
|
48
78
|
## 0.0.17
|
|
79
|
+
|
|
49
80
|
Tue, 18 Oct 2022 09:32:30 GMT
|
|
50
81
|
|
|
51
82
|
_Initial release_
|
|
52
|
-
|
package/LICENSE
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
2
|
import { BufferedReadableStream } from "./buffered.js";
|
|
3
3
|
import type { ReadableWritablePair } from "./stream.js";
|
|
4
4
|
import { ReadableStream, WritableStream } from "./stream.js";
|
|
5
5
|
export declare class BufferedTransformStream<T> implements ReadableWritablePair<T, Uint8Array> {
|
|
6
6
|
#private;
|
|
7
7
|
get readable(): ReadableStream<T>;
|
|
8
|
-
get writable(): WritableStream<Uint8Array
|
|
9
|
-
constructor(transform: (stream: BufferedReadableStream) =>
|
|
8
|
+
get writable(): WritableStream<Uint8Array<ArrayBufferLike>>;
|
|
9
|
+
constructor(transform: (stream: BufferedReadableStream) => MaybePromiseLike<T>);
|
|
10
10
|
}
|
|
11
11
|
//# 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,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"buffered-transform.d.ts","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAGvD,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;;IAG9C,IAAI,QAAQ,sBAEX;IAGD,IAAI,QAAQ,gDAEX;gBAGG,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,gBAAgB,CAAC,CAAC,CAAC;CA8CzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered-transform.js","sourceRoot":"","sources":["../src/buffered-transform.ts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AI;YACnC,KAAK,CAAC,IAAI,CAAC,UAAU;gBACjB,IAAI,CAAC;oBACD,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,CAAC;oBACxC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAC9B,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,4CAA4C;oBAC5C,wEAAwE;oBACxE,kDAAkD;oBAClD,IAAI,CAAC,YAAY,gBAAgB,EAAE,CAAC;wBAChC,UAAU,CAAC,KAAK,EAAE,CAAC;wBACnB,OAAO;oBACX,CAAC;oBACD,MAAM,CAAC,CAAC;gBACZ,CAAC;YACL,CAAC;YACD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;gBACf,wCAAwC;gBACxC,oCAAoC;gBACpC,OAAO,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;QAEH,IAAI,CAAC,SAAS,GAAG,IAAI,cAAc,CAAC;YAChC,KAAK,CAAC,KAAK,CAAC,KAAK;gBACb,MAAM,sBAAsB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAChD,CAAC;YACD,KAAK;gBACD,sBAAsB,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;YACD,KAAK;gBACD,sBAAsB,CAAC,KAAK,EAAE,CAAC;YACnC,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/esm/buffered.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
1
2
|
import type { AsyncExactReadable } from "@yume-chan/struct";
|
|
2
3
|
import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";
|
|
3
4
|
export declare class BufferedReadableStream implements AsyncExactReadable {
|
|
@@ -6,12 +7,8 @@ export declare class BufferedReadableStream implements AsyncExactReadable {
|
|
|
6
7
|
protected readonly stream: ReadableStream<Uint8Array>;
|
|
7
8
|
protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
8
9
|
constructor(stream: ReadableStream<Uint8Array>);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param length
|
|
12
|
-
* @returns
|
|
13
|
-
*/
|
|
14
|
-
readExactly(length: number): Uint8Array | Promise<Uint8Array>;
|
|
10
|
+
iterateExactly(length: number): Iterator<MaybePromiseLike<Uint8Array>, void, void>;
|
|
11
|
+
readExactly: (this: BufferedReadableStream, length: number) => MaybePromiseLike<Uint8Array<ArrayBufferLike>>;
|
|
15
12
|
/**
|
|
16
13
|
* Return a readable stream with unconsumed data (if any) and
|
|
17
14
|
* all data from the wrapped stream.
|
package/esm/buffered.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAG/E,qBAAa,sBAAuB,YAAW,kBAAkB;;IAQ7D,IAAI,QAAQ,WAEX;IAED,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;gBAEvD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;IAgD9C,cAAc,CACV,MAAM,EAAE,MAAM,GACf,QAAQ,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC;IA0CrD,WAAW,kGA8BR;IAEH;;;;OAIG;IACH,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IA4B/B,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO;CAGhC"}
|
package/esm/buffered.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ExactReadableEndedError } from "@yume-chan/struct";
|
|
1
|
+
import { bipedal, ExactReadableEndedError } from "@yume-chan/struct";
|
|
2
2
|
import { PushReadableStream } from "./push-readable.js";
|
|
3
|
-
|
|
4
|
-
// no-op
|
|
5
|
-
};
|
|
3
|
+
import { tryCancel } from "./try-close.js";
|
|
6
4
|
export class BufferedReadableStream {
|
|
7
5
|
#buffered;
|
|
6
|
+
// PERF: `subarray` is slow
|
|
7
|
+
// don't use it until absolutely necessary
|
|
8
8
|
#bufferedOffset = 0;
|
|
9
9
|
#bufferedLength = 0;
|
|
10
10
|
#position = 0;
|
|
@@ -17,89 +17,104 @@ export class BufferedReadableStream {
|
|
|
17
17
|
this.stream = stream;
|
|
18
18
|
this.reader = stream.getReader();
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
#readBuffered(length) {
|
|
21
|
+
if (!this.#buffered) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
const value = this.#buffered.subarray(this.#bufferedOffset, this.#bufferedOffset + length);
|
|
25
|
+
// PERF: Synchronous path for reading from internal buffer
|
|
26
|
+
if (this.#bufferedLength > length) {
|
|
27
|
+
this.#position += length;
|
|
28
|
+
this.#bufferedOffset += length;
|
|
29
|
+
this.#bufferedLength -= length;
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
this.#position += this.#bufferedLength;
|
|
33
|
+
this.#buffered = undefined;
|
|
34
|
+
this.#bufferedOffset = 0;
|
|
35
|
+
this.#bufferedLength = 0;
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
async #readSource(length) {
|
|
21
39
|
const { done, value } = await this.reader.read();
|
|
22
40
|
if (done) {
|
|
23
41
|
throw new ExactReadableEndedError();
|
|
24
42
|
}
|
|
43
|
+
if (value.length > length) {
|
|
44
|
+
this.#buffered = value;
|
|
45
|
+
this.#bufferedOffset = length;
|
|
46
|
+
this.#bufferedLength = value.length - length;
|
|
47
|
+
this.#position += length;
|
|
48
|
+
return value.subarray(0, length);
|
|
49
|
+
}
|
|
50
|
+
this.#position += value.length;
|
|
25
51
|
return value;
|
|
26
52
|
}
|
|
27
|
-
|
|
53
|
+
iterateExactly(length) {
|
|
54
|
+
let state = this.#buffered ? 0 : 1;
|
|
55
|
+
return {
|
|
56
|
+
next: () => {
|
|
57
|
+
switch (state) {
|
|
58
|
+
case 0: {
|
|
59
|
+
const value = this.#readBuffered(length);
|
|
60
|
+
if (value.length === length) {
|
|
61
|
+
state = 2;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
length -= value.length;
|
|
65
|
+
state = 1;
|
|
66
|
+
}
|
|
67
|
+
return { done: false, value };
|
|
68
|
+
}
|
|
69
|
+
case 1:
|
|
70
|
+
state = 3;
|
|
71
|
+
return {
|
|
72
|
+
done: false,
|
|
73
|
+
value: this.#readSource(length).then((value) => {
|
|
74
|
+
if (value.length === length) {
|
|
75
|
+
state = 2;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
length -= value.length;
|
|
79
|
+
state = 1;
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}),
|
|
83
|
+
};
|
|
84
|
+
case 2:
|
|
85
|
+
return { done: true, value: undefined };
|
|
86
|
+
case 3:
|
|
87
|
+
throw new Error("Can't call `next` before previous Promise resolves");
|
|
88
|
+
default:
|
|
89
|
+
throw new Error("unreachable");
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
readExactly = bipedal(function* (then, length) {
|
|
28
95
|
let result;
|
|
29
|
-
let index;
|
|
96
|
+
let index = 0;
|
|
97
|
+
const initial = this.#readBuffered(length);
|
|
30
98
|
if (initial) {
|
|
99
|
+
if (initial.length === length) {
|
|
100
|
+
return initial;
|
|
101
|
+
}
|
|
31
102
|
result = new Uint8Array(length);
|
|
32
|
-
result.set(initial);
|
|
33
|
-
index
|
|
103
|
+
result.set(initial, index);
|
|
104
|
+
index += initial.length;
|
|
34
105
|
length -= initial.length;
|
|
35
106
|
}
|
|
36
107
|
else {
|
|
37
|
-
const array = await this.#readSource();
|
|
38
|
-
if (array.length === length) {
|
|
39
|
-
this.#position += length;
|
|
40
|
-
return array;
|
|
41
|
-
}
|
|
42
|
-
if (array.length > length) {
|
|
43
|
-
this.#buffered = array;
|
|
44
|
-
this.#bufferedOffset = length;
|
|
45
|
-
this.#bufferedLength = array.length - length;
|
|
46
|
-
this.#position += length;
|
|
47
|
-
return array.subarray(0, length);
|
|
48
|
-
}
|
|
49
108
|
result = new Uint8Array(length);
|
|
50
|
-
result.set(array);
|
|
51
|
-
index = array.length;
|
|
52
|
-
length -= array.length;
|
|
53
|
-
this.#position += array.length;
|
|
54
109
|
}
|
|
55
110
|
while (length > 0) {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
if (array.length > length) {
|
|
63
|
-
this.#buffered = array;
|
|
64
|
-
this.#bufferedOffset = length;
|
|
65
|
-
this.#bufferedLength = array.length - length;
|
|
66
|
-
result.set(array.subarray(0, length), index);
|
|
67
|
-
this.#position += length;
|
|
68
|
-
return result;
|
|
69
|
-
}
|
|
70
|
-
result.set(array, index);
|
|
71
|
-
index += array.length;
|
|
72
|
-
length -= array.length;
|
|
73
|
-
this.#position += array.length;
|
|
111
|
+
const value = yield* then(this.#readSource(length));
|
|
112
|
+
result.set(value, index);
|
|
113
|
+
index += value.length;
|
|
114
|
+
length -= value.length;
|
|
74
115
|
}
|
|
75
116
|
return result;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @param length
|
|
80
|
-
* @returns
|
|
81
|
-
*/
|
|
82
|
-
readExactly(length) {
|
|
83
|
-
// PERF: Add a synchronous path for reading from internal buffer
|
|
84
|
-
if (this.#buffered) {
|
|
85
|
-
const array = this.#buffered;
|
|
86
|
-
const offset = this.#bufferedOffset;
|
|
87
|
-
if (this.#bufferedLength > length) {
|
|
88
|
-
// PERF: `subarray` is slow
|
|
89
|
-
// don't use it until absolutely necessary
|
|
90
|
-
this.#bufferedOffset += length;
|
|
91
|
-
this.#bufferedLength -= length;
|
|
92
|
-
this.#position += length;
|
|
93
|
-
return array.subarray(offset, offset + length);
|
|
94
|
-
}
|
|
95
|
-
this.#buffered = undefined;
|
|
96
|
-
this.#bufferedLength = 0;
|
|
97
|
-
this.#bufferedOffset = 0;
|
|
98
|
-
this.#position += array.length - offset;
|
|
99
|
-
return this.#readAsync(length, array.subarray(offset));
|
|
100
|
-
}
|
|
101
|
-
return this.#readAsync(length);
|
|
102
|
-
}
|
|
117
|
+
});
|
|
103
118
|
/**
|
|
104
119
|
* Return a readable stream with unconsumed data (if any) and
|
|
105
120
|
* all data from the wrapped stream.
|
|
@@ -112,8 +127,7 @@ export class BufferedReadableStream {
|
|
|
112
127
|
const buffered = this.#buffered.subarray(this.#bufferedOffset);
|
|
113
128
|
await controller.enqueue(buffered);
|
|
114
129
|
controller.abortSignal.addEventListener("abort", () => {
|
|
115
|
-
|
|
116
|
-
this.reader.cancel().catch(NOOP);
|
|
130
|
+
void tryCancel(this.reader);
|
|
117
131
|
});
|
|
118
132
|
// Manually pipe the stream
|
|
119
133
|
while (true) {
|
|
@@ -121,9 +135,7 @@ export class BufferedReadableStream {
|
|
|
121
135
|
if (done) {
|
|
122
136
|
return;
|
|
123
137
|
}
|
|
124
|
-
|
|
125
|
-
await controller.enqueue(value);
|
|
126
|
-
}
|
|
138
|
+
await controller.enqueue(value);
|
|
127
139
|
}
|
|
128
140
|
});
|
|
129
141
|
}
|
package/esm/buffered.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffered.js","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buffered.js","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,sBAAsB;IAC/B,SAAS,CAAyB;IAClC,2BAA2B;IAC3B,0CAA0C;IAC1C,eAAe,GAAG,CAAC,CAAC;IACpB,eAAe,GAAG,CAAC,CAAC;IAEpB,SAAS,GAAG,CAAC,CAAC;IACd,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAEkB,MAAM,CAA6B;IACnC,MAAM,CAA0C;IAEnE,YAAY,MAAkC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IACrC,CAAC;IAED,aAAa,CAAC,MAAc;QACxB,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YAClB,OAAO,SAAS,CAAC;QACrB,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CACjC,IAAI,CAAC,eAAe,EACpB,IAAI,CAAC,eAAe,GAAG,MAAM,CAChC,CAAC;QAEF,0DAA0D;QAC1D,IAAI,IAAI,CAAC,eAAe,GAAG,MAAM,EAAE,CAAC;YAChC,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC;YACzB,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC;YAC/B,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC;YAC/B,O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,CAAC;oBACjD,IAAI,IAAI,EAAE,CAAC;wBACP,OAAO;oBACX,CAAC;oBAED,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBACpC,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,kDAAkD;YAClD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,MAAM,CAAC;QACvB,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAgB;QACzB,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACJ"}
|
package/esm/concat.d.ts
CHANGED
|
@@ -22,9 +22,10 @@ export interface ConcatBufferReadableStream extends ReadableStream<Uint8Array>,
|
|
|
22
22
|
* A `TransformStream` that concatenates `Uint8Array`s.
|
|
23
23
|
*
|
|
24
24
|
* If you want to decode the result as string,
|
|
25
|
-
* prefer `.pipeThrough(new
|
|
26
|
-
* than `.pipeThough(new ConcatBufferStream()).pipeThrough(new
|
|
27
|
-
* because
|
|
25
|
+
* prefer `.pipeThrough(new TextDecoderStream()).pipeThrough(new ConcatStringStream())`,
|
|
26
|
+
* than `.pipeThough(new ConcatBufferStream()).pipeThrough(new TextDecoderStream())`,
|
|
27
|
+
* because of JavaScript engine optimizations,
|
|
28
|
+
* concatenating strings is faster than concatenating `Uint8Array`s.
|
|
28
29
|
*/
|
|
29
30
|
export declare class ConcatBufferStream {
|
|
30
31
|
#private;
|
package/esm/concat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../src/concat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../src/concat.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7D,MAAM,WAAW,0BACb,SAAQ,cAAc,CAAC,MAAM,CAAC,EAC1B,OAAO,CAAC,MAAM,CAAC;CAAG;AAO1B;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;;IAoB3B,IAAI,QAAQ,IAAI,cAAc,CAAC,MAAM,CAAC,CAErC;IAQD,IAAI,QAAQ,IAAI,0BAA0B,CAEzC;;CAkBJ;AAED,MAAM,WAAW,0BACb,SAAQ,cAAc,CAAC,UAAU,CAAC,EAC9B,OAAO,CAAC,UAAU,CAAC;CAAG;AAE9B;;;;;;;;GAQG;AACH,qBAAa,kBAAkB;;IA0C3B,IAAI,QAAQ,IAAI,cAAc,CAAC,UAAU,CAAC,CAEzC;IAQD,IAAI,QAAQ,IAAI,0BAA0B,CAEzC;;CAkBJ"}
|
package/esm/concat.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { EmptyUint8Array } from "@yume-chan/struct";
|
|
2
3
|
import { ReadableStream, WritableStream } from "./stream.js";
|
|
3
4
|
// `TransformStream` only calls its `source.flush` method when its `readable` is being read.
|
|
4
5
|
// If the user want to use the `Promise` interface, the `flush` method will never be called,
|
|
@@ -61,9 +62,10 @@ export class ConcatStringStream {
|
|
|
61
62
|
* A `TransformStream` that concatenates `Uint8Array`s.
|
|
62
63
|
*
|
|
63
64
|
* If you want to decode the result as string,
|
|
64
|
-
* prefer `.pipeThrough(new
|
|
65
|
-
* than `.pipeThough(new ConcatBufferStream()).pipeThrough(new
|
|
66
|
-
* because
|
|
65
|
+
* prefer `.pipeThrough(new TextDecoderStream()).pipeThrough(new ConcatStringStream())`,
|
|
66
|
+
* than `.pipeThough(new ConcatBufferStream()).pipeThrough(new TextDecoderStream())`,
|
|
67
|
+
* because of JavaScript engine optimizations,
|
|
68
|
+
* concatenating strings is faster than concatenating `Uint8Array`s.
|
|
67
69
|
*/
|
|
68
70
|
export class ConcatBufferStream {
|
|
69
71
|
#segments = [];
|
|
@@ -77,7 +79,7 @@ export class ConcatBufferStream {
|
|
|
77
79
|
let offset = 0;
|
|
78
80
|
switch (this.#segments.length) {
|
|
79
81
|
case 0:
|
|
80
|
-
result =
|
|
82
|
+
result = EmptyUint8Array;
|
|
81
83
|
break;
|
|
82
84
|
case 1:
|
|
83
85
|
result = this.#segments[0];
|
package/esm/concat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../src/concat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"concat.js","sourceRoot":"","sources":["../src/concat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAM7D,4FAA4F;AAC5F,4FAA4F;AAC5F,mDAAmD;AACnD,uGAAuG;AAEvG;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAkB;IAC3B,2DAA2D;IAC3D,OAAO,GAAG,EAAE,CAAC;IAEb,SAAS,GAAG,IAAI,eAAe,EAAU,CAAC;IAE1C,SAAS,GAAG,IAAI,cAAc,CAAS;QACnC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;YACb,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;QAC1B,CAAC;QACD,KAAK,EAAE,GAAG,EAAE;YACR,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/C,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;QACrC,CAAC;QACD,KAAK,EAAE,CAAC,MAAM,EAAE,EAAE;YACd,IAAI,CAAC,SAAS,C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;QACvC,KAAK,EAAE,CAAC,UAAU,EAAE,EAAE;YAClB,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC;QAC1C,CAAC;KACJ,CAA+B,CAAC;IACjC,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED;QACI,KAAK,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,EAAE;YACzC,IAAI,EAAE;gBACF,GAAG,EAAE,GAAG,EAAE,CACN,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAC/D;YACD,KAAK,EAAE;gBACH,GAAG,EAAE,GAAG,EAAE,CACN,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAChE;YACD,OAAO,EAAE;gBACL,GAAG,EAAE,GAAG,EAAE,CACN,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;aAClE;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/esm/consumable.d.ts
CHANGED
|
@@ -1,52 +1,45 @@
|
|
|
1
1
|
import type { QueuingStrategy, WritableStreamDefaultController, WritableStreamDefaultWriter } from "./stream.js";
|
|
2
|
-
import { ReadableStream
|
|
2
|
+
import { ReadableStream as NativeReadableStream, WritableStream as NativeWritableStream } from "./stream.js";
|
|
3
|
+
declare class WritableStream<in T> extends NativeWritableStream<Consumable<T>> {
|
|
4
|
+
static write<T>(writer: WritableStreamDefaultWriter<Consumable<T>>, value: T): Promise<void>;
|
|
5
|
+
constructor(sink: Consumable.WritableStreamSink<T>, strategy?: QueuingStrategy<T>);
|
|
6
|
+
}
|
|
7
|
+
declare class ReadableStream<T> extends NativeReadableStream<Consumable<T>> {
|
|
8
|
+
static enqueue<T>(controller: {
|
|
9
|
+
enqueue: (chunk: Consumable<T>) => void;
|
|
10
|
+
}, chunk: T): Promise<void>;
|
|
11
|
+
constructor(source: Consumable.ReadableStreamSource<T>, strategy?: QueuingStrategy<T>);
|
|
12
|
+
}
|
|
3
13
|
export declare class Consumable<T> {
|
|
4
14
|
#private;
|
|
15
|
+
static readonly WritableStream: typeof WritableStream;
|
|
16
|
+
static readonly ReadableStream: typeof ReadableStream;
|
|
5
17
|
readonly value: T;
|
|
6
18
|
readonly consumed: Promise<void>;
|
|
7
19
|
constructor(value: T);
|
|
8
20
|
consume(): void;
|
|
9
21
|
error(error: unknown): void;
|
|
10
|
-
tryConsume<U>(callback: (value: T) => U):
|
|
11
|
-
}
|
|
12
|
-
export declare
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
write?(chunk: T, controller: WritableStreamDefaultController): void | PromiseLike<void>;
|
|
34
|
-
abort?(reason: any): void | PromiseLike<void>;
|
|
35
|
-
close?(): void | PromiseLike<void>;
|
|
36
|
-
}
|
|
37
|
-
export declare class ConsumableWritableStream<T> extends WritableStream<Consumable<T>> {
|
|
38
|
-
static write<T>(writer: WritableStreamDefaultWriter<Consumable<T>>, value: T): Promise<void>;
|
|
39
|
-
constructor(sink: ConsumableWritableStreamSink<T>, strategy?: QueuingStrategy<T>);
|
|
40
|
-
}
|
|
41
|
-
export interface ConsumableTransformer<I, O> {
|
|
42
|
-
start?(controller: ConsumableReadableStreamController<O>): void | PromiseLike<void>;
|
|
43
|
-
transform?(chunk: I, controller: ConsumableReadableStreamController<O>): void | PromiseLike<void>;
|
|
44
|
-
flush?(controller: ConsumableReadableStreamController<O>): void | PromiseLike<void>;
|
|
45
|
-
}
|
|
46
|
-
export declare class ConsumableTransformStream<I, O> extends TransformStream<Consumable<I>, Consumable<O>> {
|
|
47
|
-
constructor(transformer: ConsumableTransformer<I, O>);
|
|
48
|
-
}
|
|
49
|
-
export declare class ConsumableInspectStream<T> extends TransformStream<Consumable<T>, Consumable<T>> {
|
|
50
|
-
constructor(callback: (value: T) => void);
|
|
51
|
-
}
|
|
22
|
+
tryConsume<U>(callback: (value: T) => U): U;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace Consumable {
|
|
25
|
+
interface WritableStreamSink<in T> {
|
|
26
|
+
start?(controller: WritableStreamDefaultController): void | PromiseLike<void>;
|
|
27
|
+
write?(chunk: T, controller: WritableStreamDefaultController): void | PromiseLike<void>;
|
|
28
|
+
abort?(reason: unknown): void | PromiseLike<void>;
|
|
29
|
+
close?(): void | PromiseLike<void>;
|
|
30
|
+
}
|
|
31
|
+
type WritableStream<in T> = typeof Consumable.WritableStream<T>;
|
|
32
|
+
interface ReadableStreamController<T> {
|
|
33
|
+
enqueue(chunk: T): Promise<void>;
|
|
34
|
+
close(): void;
|
|
35
|
+
error(reason: unknown): void;
|
|
36
|
+
}
|
|
37
|
+
interface ReadableStreamSource<T> {
|
|
38
|
+
start?(controller: ReadableStreamController<T>): void | PromiseLike<void>;
|
|
39
|
+
pull?(controller: ReadableStreamController<T>): void | PromiseLike<void>;
|
|
40
|
+
cancel?(reason: unknown): void | PromiseLike<void>;
|
|
41
|
+
}
|
|
42
|
+
type ReadableStream<T> = typeof Consumable.ReadableStream<T>;
|
|
43
|
+
}
|
|
44
|
+
export {};
|
|
52
45
|
//# sourceMappingURL=consumable.d.ts.map
|
package/esm/consumable.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumable.d.ts","sourceRoot":"","sources":["../src/consumable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,eAAe,EACf,+BAA+B,EAC/B,2BAA2B,EAC9B,MA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