@yume-chan/stream-extra 0.0.17
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 +11 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/esm/buffered-transform.d.ts +11 -0
- package/esm/buffered-transform.d.ts.map +1 -0
- package/esm/buffered-transform.js +50 -0
- package/esm/buffered-transform.js.map +1 -0
- package/esm/buffered.d.ts +28 -0
- package/esm/buffered.d.ts.map +1 -0
- package/esm/buffered.js +131 -0
- package/esm/buffered.js.map +1 -0
- package/esm/chunk.d.ts +5 -0
- package/esm/chunk.d.ts.map +1 -0
- package/esm/chunk.js +15 -0
- package/esm/chunk.js.map +1 -0
- package/esm/decode-utf8.d.ts +5 -0
- package/esm/decode-utf8.d.ts.map +1 -0
- package/esm/decode-utf8.js +12 -0
- package/esm/decode-utf8.js.map +1 -0
- package/esm/duplex.d.ts +48 -0
- package/esm/duplex.d.ts.map +1 -0
- package/esm/duplex.js +89 -0
- package/esm/duplex.js.map +1 -0
- package/esm/gather-string.d.ts +7 -0
- package/esm/gather-string.d.ts.map +1 -0
- package/esm/gather-string.js +14 -0
- package/esm/gather-string.js.map +1 -0
- package/esm/index.d.ts +16 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +16 -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/native.d.ts +240 -0
- package/esm/native.d.ts.map +1 -0
- package/esm/native.js +60 -0
- package/esm/native.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 +27 -0
- package/esm/pipe-from.js.map +1 -0
- package/esm/push-readable.d.ts +12 -0
- package/esm/push-readable.d.ts.map +1 -0
- package/esm/push-readable.js +47 -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 +18 -0
- package/esm/stream.d.ts.map +1 -0
- package/esm/stream.js +4 -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/wrap-readable.d.ts +21 -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 +13 -0
- package/esm/wrap-writable.d.ts.map +1 -0
- package/esm/wrap-writable.js +53 -0
- package/esm/wrap-writable.js.map +1 -0
- package/package.json +46 -0
- package/src/buffered-transform.ts +58 -0
- package/src/buffered.ts +148 -0
- package/src/chunk.ts +15 -0
- package/src/decode-utf8.ts +12 -0
- package/src/duplex.ts +120 -0
- package/src/gather-string.ts +15 -0
- package/src/index.ts +15 -0
- package/src/inspect.ts +12 -0
- package/src/native.ts +362 -0
- package/src/pipe-from.ts +27 -0
- package/src/push-readable.ts +62 -0
- package/src/split-string.ts +29 -0
- package/src/stream.ts +22 -0
- package/src/struct-deserialize.ts +12 -0
- package/src/struct-serialize.ts +13 -0
- package/src/wrap-readable.ts +70 -0
- package/src/wrap-writable.ts +65 -0
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
package/CHANGELOG.json
ADDED
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2022 Simon Chan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @yume-chan/stream-extra
|
|
2
|
+
|
|
3
|
+
Some useful extensions for Web Streams API.
|
|
4
|
+
|
|
5
|
+
Currently it's using [web-streams-polyfill](https://github.com/MattiasBuelens/web-streams-polyfill) because it's hard to load native implementations from both browsers and Node.js. (An experimental implementation using Top Level Await is available in `native.ts`, but not exported).
|
|
6
|
+
|
|
7
|
+
## `BufferedReadableStream`
|
|
8
|
+
|
|
9
|
+
Allowing reading specified amount of data by buffering incoming data.
|
|
10
|
+
|
|
11
|
+
It's not a Web Stream API `ReadableStream`, because `ReadableStream` doesn't allow hinting the desired read size (except using BYOB readable, but causes extra allocations for small reads).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ValueOrPromise } from '@yume-chan/struct';
|
|
2
|
+
import { BufferedReadableStream } from './buffered.js';
|
|
3
|
+
import { ReadableStream, ReadableWritablePair, WritableStream } from './stream.js';
|
|
4
|
+
export declare class BufferedTransformStream<T> implements ReadableWritablePair<T, Uint8Array> {
|
|
5
|
+
private _readable;
|
|
6
|
+
get readable(): ReadableStream<T>;
|
|
7
|
+
private _writable;
|
|
8
|
+
get writable(): WritableStream<Uint8Array>;
|
|
9
|
+
constructor(transform: (stream: BufferedReadableStream) => ValueOrPromise<T>);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=buffered-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AACxD,OAAO,EAAE,sBAAsB,EAAoC,MAAM,eAAe,CAAC;AAEzF,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGnF,qBAAa,uBAAuB,CAAC,CAAC,CAAE,YAAW,oBAAoB,CAAC,CAAC,EAAE,UAAU,CAAC;IAClF,OAAO,CAAC,SAAS,CAAoB;IACrC,IAAW,QAAQ,sBAA6B;IAEhD,OAAO,CAAC,SAAS,CAA6B;IAC9C,IAAW,QAAQ,+BAA6B;gBAEpC,SAAS,EAAE,CAAC,MAAM,EAAE,sBAAsB,KAAK,cAAc,CAAC,CAAC,CAAC;CA4C/E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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() { return this._readable; }
|
|
8
|
+
_writable;
|
|
9
|
+
get writable() { return this._writable; }
|
|
10
|
+
constructor(transform) {
|
|
11
|
+
// Convert incoming chunks to a `BufferedReadableStream`
|
|
12
|
+
let sourceStreamController;
|
|
13
|
+
const buffered = new BufferedReadableStream(new PushReadableStream(controller => sourceStreamController = controller));
|
|
14
|
+
this._readable = new ReadableStream({
|
|
15
|
+
async pull(controller) {
|
|
16
|
+
try {
|
|
17
|
+
const value = await transform(buffered);
|
|
18
|
+
controller.enqueue(value);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
// TODO: BufferedTransformStream: The semantic of stream ending is not clear
|
|
22
|
+
// If the `transform` started but did not finish, it should really be an error?
|
|
23
|
+
// But we can't detect that, unless there is a `peek` method on buffered stream.
|
|
24
|
+
if (e instanceof BufferedReadableStreamEndedError) {
|
|
25
|
+
controller.close();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
throw e;
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
cancel: (reason) => {
|
|
32
|
+
// Propagate cancel to the source stream
|
|
33
|
+
// So future writes will be rejected
|
|
34
|
+
buffered.cancel(reason);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
this._writable = new WritableStream({
|
|
38
|
+
async write(chunk) {
|
|
39
|
+
await sourceStreamController.enqueue(chunk);
|
|
40
|
+
},
|
|
41
|
+
abort() {
|
|
42
|
+
sourceStreamController.close();
|
|
43
|
+
},
|
|
44
|
+
close() {
|
|
45
|
+
sourceStreamController.close();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=buffered-transform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffered-transform.js","sourceRoot":"","sources":["../src/buffered-transform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,gC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,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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
protected readonly stream: ReadableStream<Uint8Array>;
|
|
10
|
+
protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
11
|
+
constructor(stream: ReadableStream<Uint8Array>);
|
|
12
|
+
private readSource;
|
|
13
|
+
private readAsync;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param length
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
read(length: number): Uint8Array | Promise<Uint8Array>;
|
|
20
|
+
/**
|
|
21
|
+
* Return a readable stream with unconsumed data (if any) and
|
|
22
|
+
* all data from the wrapped stream.
|
|
23
|
+
* @returns A `ReadableStream`
|
|
24
|
+
*/
|
|
25
|
+
release(): ReadableStream<Uint8Array>;
|
|
26
|
+
cancel(reason?: any): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=buffered.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAEtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;gBAEhD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;YAKvC,UAAU;YAQV,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;IA6BrC,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG;CAG7B"}
|
package/esm/buffered.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
stream;
|
|
14
|
+
reader;
|
|
15
|
+
constructor(stream) {
|
|
16
|
+
this.stream = stream;
|
|
17
|
+
this.reader = stream.getReader();
|
|
18
|
+
}
|
|
19
|
+
async readSource() {
|
|
20
|
+
const { done, value } = await this.reader.read();
|
|
21
|
+
if (done) {
|
|
22
|
+
throw new BufferedReadableStreamEndedError();
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
async readAsync(length, initial) {
|
|
27
|
+
let result;
|
|
28
|
+
let index;
|
|
29
|
+
if (initial) {
|
|
30
|
+
result = new Uint8Array(length);
|
|
31
|
+
result.set(initial);
|
|
32
|
+
index = initial.byteLength;
|
|
33
|
+
length -= initial.byteLength;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const array = await this.readSource();
|
|
37
|
+
if (array.byteLength === length) {
|
|
38
|
+
return array;
|
|
39
|
+
}
|
|
40
|
+
if (array.byteLength > length) {
|
|
41
|
+
this.buffered = array;
|
|
42
|
+
this.bufferedOffset = length;
|
|
43
|
+
this.bufferedLength = array.byteLength - length;
|
|
44
|
+
return array.subarray(0, length);
|
|
45
|
+
}
|
|
46
|
+
result = new Uint8Array(length);
|
|
47
|
+
result.set(array);
|
|
48
|
+
index = array.byteLength;
|
|
49
|
+
length -= array.byteLength;
|
|
50
|
+
}
|
|
51
|
+
while (length > 0) {
|
|
52
|
+
const array = await this.readSource();
|
|
53
|
+
if (array.byteLength === length) {
|
|
54
|
+
result.set(array, index);
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
if (array.byteLength > length) {
|
|
58
|
+
this.buffered = array;
|
|
59
|
+
this.bufferedOffset = length;
|
|
60
|
+
this.bufferedLength = array.byteLength - length;
|
|
61
|
+
result.set(array.subarray(0, length), index);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
result.set(array, index);
|
|
65
|
+
index += array.byteLength;
|
|
66
|
+
length -= array.byteLength;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param length
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
read(length) {
|
|
76
|
+
// PERF: Add a synchronous path for reading from internal buffer
|
|
77
|
+
if (this.buffered) {
|
|
78
|
+
const array = this.buffered;
|
|
79
|
+
const offset = this.bufferedOffset;
|
|
80
|
+
if (this.bufferedLength > length) {
|
|
81
|
+
// PERF: `subarray` is slow
|
|
82
|
+
// don't use it until absolutely necessary
|
|
83
|
+
this.bufferedOffset += length;
|
|
84
|
+
this.bufferedLength -= length;
|
|
85
|
+
return array.subarray(offset, offset + length);
|
|
86
|
+
}
|
|
87
|
+
this.buffered = undefined;
|
|
88
|
+
return this.readAsync(length, array.subarray(offset));
|
|
89
|
+
}
|
|
90
|
+
return this.readAsync(length);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Return a readable stream with unconsumed data (if any) and
|
|
94
|
+
* all data from the wrapped stream.
|
|
95
|
+
* @returns A `ReadableStream`
|
|
96
|
+
*/
|
|
97
|
+
release() {
|
|
98
|
+
if (this.buffered) {
|
|
99
|
+
return new PushReadableStream(async (controller) => {
|
|
100
|
+
// Put the remaining data back to the stream
|
|
101
|
+
await controller.enqueue(this.buffered);
|
|
102
|
+
// Manually pipe the stream
|
|
103
|
+
while (true) {
|
|
104
|
+
try {
|
|
105
|
+
const { done, value } = await this.reader.read();
|
|
106
|
+
if (done) {
|
|
107
|
+
controller.close();
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
await controller.enqueue(value);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
controller.error(e);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Simply release the reader and return the stream
|
|
123
|
+
this.reader.releaseLock();
|
|
124
|
+
return this.stream;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
cancel(reason) {
|
|
128
|
+
return this.reader.cancel(reason);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=buffered.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffered.js","sourceRoot":"","sources":["../src/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,MAAM,OAAO,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D;YAClD,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC,MAAM,CAAC;SACtB;IACL,CAAC;IAEM,MAAM,CAAC,MAAY;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;CACJ"}
|
package/esm/chunk.d.ts
ADDED
|
@@ -0,0 +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,WAAY,SAAQ,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC;gBACjD,IAAI,EAAE,MAAM;CAWlC"}
|
package/esm/chunk.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TransformStream } from "./stream.js";
|
|
2
|
+
export class ChunkStream extends TransformStream {
|
|
3
|
+
constructor(size) {
|
|
4
|
+
super({
|
|
5
|
+
transform(chunk, controller) {
|
|
6
|
+
for (let start = 0; start < chunk.byteLength;) {
|
|
7
|
+
const end = start + size;
|
|
8
|
+
controller.enqueue(chunk.subarray(start, end));
|
|
9
|
+
start = end;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=chunk.js.map
|
package/esm/chunk.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../src/chunk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,WAAY,SAAQ,eAAuC;IACpE,YAAmB,IAAY;QAC3B,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAE,UAAU;gBACvB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,UAAU,GAAG;oBAC3C,MAAM,GAAG,GAAG,KAAK,GAAG,IAAI,CAAC;oBACzB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;oBAC/C,KAAK,GAAG,GAAG,CAAC;iBACf;YACL,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-utf8.d.ts","sourceRoot":"","sources":["../src/decode-utf8.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,qBAAa,gBAAiB,SAAQ,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC;;CAQxE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { decodeUtf8 } from '@yume-chan/struct';
|
|
2
|
+
import { TransformStream } from "./stream.js";
|
|
3
|
+
export class DecodeUtf8Stream extends TransformStream {
|
|
4
|
+
constructor() {
|
|
5
|
+
super({
|
|
6
|
+
transform(chunk, controller) {
|
|
7
|
+
controller.enqueue(decodeUtf8(chunk));
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=decode-utf8.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-utf8.js","sourceRoot":"","sources":["../src/decode-utf8.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,gBAAiB,SAAQ,eAAmC;IACrE;QACI,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAE,UAAU;gBACvB,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;YAC1C,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/esm/duplex.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
2
|
+
import { WritableStream, type ReadableStream } from "./stream.js";
|
|
3
|
+
import { WrapReadableStream } from "./wrap-readable.js";
|
|
4
|
+
export interface DuplexStreamFactoryOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Callback when any `ReadableStream` is cancelled (the user doesn't need any more data),
|
|
7
|
+
* or `WritableStream` is ended (the user won't produce any more data),
|
|
8
|
+
* or `DuplexStreamFactory#close` is called.
|
|
9
|
+
*
|
|
10
|
+
* Usually you want to let the other peer know that the duplex stream should be clsoed.
|
|
11
|
+
*
|
|
12
|
+
* `dispose` will automatically be called after `close` completes,
|
|
13
|
+
* but if you want to wait another peer for a close confirmation and call
|
|
14
|
+
* `DuplexStreamFactory#dispose` yourself, you can return `false`
|
|
15
|
+
* (or a `Promise` that resolves to `false`) to disable the automatic call.
|
|
16
|
+
*/
|
|
17
|
+
close?: (() => ValueOrPromise<boolean | void>) | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Callback when any `ReadableStream` is closed (the other peer doesn't produce any more data),
|
|
20
|
+
* or `WritableStream` is aborted (the other peer can't receive any more data),
|
|
21
|
+
* or `DuplexStreamFactory#abort` is called.
|
|
22
|
+
*
|
|
23
|
+
* Usually indicates the other peer has closed the duplex stream. You can clean up
|
|
24
|
+
* any resources you have allocated now.
|
|
25
|
+
*/
|
|
26
|
+
dispose?: (() => void | Promise<void>) | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A factory for creating a duplex stream.
|
|
30
|
+
*
|
|
31
|
+
* It can create multiple `ReadableStream`s and `WritableStream`s,
|
|
32
|
+
* when any of them is closed, all other streams will be closed as well.
|
|
33
|
+
*/
|
|
34
|
+
export declare class DuplexStreamFactory<R, W> {
|
|
35
|
+
private readableControllers;
|
|
36
|
+
private writers;
|
|
37
|
+
private _writableClosed;
|
|
38
|
+
get writableClosed(): boolean;
|
|
39
|
+
private _closed;
|
|
40
|
+
get closed(): Promise<void>;
|
|
41
|
+
private options;
|
|
42
|
+
constructor(options?: DuplexStreamFactoryOptions);
|
|
43
|
+
wrapReadable(readable: ReadableStream<R>): WrapReadableStream<R>;
|
|
44
|
+
createWritable(stream: WritableStream<W>): WritableStream<W>;
|
|
45
|
+
close(): Promise<void>;
|
|
46
|
+
dispose(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=duplex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duplex.d.ts","sourceRoot":"","sources":["../src/duplex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAA0E,MAAM,aAAa,CAAC;AAC1I,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAExD,MAAM,WAAW,0BAA0B;IACvC;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,EAAE,CAAC,MAAM,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;IAE3D;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC;CACtD;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB,CAAC,CAAC,EAAE,CAAC;IACjC,OAAO,CAAC,mBAAmB,CAA4C;IACvE,OAAO,CAAC,OAAO,CAAwC;IAEvD,OAAO,CAAC,eAAe,CAAS;IAChC,IAAW,cAAc,YAAmC;IAE5D,OAAO,CAAC,OAAO,CAA+B;IAC9C,IAAW,MAAM,kBAAmC;IAEpD,OAAO,CAAC,OAAO,CAA6B;gBAEzB,OAAO,CAAC,EAAE,0BAA0B;IAIhD,YAAY,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC;IAiBhE,cAAc,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAsBtD,KAAK;IAiBL,OAAO;CAUvB"}
|
package/esm/duplex.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { WritableStream } from "./stream.js";
|
|
3
|
+
import { WrapReadableStream } from "./wrap-readable.js";
|
|
4
|
+
/**
|
|
5
|
+
* A factory for creating a duplex stream.
|
|
6
|
+
*
|
|
7
|
+
* It can create multiple `ReadableStream`s and `WritableStream`s,
|
|
8
|
+
* when any of them is closed, all other streams will be closed as well.
|
|
9
|
+
*/
|
|
10
|
+
export class DuplexStreamFactory {
|
|
11
|
+
readableControllers = [];
|
|
12
|
+
writers = [];
|
|
13
|
+
_writableClosed = false;
|
|
14
|
+
get writableClosed() { return this._writableClosed; }
|
|
15
|
+
_closed = new PromiseResolver();
|
|
16
|
+
get closed() { return this._closed.promise; }
|
|
17
|
+
options;
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.options = options ?? {};
|
|
20
|
+
}
|
|
21
|
+
wrapReadable(readable) {
|
|
22
|
+
return new WrapReadableStream({
|
|
23
|
+
start: (controller) => {
|
|
24
|
+
this.readableControllers.push(controller);
|
|
25
|
+
return readable;
|
|
26
|
+
},
|
|
27
|
+
cancel: async () => {
|
|
28
|
+
// cancel means the local peer closes the connection first.
|
|
29
|
+
await this.close();
|
|
30
|
+
},
|
|
31
|
+
close: async () => {
|
|
32
|
+
// stream end means the remote peer closed the connection first.
|
|
33
|
+
await this.dispose();
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
createWritable(stream) {
|
|
38
|
+
const writer = stream.getWriter();
|
|
39
|
+
this.writers.push(writer);
|
|
40
|
+
// `WritableStream` has no way to tell if the remote peer has closed the connection.
|
|
41
|
+
// So it only triggers `close`.
|
|
42
|
+
return new WritableStream({
|
|
43
|
+
write: async (chunk) => {
|
|
44
|
+
await writer.ready;
|
|
45
|
+
await writer.write(chunk);
|
|
46
|
+
},
|
|
47
|
+
abort: async (reason) => {
|
|
48
|
+
await writer.abort(reason);
|
|
49
|
+
await this.close();
|
|
50
|
+
},
|
|
51
|
+
close: async () => {
|
|
52
|
+
try {
|
|
53
|
+
await writer.close();
|
|
54
|
+
}
|
|
55
|
+
catch { }
|
|
56
|
+
await this.close();
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async close() {
|
|
61
|
+
if (this._writableClosed) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
this._writableClosed = true;
|
|
65
|
+
// Call `close` first, so it can still write data to `WritableStream`s.
|
|
66
|
+
if (await this.options.close?.() !== false) {
|
|
67
|
+
// `close` can return `false` to disable automatic `dispose`.
|
|
68
|
+
await this.dispose();
|
|
69
|
+
}
|
|
70
|
+
for (const writer of this.writers) {
|
|
71
|
+
try {
|
|
72
|
+
await writer.close();
|
|
73
|
+
}
|
|
74
|
+
catch { }
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async dispose() {
|
|
78
|
+
this._writableClosed = true;
|
|
79
|
+
this._closed.resolve();
|
|
80
|
+
for (const controller of this.readableControllers) {
|
|
81
|
+
try {
|
|
82
|
+
controller.close();
|
|
83
|
+
}
|
|
84
|
+
catch { }
|
|
85
|
+
}
|
|
86
|
+
await this.options.dispose?.();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=duplex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"duplex.js","sourceRoot":"","sources":["../src/duplex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,cAAc,EAA+F,MAAM,aAAa,CAAC;AAC1I,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,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mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,qBAAa,kBAAmB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAE1D,OAAO,CAAC,OAAO,CAAM;IACrB,IAAW,MAAM,WAA2B;;CAS/C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WritableStream } from "./stream.js";
|
|
2
|
+
export class GatherStringStream extends WritableStream {
|
|
3
|
+
// PERF: rope (concat strings) is faster than `[].join('')`
|
|
4
|
+
_result = '';
|
|
5
|
+
get result() { return this._result; }
|
|
6
|
+
constructor() {
|
|
7
|
+
super({
|
|
8
|
+
write: (chunk) => {
|
|
9
|
+
this._result += chunk;
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=gather-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gather-string.js","sourceRoot":"","sources":["../src/gather-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,kBAAmB,SAAQ,cAAsB;IAC1D,2DAA2D;IACnD,OAAO,GAAG,EAAE,CAAC;IACrB,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5C;QACI,KAAK,CAAC;YACF,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;gBACb,IAAI,CAAC,OAAO,IAAI,KAAK,CAAC;YAC1B,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './buffered-transform.js';
|
|
2
|
+
export * from './buffered.js';
|
|
3
|
+
export * from './chunk.js';
|
|
4
|
+
export * from './decode-utf8.js';
|
|
5
|
+
export * from './duplex.js';
|
|
6
|
+
export * from './gather-string.js';
|
|
7
|
+
export * from './inspect.js';
|
|
8
|
+
export * from './pipe-from.js';
|
|
9
|
+
export * from './push-readable.js';
|
|
10
|
+
export * from './split-string.js';
|
|
11
|
+
export * from './stream.js';
|
|
12
|
+
export * from './struct-deserialize.js';
|
|
13
|
+
export * from './struct-serialize.js';
|
|
14
|
+
export * from './wrap-readable.js';
|
|
15
|
+
export * from './wrap-writable.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './buffered-transform.js';
|
|
2
|
+
export * from './buffered.js';
|
|
3
|
+
export * from './chunk.js';
|
|
4
|
+
export * from './decode-utf8.js';
|
|
5
|
+
export * from './duplex.js';
|
|
6
|
+
export * from './gather-string.js';
|
|
7
|
+
export * from './inspect.js';
|
|
8
|
+
export * from './pipe-from.js';
|
|
9
|
+
export * from './push-readable.js';
|
|
10
|
+
export * from './split-string.js';
|
|
11
|
+
export * from './stream.js';
|
|
12
|
+
export * from './struct-deserialize.js';
|
|
13
|
+
export * from './struct-serialize.js';
|
|
14
|
+
export * from './wrap-readable.js';
|
|
15
|
+
export * from './wrap-writable.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
|
package/esm/inspect.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../src/inspect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,qBAAa,aAAa,CAAC,CAAC,CAAE,SAAQ,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC;gBAC3C,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI;CAQ3C"}
|
package/esm/inspect.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TransformStream } from "./stream.js";
|
|
2
|
+
export class InspectStream extends TransformStream {
|
|
3
|
+
constructor(callback) {
|
|
4
|
+
super({
|
|
5
|
+
transform(chunk, controller) {
|
|
6
|
+
callback(chunk);
|
|
7
|
+
controller.enqueue(chunk);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=inspect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.js","sourceRoot":"","sources":["../src/inspect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,OAAO,aAAiB,SAAQ,eAAqB;IACvD,YAAY,QAA4B;QACpC,KAAK,CAAC;YACF,SAAS,CAAC,KAAK,EAAE,UAAU;gBACvB,QAAQ,CAAC,KAAK,CAAC,CAAC;gBAChB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;CACJ"}
|