@yume-chan/stream-extra 0.0.0-20240714132542
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 +76 -0
- package/LICENSE +21 -0
- package/README.md +43 -0
- package/esm/buffered-transform.d.ts +11 -0
- package/esm/buffered-transform.d.ts.map +1 -0
- package/esm/buffered-transform.js +57 -0
- package/esm/buffered-transform.js.map +1 -0
- package/esm/buffered.d.ts +23 -0
- package/esm/buffered.d.ts.map +1 -0
- package/esm/buffered.js +138 -0
- package/esm/buffered.js.map +1 -0
- package/esm/concat.d.ts +36 -0
- package/esm/concat.d.ts.map +1 -0
- package/esm/concat.js +130 -0
- package/esm/concat.js.map +1 -0
- package/esm/consumable.d.ts +40 -0
- package/esm/consumable.d.ts.map +1 -0
- package/esm/consumable.js +130 -0
- package/esm/consumable.js.map +1 -0
- package/esm/distribution.d.ts +22 -0
- package/esm/distribution.d.ts.map +1 -0
- package/esm/distribution.js +103 -0
- package/esm/distribution.js.map +1 -0
- package/esm/duplex.d.ts +45 -0
- package/esm/duplex.d.ts.map +1 -0
- package/esm/duplex.js +93 -0
- package/esm/duplex.js.map +1 -0
- 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 +19 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +19 -0
- package/esm/index.js.map +1 -0
- package/esm/inspect.d.ts +5 -0
- package/esm/inspect.d.ts.map +1 -0
- package/esm/inspect.js +12 -0
- package/esm/inspect.js.map +1 -0
- package/esm/maybe-consumable.d.ts +21 -0
- package/esm/maybe-consumable.d.ts.map +1 -0
- package/esm/maybe-consumable.js +62 -0
- package/esm/maybe-consumable.js.map +1 -0
- package/esm/pipe-from.d.ts +13 -0
- package/esm/pipe-from.d.ts.map +1 -0
- package/esm/pipe-from.js +24 -0
- package/esm/pipe-from.js.map +1 -0
- package/esm/push-readable.d.ts +35 -0
- package/esm/push-readable.d.ts.map +1 -0
- package/esm/push-readable.js +240 -0
- package/esm/push-readable.js.map +1 -0
- package/esm/split-string.d.ts +5 -0
- package/esm/split-string.d.ts.map +1 -0
- package/esm/split-string.js +25 -0
- package/esm/split-string.js.map +1 -0
- package/esm/stream.d.ts +25 -0
- package/esm/stream.d.ts.map +1 -0
- package/esm/stream.js +7 -0
- package/esm/stream.js.map +1 -0
- package/esm/struct-deserialize.d.ts +7 -0
- package/esm/struct-deserialize.d.ts.map +1 -0
- package/esm/struct-deserialize.js +9 -0
- package/esm/struct-deserialize.js.map +1 -0
- package/esm/struct-serialize.d.ts +6 -0
- package/esm/struct-serialize.d.ts.map +1 -0
- package/esm/struct-serialize.js +11 -0
- package/esm/struct-serialize.js.map +1 -0
- 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/types.d.ts +777 -0
- package/esm/types.d.ts.map +1 -0
- package/esm/types.js +3 -0
- package/esm/types.js.map +1 -0
- package/esm/wrap-readable.d.ts +22 -0
- package/esm/wrap-readable.d.ts.map +1 -0
- package/esm/wrap-readable.js +57 -0
- package/esm/wrap-readable.js.map +1 -0
- package/esm/wrap-writable.d.ts +15 -0
- package/esm/wrap-writable.d.ts.map +1 -0
- package/esm/wrap-writable.js +63 -0
- package/esm/wrap-writable.js.map +1 -0
- package/package.json +48 -0
- package/src/buffered-transform.ts +71 -0
- package/src/buffered.ts +160 -0
- package/src/concat.ts +162 -0
- package/src/consumable.ts +205 -0
- package/src/distribution.ts +123 -0
- package/src/duplex.ts +146 -0
- package/src/encoding.ts +39 -0
- package/src/index.ts +18 -0
- package/src/inspect.ts +12 -0
- package/src/maybe-consumable.ts +101 -0
- package/src/pipe-from.ts +28 -0
- package/src/push-readable.ts +307 -0
- package/src/split-string.ts +32 -0
- package/src/stream.ts +46 -0
- package/src/struct-deserialize.ts +14 -0
- package/src/struct-serialize.ts +15 -0
- package/src/task.ts +21 -0
- package/src/types.ts +881 -0
- package/src/wrap-readable.ts +93 -0
- package/src/wrap-writable.ts +88 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.build.tsbuildinfo +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,WAAW,WAAW;IAChC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B;;OAEG;IACH,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IAC5D;;OAEG;IACH,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CAClE;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,yBACjB,YAAW,eAAe,CAAC,eAAe,CAAC;gBAE/B,OAAO,EAAE,mBAAmB;IACxC;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAAC;IAC5B;;OAEG;IACH,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,eAAe,KAAK,MAAM,CAAC;CAClD;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,YAAW,eAAe,CAAC,OAAO,CAAC;gBAC7D,OAAO,EAAE,mBAAmB;IACxC;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAAC;IAC5B;;;OAGG;IACH,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;CACrC;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,eAAe,CAAC,CAAC;IACtC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG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;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,+BAA+B;IAChD,OAAO;IACP;;;;;;OAMG;IACH,IAAI,WAAW,IAAI,OAAO,CAAC;IAC3B;;OAEG;IACH,IAAI,MAAM,IAAI,WAAW,CAAC;IAC1B;;;;;;OAMG;IACH,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI;CAC3B;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,2BAA2B,CAAC,EAAE,CAAC,CAAC;gBACrC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IACrC;;;OAGG;IACH,IAAI,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IACjC;;;;;;;OAOG;IACH,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAAC;IACjC;;;;;;;OAOG;IACH,IAAI,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IACtC;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IACtB;;;;;;;;;OASG;IACH,WAAW,IAAI,IAAI;IACnB;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CACjC;AAED,OAAO,EAAE,CAAC"}
|
package/esm/types.js
ADDED
package/esm/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAg3B5C,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
2
|
+
import type { QueuingStrategy, ReadableStreamDefaultController } from "./stream.js";
|
|
3
|
+
import { ReadableStream } from "./stream.js";
|
|
4
|
+
export type WrapReadableStreamStart<T> = (controller: ReadableStreamDefaultController<T>) => ValueOrPromise<ReadableStream<T>>;
|
|
5
|
+
export interface ReadableStreamWrapper<T> {
|
|
6
|
+
start: WrapReadableStreamStart<T>;
|
|
7
|
+
cancel?(reason?: unknown): ValueOrPromise<void>;
|
|
8
|
+
close?(): ValueOrPromise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* This class has multiple usages:
|
|
12
|
+
*
|
|
13
|
+
* 1. Get notified when the stream is cancelled or closed.
|
|
14
|
+
* 2. Synchronously create a `ReadableStream` by asynchronously return another `ReadableStream`.
|
|
15
|
+
* 3. Convert native `ReadableStream`s to polyfilled ones so they can `pipe` between.
|
|
16
|
+
*/
|
|
17
|
+
export declare class WrapReadableStream<T> extends ReadableStream<T> {
|
|
18
|
+
#private;
|
|
19
|
+
readable: ReadableStream<T>;
|
|
20
|
+
constructor(wrapper: ReadableStream<T> | WrapReadableStreamStart<T> | ReadableStreamWrapper<T>, strategy?: QueuingStrategy<T>);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=wrap-readable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-readable.d.ts","sourceRoot":"","sources":["../src/wrap-readable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,KAAK,EACR,eAAe,EACf,+BAA+B,EAElC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,CACrC,UAAU,EAAE,+BAA+B,CAAC,CAAC,CAAC,KAC7C,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvC,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACpC,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;IAChD,KAAK,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;CAClC;AAoBD;;;;;;GAMG;AACH,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;;IACxD,QAAQ,EAAG,cAAc,CAAC,CAAC,CAAC,CAAC;gBAKzB,OAAO,EACD,cAAc,CAAC,CAAC,CAAC,GACjB,uBAAuB,CAAC,CAAC,CAAC,GAC1B,qBAAqB,CAAC,CAAC,CAAC,EAC9B,QAAQ,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;CAsCpC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ReadableStream } from "./stream.js";
|
|
2
|
+
function getWrappedReadableStream(wrapper, controller) {
|
|
3
|
+
if ("start" in wrapper) {
|
|
4
|
+
return wrapper.start(controller);
|
|
5
|
+
}
|
|
6
|
+
else if (typeof wrapper === "function") {
|
|
7
|
+
return wrapper(controller);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
// Can't use `wrapper instanceof ReadableStream`
|
|
11
|
+
// Because we want to be compatible with any ReadableStream-like objects
|
|
12
|
+
return wrapper;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* This class has multiple usages:
|
|
17
|
+
*
|
|
18
|
+
* 1. Get notified when the stream is cancelled or closed.
|
|
19
|
+
* 2. Synchronously create a `ReadableStream` by asynchronously return another `ReadableStream`.
|
|
20
|
+
* 3. Convert native `ReadableStream`s to polyfilled ones so they can `pipe` between.
|
|
21
|
+
*/
|
|
22
|
+
export class WrapReadableStream extends ReadableStream {
|
|
23
|
+
readable;
|
|
24
|
+
#reader;
|
|
25
|
+
constructor(wrapper, strategy) {
|
|
26
|
+
super({
|
|
27
|
+
start: async (controller) => {
|
|
28
|
+
// `start` is invoked before `ReadableStream`'s constructor finish,
|
|
29
|
+
// so using `this` synchronously causes
|
|
30
|
+
// "Must call super constructor in derived class before accessing 'this' or returning from derived constructor".
|
|
31
|
+
// Queue a microtask to avoid this.
|
|
32
|
+
await Promise.resolve();
|
|
33
|
+
this.readable = await getWrappedReadableStream(wrapper, controller);
|
|
34
|
+
this.#reader = this.readable.getReader();
|
|
35
|
+
},
|
|
36
|
+
pull: async (controller) => {
|
|
37
|
+
const result = await this.#reader.read();
|
|
38
|
+
if (result.done) {
|
|
39
|
+
controller.close();
|
|
40
|
+
if ("close" in wrapper) {
|
|
41
|
+
await wrapper.close?.();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
controller.enqueue(result.value);
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
cancel: async (reason) => {
|
|
49
|
+
await this.#reader.cancel(reason);
|
|
50
|
+
if ("cancel" in wrapper) {
|
|
51
|
+
await wrapper.cancel?.(reason);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}, strategy);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=wrap-readable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-readable.js","sourceRoot":"","sources":["../src/wrap-readable.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAY7C,SAAS,wBAAwB,CAC7B,OAG8B,EAC9B,UAA8C;IAE9C,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;QACrB,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;SAAM,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QACvC,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACJ,gDAAgD;QAChD,wEAAwE;QACxE,OAAO,OAAO,CAAC;IACnB,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAO,kBAAsB,SAAQ,cAAiB;IACxD,QAAQ,CAAqB;IAE7B,OAAO,CAAkC;IAEzC,YACI,OAG8B,EAC9B,QAA6B;QAE7B,KAAK,CACD;YACI,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;gBACxB,mEAAmE;gBACnE,uCAAuC;gBACvC,gHAAgH;gBAChH,mCAAmC;gBACnC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;gBAExB,IAAI,CAAC,QAAQ,GAAG,MAAM,wBAAwB,CAC1C,OAAO,EACP,UAAU,CACb,CAAC;gBACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;YAC7C,CAAC;YACD,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;gBACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;gBACzC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;oBACd,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;wBACrB,MAAM,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;oBAC5B,CAAC;gBACL,CAAC;qBAAM,CAAC;oBACJ,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACrC,CAAC;YACL,CAAC;YACD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;gBACrB,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAClC,IAAI,QAAQ,IAAI,OAAO,EAAE,CAAC;oBACtB,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;gBACnC,CAAC;YACL,CAAC;SACJ,EACD,QAAQ,CACX,CAAC;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
2
|
+
import type { TransformStream } from "./stream.js";
|
|
3
|
+
import { WritableStream } from "./stream.js";
|
|
4
|
+
export type WrapWritableStreamStart<T> = () => ValueOrPromise<WritableStream<T>>;
|
|
5
|
+
export interface WritableStreamWrapper<T> {
|
|
6
|
+
start: WrapWritableStreamStart<T>;
|
|
7
|
+
close?(): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare class WrapWritableStream<T> extends WritableStream<T> {
|
|
10
|
+
#private;
|
|
11
|
+
writable: WritableStream<T>;
|
|
12
|
+
constructor(start: WritableStream<T> | WrapWritableStreamStart<T> | WritableStreamWrapper<T>);
|
|
13
|
+
bePipedThroughFrom<U>(transformer: TransformStream<U, T>): WrapWritableStream<U>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=wrap-writable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-writable.d.ts","sourceRoot":"","sources":["../src/wrap-writable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,KAAK,EAAE,eAAe,EAA+B,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,MAAM,cAAc,CACzD,cAAc,CAAC,CAAC,CAAC,CACpB,CAAC;AAEF,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACpC,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAClC,KAAK,CAAC,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC;AAmBD,qBAAa,kBAAkB,CAAC,CAAC,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;;IACxD,QAAQ,EAAG,cAAc,CAAC,CAAC,CAAC,CAAC;gBAKzB,KAAK,EACC,cAAc,CAAC,CAAC,CAAC,GACjB,uBAAuB,CAAC,CAAC,CAAC,GAC1B,qBAAqB,CAAC,CAAC,CAAC;IAmClC,kBAAkB,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;CAY3D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { WritableStream } from "./stream.js";
|
|
2
|
+
async function getWrappedWritableStream(start) {
|
|
3
|
+
if ("start" in start) {
|
|
4
|
+
return await start.start();
|
|
5
|
+
}
|
|
6
|
+
else if (typeof start === "function") {
|
|
7
|
+
return await start();
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
// Can't use `wrapper instanceof WritableStream`
|
|
11
|
+
// Because we want to be compatible with any WritableStream-like objects
|
|
12
|
+
return start;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class WrapWritableStream extends WritableStream {
|
|
16
|
+
writable;
|
|
17
|
+
#writer;
|
|
18
|
+
constructor(start) {
|
|
19
|
+
super({
|
|
20
|
+
start: async () => {
|
|
21
|
+
// `start` is invoked before `ReadableStream`'s constructor finish,
|
|
22
|
+
// so using `this` synchronously causes
|
|
23
|
+
// "Must call super constructor in derived class before accessing 'this' or returning from derived constructor".
|
|
24
|
+
// Queue a microtask to avoid this.
|
|
25
|
+
await Promise.resolve();
|
|
26
|
+
this.writable = await getWrappedWritableStream(start);
|
|
27
|
+
this.#writer = this.writable.getWriter();
|
|
28
|
+
},
|
|
29
|
+
write: async (chunk) => {
|
|
30
|
+
await this.#writer.write(chunk);
|
|
31
|
+
},
|
|
32
|
+
abort: async (reason) => {
|
|
33
|
+
await this.#writer.abort(reason);
|
|
34
|
+
if (start !== this.writable && "close" in start) {
|
|
35
|
+
await start.close?.();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
close: async () => {
|
|
39
|
+
// Close the inner stream first.
|
|
40
|
+
// Usually the inner stream is a logical sub-stream over the outer stream,
|
|
41
|
+
// closing the outer stream first will make the inner stream incapable of
|
|
42
|
+
// sending data in its `close` handler.
|
|
43
|
+
await this.#writer.close();
|
|
44
|
+
if (start !== this.writable && "close" in start) {
|
|
45
|
+
await start.close?.();
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
bePipedThroughFrom(transformer) {
|
|
51
|
+
let promise;
|
|
52
|
+
return new WrapWritableStream({
|
|
53
|
+
start: () => {
|
|
54
|
+
promise = transformer.readable.pipeTo(this);
|
|
55
|
+
return transformer.writable;
|
|
56
|
+
},
|
|
57
|
+
async close() {
|
|
58
|
+
await promise;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=wrap-writable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrap-writable.js","sourceRoot":"","sources":["../src/wrap-writable.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAW7C,KAAK,UAAU,wBAAwB,CACnC,KAG8B;IAE9B,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;QACnB,OAAO,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QACrC,OAAO,MAAM,KAAK,EAAE,CAAC;IACzB,CAAC;SAAM,CAAC;QACJ,gDAAgD;QAChD,wEAAwE;QACxE,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC;AAED,MAAM,OAAO,kBAAsB,SAAQ,cAAiB;IACxD,QAAQ,CAAqB;IAE7B,OAAO,CAAkC;IAEzC,YACI,KAG8B;QAE9B,KAAK,CAAC;YACF,KAAK,EAAE,KAAK,IAAI,EAAE;gBACd,mEAAmE;gBACnE,uCAAuC;gBACvC,gHAAgH;gBAChH,mCAAmC;gBACnC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;gBAExB,IAAI,CAAC,QAAQ,GAAG,MAAM,wBAAwB,CAAC,KAAK,CAAC,CAAC;gBACtD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,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240714132542",
|
|
4
|
+
"description": "Extensions to Web Streams API",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"stream",
|
|
7
|
+
"web-streams-api"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Simon Chan",
|
|
12
|
+
"email": "cnsimonchan@live.com",
|
|
13
|
+
"url": "https://chensi.moe/blog"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/yume-chan/ya-webadb/tree/main/packages/stream-extra#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/yume-chan/ya-webadb.git",
|
|
19
|
+
"directory": "packages/stream-extra"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/yume-chan/ya-webadb/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "esm/index.js",
|
|
26
|
+
"types": "esm/index.d.ts",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@yume-chan/async": "^2.2.0",
|
|
30
|
+
"@yume-chan/struct": "0.0.0-20240714132542"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@jest/globals": "^30.0.0-alpha.4",
|
|
34
|
+
"@yume-chan/eslint-config": "^1.0.0",
|
|
35
|
+
"@yume-chan/tsconfig": "^1.0.0",
|
|
36
|
+
"cross-env": "^7.0.3",
|
|
37
|
+
"jest": "^30.0.0-alpha.4",
|
|
38
|
+
"prettier": "^3.3.3",
|
|
39
|
+
"ts-jest": "^29.2.2",
|
|
40
|
+
"typescript": "^5.5.3"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -b tsconfig.build.json",
|
|
44
|
+
"build:watch": "tsc -b tsconfig.build.json",
|
|
45
|
+
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" TS_JEST_DISABLE_VER_CHECKER=true jest --coverage",
|
|
46
|
+
"lint": "run-eslint && prettier src/**/*.ts --write --tab-width 4"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
2
|
+
import { StructEmptyError } from "@yume-chan/struct";
|
|
3
|
+
|
|
4
|
+
import { BufferedReadableStream } from "./buffered.js";
|
|
5
|
+
import type { PushReadableStreamController } from "./push-readable.js";
|
|
6
|
+
import { PushReadableStream } from "./push-readable.js";
|
|
7
|
+
import type { ReadableWritablePair } from "./stream.js";
|
|
8
|
+
import { ReadableStream, WritableStream } from "./stream.js";
|
|
9
|
+
|
|
10
|
+
// TODO: BufferedTransformStream: find better implementation
|
|
11
|
+
export class BufferedTransformStream<T>
|
|
12
|
+
implements ReadableWritablePair<T, Uint8Array>
|
|
13
|
+
{
|
|
14
|
+
#readable: ReadableStream<T>;
|
|
15
|
+
get readable() {
|
|
16
|
+
return this.#readable;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#writable: WritableStream<Uint8Array>;
|
|
20
|
+
get writable() {
|
|
21
|
+
return this.#writable;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
transform: (stream: BufferedReadableStream) => ValueOrPromise<T>,
|
|
26
|
+
) {
|
|
27
|
+
// Convert incoming chunks to a `BufferedReadableStream`
|
|
28
|
+
let sourceStreamController!: PushReadableStreamController<Uint8Array>;
|
|
29
|
+
|
|
30
|
+
const buffered = new BufferedReadableStream(
|
|
31
|
+
new PushReadableStream<Uint8Array>((controller) => {
|
|
32
|
+
sourceStreamController = controller;
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
this.#readable = new ReadableStream<T>({
|
|
37
|
+
async pull(controller) {
|
|
38
|
+
try {
|
|
39
|
+
const value = await transform(buffered);
|
|
40
|
+
controller.enqueue(value);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
// Treat `StructEmptyError` as a normal end.
|
|
43
|
+
// If the `transform` method doesn't have enough data to return a value,
|
|
44
|
+
// it should throw another error to indicate that.
|
|
45
|
+
if (e instanceof StructEmptyError) {
|
|
46
|
+
controller.close();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
cancel: (reason) => {
|
|
53
|
+
// Propagate cancel to the source stream
|
|
54
|
+
// So future writes will be rejected
|
|
55
|
+
return buffered.cancel(reason);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.#writable = new WritableStream({
|
|
60
|
+
async write(chunk) {
|
|
61
|
+
await sourceStreamController.enqueue(chunk);
|
|
62
|
+
},
|
|
63
|
+
abort() {
|
|
64
|
+
sourceStreamController.close();
|
|
65
|
+
},
|
|
66
|
+
close() {
|
|
67
|
+
sourceStreamController.close();
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/buffered.ts
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { AsyncExactReadable } from "@yume-chan/struct";
|
|
2
|
+
import { ExactReadableEndedError } from "@yume-chan/struct";
|
|
3
|
+
|
|
4
|
+
import { PushReadableStream } from "./push-readable.js";
|
|
5
|
+
import type { ReadableStream, ReadableStreamDefaultReader } from "./stream.js";
|
|
6
|
+
|
|
7
|
+
const NOOP = () => {
|
|
8
|
+
// no-op
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class BufferedReadableStream implements AsyncExactReadable {
|
|
12
|
+
#buffered: Uint8Array | undefined;
|
|
13
|
+
#bufferedOffset = 0;
|
|
14
|
+
#bufferedLength = 0;
|
|
15
|
+
|
|
16
|
+
#position = 0;
|
|
17
|
+
get position() {
|
|
18
|
+
return this.#position;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected readonly stream: ReadableStream<Uint8Array>;
|
|
22
|
+
protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
23
|
+
|
|
24
|
+
constructor(stream: ReadableStream<Uint8Array>) {
|
|
25
|
+
this.stream = stream;
|
|
26
|
+
this.reader = stream.getReader();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async #readSource() {
|
|
30
|
+
const { done, value } = await this.reader.read();
|
|
31
|
+
if (done) {
|
|
32
|
+
throw new ExactReadableEndedError();
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async #readAsync(length: number, initial?: Uint8Array) {
|
|
38
|
+
let result: Uint8Array;
|
|
39
|
+
let index: number;
|
|
40
|
+
|
|
41
|
+
if (initial) {
|
|
42
|
+
result = new Uint8Array(length);
|
|
43
|
+
result.set(initial);
|
|
44
|
+
index = initial.length;
|
|
45
|
+
length -= initial.length;
|
|
46
|
+
} else {
|
|
47
|
+
const array = await this.#readSource();
|
|
48
|
+
if (array.length === length) {
|
|
49
|
+
this.#position += length;
|
|
50
|
+
return array;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (array.length > length) {
|
|
54
|
+
this.#buffered = array;
|
|
55
|
+
this.#bufferedOffset = length;
|
|
56
|
+
this.#bufferedLength = array.length - length;
|
|
57
|
+
this.#position += length;
|
|
58
|
+
return array.subarray(0, length);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
result = new Uint8Array(length);
|
|
62
|
+
result.set(array);
|
|
63
|
+
index = array.length;
|
|
64
|
+
length -= array.length;
|
|
65
|
+
this.#position += array.length;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
while (length > 0) {
|
|
69
|
+
const array = await this.#readSource();
|
|
70
|
+
if (array.length === length) {
|
|
71
|
+
result.set(array, index);
|
|
72
|
+
this.#position += length;
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (array.length > length) {
|
|
77
|
+
this.#buffered = array;
|
|
78
|
+
this.#bufferedOffset = length;
|
|
79
|
+
this.#bufferedLength = array.length - length;
|
|
80
|
+
result.set(array.subarray(0, length), index);
|
|
81
|
+
this.#position += length;
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
result.set(array, index);
|
|
86
|
+
index += array.length;
|
|
87
|
+
length -= array.length;
|
|
88
|
+
this.#position += array.length;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param length
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
readExactly(length: number): Uint8Array | Promise<Uint8Array> {
|
|
100
|
+
// PERF: Add a synchronous path for reading from internal buffer
|
|
101
|
+
if (this.#buffered) {
|
|
102
|
+
const array = this.#buffered;
|
|
103
|
+
const offset = this.#bufferedOffset;
|
|
104
|
+
if (this.#bufferedLength > length) {
|
|
105
|
+
// PERF: `subarray` is slow
|
|
106
|
+
// don't use it until absolutely necessary
|
|
107
|
+
this.#bufferedOffset += length;
|
|
108
|
+
this.#bufferedLength -= length;
|
|
109
|
+
this.#position += length;
|
|
110
|
+
return array.subarray(offset, offset + length);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
this.#buffered = undefined;
|
|
114
|
+
this.#bufferedLength = 0;
|
|
115
|
+
this.#bufferedOffset = 0;
|
|
116
|
+
this.#position += array.length - offset;
|
|
117
|
+
return this.#readAsync(length, array.subarray(offset));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return this.#readAsync(length);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Return a readable stream with unconsumed data (if any) and
|
|
125
|
+
* all data from the wrapped stream.
|
|
126
|
+
* @returns A `ReadableStream`
|
|
127
|
+
*/
|
|
128
|
+
release(): ReadableStream<Uint8Array> {
|
|
129
|
+
if (this.#bufferedLength > 0) {
|
|
130
|
+
return new PushReadableStream<Uint8Array>(async (controller) => {
|
|
131
|
+
// Put the remaining data back to the stream
|
|
132
|
+
const buffered = this.#buffered!.subarray(this.#bufferedOffset);
|
|
133
|
+
await controller.enqueue(buffered);
|
|
134
|
+
|
|
135
|
+
controller.abortSignal.addEventListener("abort", () => {
|
|
136
|
+
// NOOP: the reader might already be released
|
|
137
|
+
this.reader.cancel().catch(NOOP);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// Manually pipe the stream
|
|
141
|
+
while (true) {
|
|
142
|
+
const { done, value } = await this.reader.read();
|
|
143
|
+
if (done) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await controller.enqueue(value);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
// Simply release the reader and return the stream
|
|
152
|
+
this.reader.releaseLock();
|
|
153
|
+
return this.stream;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async cancel(reason?: unknown) {
|
|
158
|
+
await this.reader.cancel(reason);
|
|
159
|
+
}
|
|
160
|
+
}
|
package/src/concat.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { EMPTY_UINT8_ARRAY } from "@yume-chan/struct";
|
|
3
|
+
|
|
4
|
+
import type { ReadableStreamDefaultController } from "./stream.js";
|
|
5
|
+
import { ReadableStream, WritableStream } from "./stream.js";
|
|
6
|
+
|
|
7
|
+
export interface ConcatStringReadableStream
|
|
8
|
+
extends ReadableStream<string>,
|
|
9
|
+
Promise<string> {}
|
|
10
|
+
|
|
11
|
+
// `TransformStream` only calls its `source.flush` method when its `readable` is being read.
|
|
12
|
+
// If the user want to use the `Promise` interface, the `flush` method will never be called,
|
|
13
|
+
// so the `PromiseResolver` will never be resolved.
|
|
14
|
+
// Thus we need to implement our own `TransformStream` using a `WritableStream` and a `ReadableStream`.
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A `TransformStream` that concatenates strings.
|
|
18
|
+
*
|
|
19
|
+
* Its `readable` is also a `Promise<string>`, so it's possible to `await` it to get the result.
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* const result: string = await readable.pipeThrough(new ConcatStringStream());
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class ConcatStringStream {
|
|
26
|
+
// PERF: rope (concat strings) is faster than `[].join('')`
|
|
27
|
+
#result = "";
|
|
28
|
+
|
|
29
|
+
#resolver = new PromiseResolver<string>();
|
|
30
|
+
|
|
31
|
+
#writable = new WritableStream<string>({
|
|
32
|
+
write: (chunk) => {
|
|
33
|
+
this.#result += chunk;
|
|
34
|
+
},
|
|
35
|
+
close: () => {
|
|
36
|
+
this.#resolver.resolve(this.#result);
|
|
37
|
+
this.#readableController.enqueue(this.#result);
|
|
38
|
+
this.#readableController.close();
|
|
39
|
+
},
|
|
40
|
+
abort: (reason) => {
|
|
41
|
+
this.#resolver.reject(reason);
|
|
42
|
+
this.#readableController.error(reason);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
get writable(): WritableStream<string> {
|
|
46
|
+
return this.#writable;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#readableController!: ReadableStreamDefaultController<string>;
|
|
50
|
+
#readable = new ReadableStream<string>({
|
|
51
|
+
start: (controller) => {
|
|
52
|
+
this.#readableController = controller;
|
|
53
|
+
},
|
|
54
|
+
}) as ConcatStringReadableStream;
|
|
55
|
+
get readable(): ConcatStringReadableStream {
|
|
56
|
+
return this.#readable;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
constructor() {
|
|
60
|
+
void Object.defineProperties(this.#readable, {
|
|
61
|
+
then: {
|
|
62
|
+
get: () =>
|
|
63
|
+
this.#resolver.promise.then.bind(this.#resolver.promise),
|
|
64
|
+
},
|
|
65
|
+
catch: {
|
|
66
|
+
get: () =>
|
|
67
|
+
this.#resolver.promise.catch.bind(this.#resolver.promise),
|
|
68
|
+
},
|
|
69
|
+
finally: {
|
|
70
|
+
get: () =>
|
|
71
|
+
this.#resolver.promise.finally.bind(this.#resolver.promise),
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ConcatBufferReadableStream
|
|
78
|
+
extends ReadableStream<Uint8Array>,
|
|
79
|
+
Promise<Uint8Array> {}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* A `TransformStream` that concatenates `Uint8Array`s.
|
|
83
|
+
*
|
|
84
|
+
* If you want to decode the result as string,
|
|
85
|
+
* prefer `.pipeThrough(new TextDecoderStream()).pipeThrough(new ConcatStringStream())`,
|
|
86
|
+
* than `.pipeThough(new ConcatBufferStream()).pipeThrough(new TextDecoderStream())`,
|
|
87
|
+
* because of JavaScript engine optimizations,
|
|
88
|
+
* concatenating strings is faster than concatenating `Uint8Array`s.
|
|
89
|
+
*/
|
|
90
|
+
export class ConcatBufferStream {
|
|
91
|
+
#segments: Uint8Array[] = [];
|
|
92
|
+
|
|
93
|
+
#resolver = new PromiseResolver<Uint8Array>();
|
|
94
|
+
|
|
95
|
+
#writable = new WritableStream<Uint8Array>({
|
|
96
|
+
write: (chunk) => {
|
|
97
|
+
this.#segments.push(chunk);
|
|
98
|
+
},
|
|
99
|
+
close: () => {
|
|
100
|
+
let result: Uint8Array;
|
|
101
|
+
let offset = 0;
|
|
102
|
+
switch (this.#segments.length) {
|
|
103
|
+
case 0:
|
|
104
|
+
result = EMPTY_UINT8_ARRAY;
|
|
105
|
+
break;
|
|
106
|
+
case 1:
|
|
107
|
+
result = this.#segments[0]!;
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
result = new Uint8Array(
|
|
111
|
+
this.#segments.reduce(
|
|
112
|
+
(prev, item) => prev + item.length,
|
|
113
|
+
0,
|
|
114
|
+
),
|
|
115
|
+
);
|
|
116
|
+
for (const segment of this.#segments) {
|
|
117
|
+
result.set(segment, offset);
|
|
118
|
+
offset += segment.length;
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.#resolver.resolve(result);
|
|
124
|
+
this.#readableController.enqueue(result);
|
|
125
|
+
this.#readableController.close();
|
|
126
|
+
},
|
|
127
|
+
abort: (reason) => {
|
|
128
|
+
this.#resolver.reject(reason);
|
|
129
|
+
this.#readableController.error(reason);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
get writable(): WritableStream<Uint8Array> {
|
|
133
|
+
return this.#writable;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#readableController!: ReadableStreamDefaultController<Uint8Array>;
|
|
137
|
+
#readable = new ReadableStream<Uint8Array>({
|
|
138
|
+
start: (controller) => {
|
|
139
|
+
this.#readableController = controller;
|
|
140
|
+
},
|
|
141
|
+
}) as ConcatBufferReadableStream;
|
|
142
|
+
get readable(): ConcatBufferReadableStream {
|
|
143
|
+
return this.#readable;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
constructor() {
|
|
147
|
+
void Object.defineProperties(this.#readable, {
|
|
148
|
+
then: {
|
|
149
|
+
get: () =>
|
|
150
|
+
this.#resolver.promise.then.bind(this.#resolver.promise),
|
|
151
|
+
},
|
|
152
|
+
catch: {
|
|
153
|
+
get: () =>
|
|
154
|
+
this.#resolver.promise.catch.bind(this.#resolver.promise),
|
|
155
|
+
},
|
|
156
|
+
finally: {
|
|
157
|
+
get: () =>
|
|
158
|
+
this.#resolver.promise.finally.bind(this.#resolver.promise),
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|