create-web-stream 1.0.0 → 1.1.1
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/README.md +96 -10
- package/dist/index.cjs +190 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +71 -9
- package/dist/index.js +190 -22
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,16 +1,102 @@
|
|
|
1
1
|
Note: **I’m using a translation tool, so there may be some inappropriate expressions.**
|
|
2
2
|
|
|
3
|
-
#
|
|
4
|
-
This library provides functions for creating Web API `ReadableStream` and `WritableStream` instances from simple handlers, with support for BYOB readers, buffered writers, AbortSignal integration, and guaranteed cleanup callbacks.
|
|
3
|
+
# create-web-stream
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
- `createReadableStream`
|
|
8
|
-
- `createWriteableFileStream`
|
|
5
|
+
A library for creating Web API `ReadableStream<Uint8Array>` and `WritableStream<Uint8Array>` instances from simple handlers and options. Supports BYOB readers, buffered writers, `AbortSignal` integration, and guaranteed cleanup callbacks.
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
This project is licensed under either of
|
|
7
|
+
## Installation
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install create-web-stream
|
|
11
|
+
# or
|
|
12
|
+
pnpm add create-web-stream
|
|
13
|
+
# or
|
|
14
|
+
yarn add create-web-stream
|
|
15
|
+
```
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### createReadableStream
|
|
20
|
+
|
|
21
|
+
Creates a `ReadableStream` that yields byte data from the handler's `read` callback.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createReadableStream } from "create-web-stream"
|
|
25
|
+
|
|
26
|
+
const stream = createReadableStream(
|
|
27
|
+
// Handler
|
|
28
|
+
{
|
|
29
|
+
async read() {
|
|
30
|
+
// Return the next chunk. Return null, undefined, or empty Uint8Array to end the stream
|
|
31
|
+
return new Uint8Array([1, 2, 3])
|
|
32
|
+
},
|
|
33
|
+
async release(type, reason) {
|
|
34
|
+
// Clearnup
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
// Options
|
|
38
|
+
{ signal: myAbortSignal }
|
|
39
|
+
)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### createBYOBReadableStream
|
|
43
|
+
|
|
44
|
+
Creates a BYOB-style `ReadableStream` that reads directly into a buffer provided by the consumer.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { createBYOBReadableStream } from "create-web-stream"
|
|
48
|
+
|
|
49
|
+
const stream = createBYOBReadableStream(
|
|
50
|
+
// Handler
|
|
51
|
+
{
|
|
52
|
+
async read(buffer) {
|
|
53
|
+
// Write into buffer and return the number of bytes written. Return 0 to end the stream
|
|
54
|
+
buffer.set(new Uint8Array([1, 2, 3]), 0)
|
|
55
|
+
return 3
|
|
56
|
+
},
|
|
57
|
+
async release(type, reason) {
|
|
58
|
+
// Clearnup
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
// bufferSize for fallback
|
|
62
|
+
4096,
|
|
63
|
+
// Options
|
|
64
|
+
{ signal: myAbortSignal }
|
|
65
|
+
)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### createWritableStream
|
|
69
|
+
|
|
70
|
+
Creates a `WritableStream` that passes byte data to the handler's `write` callback.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import { createWritableStream } from "create-web-stream"
|
|
74
|
+
|
|
75
|
+
const stream = createWritableStream(
|
|
76
|
+
// Handler
|
|
77
|
+
{
|
|
78
|
+
async write(chunk) {
|
|
79
|
+
console.log("write: ", chunk.byteLength, "bytes")
|
|
80
|
+
},
|
|
81
|
+
async release(type, reason) {
|
|
82
|
+
// Clearnup
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
// Options
|
|
86
|
+
{
|
|
87
|
+
signal: myAbortSignal,
|
|
88
|
+
bufferSize: 0, // Unbuffered
|
|
89
|
+
strictBufferSize: false,
|
|
90
|
+
useBufferView: false,
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
This project is licensed under either of:
|
|
98
|
+
|
|
99
|
+
- MIT License
|
|
100
|
+
- Apache License (Version 2.0)
|
|
101
|
+
|
|
102
|
+
at your option.
|
package/dist/index.cjs
CHANGED
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a `ReadableStream` that yields byte data using the provided custom handler.
|
|
5
5
|
*
|
|
6
|
-
* This function does not throw errors.
|
|
7
6
|
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
8
7
|
* the caller must check and handle it manually.
|
|
9
|
-
* The resulting stream includes a BYOB (Bring Your Own Buffer) reader if supported by the runtime.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* The resulting stream can provide a BYOB reader if supported by the runtime.
|
|
10
|
+
* If unsupported, only a default reader is available.
|
|
11
|
+
*
|
|
12
|
+
* @param {CreateReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.
|
|
13
|
+
* @param {CreateReadableStreamOptions} options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.
|
|
14
|
+
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
|
|
14
15
|
*/
|
|
15
16
|
function createReadableStream(handler, options) {
|
|
17
|
+
const read = handler.read;
|
|
18
|
+
const release = handler.release;
|
|
16
19
|
let abortListener = null;
|
|
17
20
|
let buffer = null;
|
|
18
21
|
let cleanupPromise = null;
|
|
@@ -24,14 +27,17 @@ function createReadableStream(handler, options) {
|
|
|
24
27
|
options.signal.removeEventListener("abort", abortListener);
|
|
25
28
|
abortListener = null;
|
|
26
29
|
}
|
|
27
|
-
if (
|
|
28
|
-
await
|
|
30
|
+
if (release != null) {
|
|
31
|
+
await release(type, reason);
|
|
29
32
|
}
|
|
30
33
|
})();
|
|
31
34
|
}
|
|
32
35
|
return cleanupPromise;
|
|
33
36
|
}
|
|
34
|
-
|
|
37
|
+
const useByteStream = (options?.__internal_useByteStream__ !== undefined)
|
|
38
|
+
? options.__internal_useByteStream__
|
|
39
|
+
: isReadableByteStreamAvailable();
|
|
40
|
+
if (!useByteStream) {
|
|
35
41
|
return new ReadableStream({
|
|
36
42
|
start(controller) {
|
|
37
43
|
if (options?.signal != null) {
|
|
@@ -46,7 +52,7 @@ function createReadableStream(handler, options) {
|
|
|
46
52
|
async pull(controller) {
|
|
47
53
|
try {
|
|
48
54
|
throwIfAborted(options?.signal);
|
|
49
|
-
const data = await
|
|
55
|
+
const data = await read();
|
|
50
56
|
throwIfAborted(options?.signal);
|
|
51
57
|
if (data == null || data.byteLength === 0) {
|
|
52
58
|
await cleanup("Close");
|
|
@@ -85,7 +91,7 @@ function createReadableStream(handler, options) {
|
|
|
85
91
|
try {
|
|
86
92
|
throwIfAborted(options?.signal);
|
|
87
93
|
if (buffer == null || buffer.byteLength === 0) {
|
|
88
|
-
buffer = (await
|
|
94
|
+
buffer = (await read()) ?? null;
|
|
89
95
|
throwIfAborted(options?.signal);
|
|
90
96
|
}
|
|
91
97
|
if (buffer == null || buffer.byteLength === 0) {
|
|
@@ -130,19 +136,163 @@ function createReadableStream(handler, options) {
|
|
|
130
136
|
}
|
|
131
137
|
});
|
|
132
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Creates a `ReadableStream` that yields byte data using a BYOB-style handler.
|
|
141
|
+
*
|
|
142
|
+
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
143
|
+
* the caller must check and handle it manually.
|
|
144
|
+
*
|
|
145
|
+
* The resulting stream can provide a BYOB reader if supported by the runtime.
|
|
146
|
+
* If unsupported, only a default reader is available.
|
|
147
|
+
*
|
|
148
|
+
* @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.
|
|
149
|
+
* @param {number} defaultBufferSize The size of the fallback buffer passed to `handler.read`. Must be a positive safe integer. Used as `autoAllocateChunkSize` when a bytes-type reader is available. If unsupported, used as the size of the internal buffer for a default reader.
|
|
150
|
+
* @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.
|
|
151
|
+
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
|
|
152
|
+
*/
|
|
153
|
+
function createBYOBReadableStream(handler, defaultBufferSize, options) {
|
|
154
|
+
requiresNonzeroSafeInt(defaultBufferSize, "defaultBufferSize");
|
|
155
|
+
const read = handler.read;
|
|
156
|
+
const release = handler.release;
|
|
157
|
+
let abortListener = null;
|
|
158
|
+
let buffer = null;
|
|
159
|
+
let cleanupPromise = null;
|
|
160
|
+
function cleanup(type, reason) {
|
|
161
|
+
if (cleanupPromise === null) {
|
|
162
|
+
cleanupPromise = (async () => {
|
|
163
|
+
buffer = null;
|
|
164
|
+
if (options?.signal != null && abortListener != null) {
|
|
165
|
+
options.signal.removeEventListener("abort", abortListener);
|
|
166
|
+
abortListener = null;
|
|
167
|
+
}
|
|
168
|
+
if (release != null) {
|
|
169
|
+
await release(type, reason);
|
|
170
|
+
}
|
|
171
|
+
})();
|
|
172
|
+
}
|
|
173
|
+
return cleanupPromise;
|
|
174
|
+
}
|
|
175
|
+
const useByteStream = (options?.__internal_useByteStream__ !== undefined)
|
|
176
|
+
? options.__internal_useByteStream__
|
|
177
|
+
: isReadableByteStreamAvailable();
|
|
178
|
+
if (!useByteStream) {
|
|
179
|
+
return new ReadableStream({
|
|
180
|
+
start(controller) {
|
|
181
|
+
if (options?.signal != null) {
|
|
182
|
+
abortListener = () => {
|
|
183
|
+
const reason = options?.signal?.reason ?? newAbortSignalDefaultError();
|
|
184
|
+
cleanup("SignalAbort", reason).catch(() => { });
|
|
185
|
+
controller.error(reason);
|
|
186
|
+
};
|
|
187
|
+
options?.signal?.addEventListener("abort", abortListener);
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
async pull(controller) {
|
|
191
|
+
try {
|
|
192
|
+
throwIfAborted(options?.signal);
|
|
193
|
+
if (buffer === null) {
|
|
194
|
+
buffer = new Uint8Array(defaultBufferSize);
|
|
195
|
+
}
|
|
196
|
+
throwIfAborted(options?.signal);
|
|
197
|
+
const nread = await read(buffer);
|
|
198
|
+
throwIfAborted(options?.signal);
|
|
199
|
+
requiresSafeUint(nread, "nread");
|
|
200
|
+
if (nread === 0) {
|
|
201
|
+
await cleanup("Close");
|
|
202
|
+
controller.close();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
controller.enqueue(buffer.slice(0, nread));
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
const isSignalAbort = isThrownByAbortSignal(e, options?.signal);
|
|
209
|
+
await cleanup(isSignalAbort ? "SignalAbort" : "Error", e).catch(() => { });
|
|
210
|
+
throw e;
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
async cancel(reason) {
|
|
214
|
+
await cleanup("Cancel", reason);
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return new ReadableStream({
|
|
219
|
+
type: "bytes",
|
|
220
|
+
autoAllocateChunkSize: defaultBufferSize,
|
|
221
|
+
start(controller) {
|
|
222
|
+
if (options?.signal) {
|
|
223
|
+
abortListener = () => {
|
|
224
|
+
const reason = options?.signal?.reason ?? newAbortSignalDefaultError();
|
|
225
|
+
cleanup("SignalAbort", reason).catch(() => { });
|
|
226
|
+
controller.error(reason);
|
|
227
|
+
};
|
|
228
|
+
options?.signal.addEventListener("abort", abortListener);
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
async pull(controller) {
|
|
232
|
+
try {
|
|
233
|
+
throwIfAborted(options?.signal);
|
|
234
|
+
const byob = controller.byobRequest;
|
|
235
|
+
if (byob == null) {
|
|
236
|
+
if (buffer == null) {
|
|
237
|
+
buffer = new Uint8Array(defaultBufferSize);
|
|
238
|
+
}
|
|
239
|
+
throwIfAborted(options?.signal);
|
|
240
|
+
const nread = await read(buffer);
|
|
241
|
+
throwIfAborted(options?.signal);
|
|
242
|
+
requiresSafeUint(nread, "nread");
|
|
243
|
+
if (nread === 0) {
|
|
244
|
+
await cleanup("Close");
|
|
245
|
+
controller.close();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
controller.enqueue(buffer.slice(0, nread));
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const v = byob.view;
|
|
252
|
+
if (v == null)
|
|
253
|
+
return;
|
|
254
|
+
const view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
|
|
255
|
+
throwIfAborted(options?.signal);
|
|
256
|
+
const nread = await read(view);
|
|
257
|
+
throwIfAborted(options?.signal);
|
|
258
|
+
requiresSafeUint(nread, "nread");
|
|
259
|
+
if (nread === 0) {
|
|
260
|
+
await cleanup("Close");
|
|
261
|
+
// byobRequest がある場合、respond を呼ばないと promise が解決されない。
|
|
262
|
+
// controller.close() の後だと respond(0) を読んでもエラーにはならない。
|
|
263
|
+
// https://github.com/whatwg/streams/issues/1170
|
|
264
|
+
controller.close();
|
|
265
|
+
controller.byobRequest?.respond(0);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
byob.respond(nread);
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
const isSignalAbort = isThrownByAbortSignal(e, options?.signal);
|
|
272
|
+
await cleanup(isSignalAbort ? "SignalAbort" : "Error", e).catch(() => { });
|
|
273
|
+
throw e;
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
async cancel(reason) {
|
|
277
|
+
await cleanup("Cancel", reason);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
}
|
|
133
281
|
/**
|
|
134
282
|
* Creates a `WritableStream` that writes byte data using the provided custom handler.
|
|
135
283
|
*
|
|
136
|
-
* This function itself does not throw errors.
|
|
137
284
|
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
138
285
|
* the caller must check and handle it manually.
|
|
139
286
|
*
|
|
140
|
-
* @param handler
|
|
141
|
-
* @param options
|
|
142
|
-
* @returns A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
|
|
287
|
+
* @param {CreateWritableStreamHandler} handler The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.
|
|
288
|
+
* @param {CreateWritableStreamOptions} options Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.
|
|
289
|
+
* @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
|
|
143
290
|
*/
|
|
144
291
|
function createWritableStream(handler, options) {
|
|
145
|
-
const
|
|
292
|
+
const write = handler.write;
|
|
293
|
+
const release = handler.release;
|
|
294
|
+
const bufferSize = options?.bufferSize ?? 0;
|
|
295
|
+
requiresSafeUint(bufferSize, "bufferSize");
|
|
146
296
|
let abortListener = null;
|
|
147
297
|
let buffer = null;
|
|
148
298
|
let bufferOffset = 0;
|
|
@@ -155,8 +305,8 @@ function createWritableStream(handler, options) {
|
|
|
155
305
|
options?.signal?.removeEventListener("abort", abortListener);
|
|
156
306
|
abortListener = null;
|
|
157
307
|
}
|
|
158
|
-
if (
|
|
159
|
-
await
|
|
308
|
+
if (release != null) {
|
|
309
|
+
await release(type, reason);
|
|
160
310
|
}
|
|
161
311
|
})();
|
|
162
312
|
}
|
|
@@ -185,11 +335,11 @@ function createWritableStream(handler, options) {
|
|
|
185
335
|
? buffer.subarray(0, bufferOffset)
|
|
186
336
|
: buffer.slice(0, bufferOffset);
|
|
187
337
|
throwIfAborted(options?.signal);
|
|
188
|
-
await
|
|
338
|
+
await write(chunk);
|
|
189
339
|
bufferOffset = 0;
|
|
190
340
|
}
|
|
191
341
|
throwIfAborted(options?.signal);
|
|
192
|
-
await
|
|
342
|
+
await write(mapToArrayBuffer(src));
|
|
193
343
|
return;
|
|
194
344
|
}
|
|
195
345
|
let srcOffset = 0;
|
|
@@ -208,7 +358,7 @@ function createWritableStream(handler, options) {
|
|
|
208
358
|
if (options?.useBufferView !== true) {
|
|
209
359
|
buffer = null;
|
|
210
360
|
}
|
|
211
|
-
await
|
|
361
|
+
await write(chunk);
|
|
212
362
|
bufferOffset = 0;
|
|
213
363
|
}
|
|
214
364
|
}
|
|
@@ -224,7 +374,7 @@ function createWritableStream(handler, options) {
|
|
|
224
374
|
if (0 < bufferOffset && buffer != null) {
|
|
225
375
|
const view = buffer.subarray(0, bufferOffset);
|
|
226
376
|
buffer = null;
|
|
227
|
-
await
|
|
377
|
+
await write(view);
|
|
228
378
|
}
|
|
229
379
|
await cleanup("Close");
|
|
230
380
|
}
|
|
@@ -268,7 +418,26 @@ function mapToArrayBuffer(buffer) {
|
|
|
268
418
|
? buffer
|
|
269
419
|
: new Uint8Array(buffer);
|
|
270
420
|
}
|
|
421
|
+
function requiresSafeUint(num, numName) {
|
|
422
|
+
const name = numName ?? "value";
|
|
423
|
+
if (!Number.isSafeInteger(num)) {
|
|
424
|
+
throw new TypeError(`${name} must be a safe integer.`);
|
|
425
|
+
}
|
|
426
|
+
if (num < 0) {
|
|
427
|
+
throw new RangeError(`${name} must be a positive integer.`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function requiresNonzeroSafeInt(num, numName) {
|
|
431
|
+
const name = numName;
|
|
432
|
+
if (!Number.isSafeInteger(num)) {
|
|
433
|
+
throw new TypeError(`${name} must be a safe integer.`);
|
|
434
|
+
}
|
|
435
|
+
if (num <= 0) {
|
|
436
|
+
throw new RangeError(`${name} must be a non-zero positive integer.`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
271
439
|
|
|
440
|
+
exports.createBYOBReadableStream = createBYOBReadableStream;
|
|
272
441
|
exports.createReadableStream = createReadableStream;
|
|
273
442
|
exports.createWritableStream = createWritableStream;
|
|
274
443
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["export type CreateReadableStreamHandlerSource = Uint8Array<ArrayBuffer> | null | undefined\n\nexport type CreateReadableStreamHandlerReleaseType = \"Close\" | \"Cancel\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateReadableStreamHandler = {\n\n\t/**\n\t * A callback invoked when the stream's consumer requests more data.\n\t * \n\t * - **Yielding data**: Return a `Uint8Array` containing the next chunk of bytes.\n\t * - **Ending the stream**: Return `null`, `undefined`, or an empty `Uint8Array` (`byteLength === 0`) to signal that no more data is available. This will automatically close the stream.\n\t * - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t */\n\tread: () => PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource,\n\n\t/**\n\t * An optional callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream's reader is successfully read to the end. (type: `\"Close\"`)\n\t * - The stream or its reader is explicitly canceled. (type: `\"Cancel\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a read operation. (type: `\"Error\"`)\n\t */\n\trelease?: (type: CreateReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void,\n}\n\nexport type CreateReadableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal\n}\n\n/**\n * Creates a `ReadableStream` that yields byte data using the provided custom handler.\n * \n * This function does not throw errors. \n * If you need to throw an error early when the provided `options.signal` is already aborted,\n * the caller must check and handle it manually.\n * The resulting stream includes a BYOB (Bring Your Own Buffer) reader if supported by the runtime.\n * \n * @param handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.\n * @param options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.\n * @returns A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.\n */\nexport function createReadableStream(\n\thandler: CreateReadableStreamHandler,\n\toptions?: CreateReadableStreamOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\n\tlet abortListener: (() => void) | null = null\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null\n\n\tlet cleanupPromise: Promise<void> | null = null\n\tfunction cleanup(\n\t\ttype: CreateReadableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (handler.release != null) {\n\t\t\t\t\tawait handler.release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\tif (!isReadableByteStreamAvailable()) {\n\t\treturn new ReadableStream({\n\n\t\t\tstart(controller) {\n\t\t\t\tif (options?.signal != null) {\n\t\t\t\t\tabortListener = () => {\n\t\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t\t}\n\t\t\t\t\toptions?.signal?.addEventListener(\"abort\", abortListener);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst data = await handler.read()\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (data == null || data.byteLength === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(data)\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync cancel(reason) {\n\t\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t\t}\n\t\t})\n\t}\n\n\t// autoAllocateChunkSize を指定すると stream.getReader() でも byob が使われるようになるが、\n\t// この実装で byob を用いてもコピーが増えるだけで恩恵が少ないため指定しない。\n\t// また type: \"bytes\" で strategy を指定すると (正確には size を定義すると) エラーになる点にも注意。\n\treturn new ReadableStream({\n\t\ttype: \"bytes\",\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener)\n\t\t\t}\n\t\t},\n\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tbuffer = (await handler.read()) ?? null\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t}\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tawait cleanup(\"Close\")\n\n\t\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されない。\n\t\t\t\t\t// controller.close() の後だと respond(0) を読んでもエラーにはならない。\n\t\t\t\t\t// https://github.com/whatwg/streams/issues/1170\n\t\t\t\t\tcontroller.close()\n\t\t\t\t\tcontroller.byobRequest?.respond(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst byob = controller.byobRequest\n\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されないことに注意\n\t\t\t\tif (byob != null) {\n\t\t\t\t\t// respond する前なので null にならない\n\t\t\t\t\tconst v = byob.view!!\n\t\t\t\t\tconst view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength)\n\t\t\t\t\tconst nread = Math.min(buffer.byteLength, view.byteLength)\n\n\t\t\t\t\tview.set(buffer.subarray(0, nread))\n\t\t\t\t\tbuffer = buffer.subarray(nread)\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tbyob.respond(nread)\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tcontroller.enqueue(buffer)\n\t\t\t\t\tbuffer = null\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\n\t\t\t\t// byobRequest が存在する場合、controller.close() を呼んだだけでは\n\t\t\t\t// Promise は解決されず、respond() も呼ぶ必要がある。\n\t\t\t\t// controller.error() も同様の挙動になる可能性がある。(要検証)\n\t\t\t\t// 少なくとも throw すれば Promise は解決されるため、現状はこの実装とする。\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync cancel(reason) {\n\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t}\n\t})\n}\n\n\nexport type CreateWritableStreamHandlerReleaseType = \"Close\" | \"Abort\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateWritableStreamHandler = {\n\n\t/**\n\t * A callback invoked when a new chunk of byte data is ready to be written.\n\t * \n\t * - **Data Chunk**: Receives a `Uint8Array` containing the data. The exact size and memory reference of this chunk depend on the stream's `bufferSize` and `strictBufferSize` options.\n\t * - **Data Safety**: If `options.useBufferView` is `true`, the `chunk` might be a direct view (subarray) of the internal buffer. To prevent data corruption, do not retain references to this view outside this callback.\n\t * - **Handling Errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t */\n\twrite: (chunk: Uint8Array<ArrayBuffer>) => PromiseLike<void> | void,\n\n\t/**\n\t * A callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream or its writer is explicitly closed. (type: `\"Close\"`)\n\t * - The stream or its writer is explicitly aborted. (type: `\"Abort\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a write operation. (type: `\"Error\"`)\n\t */\n\trelease?: (\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t) => PromiseLike<void> | void,\n}\n\nexport type CreateWritableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * The size of the internal buffer in bytes.\n\t * \n\t * Defaults to `0` (unbuffered).\n\t */\n\tbufferSize?: number,\n\n\t/**\n\t * If `true`, the stream strictly enforces the `bufferSize` for every chunk passed to the handler.\n\t * Only the final `write` call may receive a chunk smaller than the `bufferSize`.\n\t * \n\t * If `false`, chunks larger than the `bufferSize` will bypass the internal buffer and be processed directly.\n\t * \n\t * Defaults to `false`.\n\t */\n\tstrictBufferSize?: boolean,\n\n\t/**\n\t * If `true`, the handler's `write` method can receive a chunk as a view (subarray) of the internal buffer.\n\t * This reduces the number of memory copies, but the received chunk must not be referenced outside the `write` method.\n\t * If you need to retain the chunk data externally, you must make a copy of it within the `write` method.\n\t * \n\t * Defaults to `false`.\n\t */\n\tuseBufferView?: boolean,\n}\n\n/**\n * Creates a `WritableStream` that writes byte data using the provided custom handler.\n * \n * This function itself does not throw errors.\n * If you need to throw an error early when the provided `options.signal` is already aborted, \n * the caller must check and handle it manually.\n * \n * @param handler - The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.\n * @param options - Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.\n * @returns A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.\n */\nexport function createWritableStream(\n\thandler: CreateWritableStreamHandler,\n\toptions?: CreateWritableStreamOptions,\n): WritableStream<Uint8Array<ArrayBufferLike>> {\n\n\tconst bufferSize = Math.max(0, Math.ceil(options?.bufferSize ?? 0))\n\n\tlet abortListener: (() => void) | null = null;\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null;\n\tlet bufferOffset = 0;\n\n\tlet cleanupPromise: Promise<void> | null = null;\n\tfunction cleanup(\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions?.signal?.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (handler.release != null) {\n\t\t\t\t\tawait handler.release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\treturn new WritableStream<Uint8Array<ArrayBufferLike>>({\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal != null) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener);\n\t\t\t}\n\t\t},\n\n\t\tasync write(src) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t// bufferSize が 0 以下の場合や src が buffer より大きい場合は buffer を使わずに処理する。\n\t\t\t\tif (\n\t\t\t\t\tbufferSize <= 0 ||\n\t\t\t\t\t(bufferSize <= src.byteLength && options?.strictBufferSize !== true)\n\t\t\t\t) {\n\n\t\t\t\t\t// buffer に既にデータがある場合、それを処理する。\n\t\t\t\t\tif (buffer !== null && 0 < bufferOffset) {\n\t\t\t\t\t\tconst chunk = options?.useBufferView === true\n\t\t\t\t\t\t\t? buffer.subarray(0, bufferOffset)\n\t\t\t\t\t\t\t: buffer.slice(0, bufferOffset)\n\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\t\tawait handler.write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tawait handler.write(mapToArrayBuffer(src))\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tlet srcOffset = 0;\n\t\t\t\twhile (srcOffset < src.byteLength) {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (buffer === null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(bufferSize)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst n = Math.min(bufferSize - bufferOffset, src.byteLength - srcOffset)\n\t\t\t\t\tbuffer.set(src.subarray(srcOffset, srcOffset + n), bufferOffset)\n\t\t\t\t\tbufferOffset += n\n\t\t\t\t\tsrcOffset += n\n\n\t\t\t\t\tif (bufferOffset === bufferSize) {\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\t\tconst chunk = buffer\n\t\t\t\t\t\tif (options?.useBufferView !== true) {\n\t\t\t\t\t\t\tbuffer = null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait handler.write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync close() {\n\t\t\ttry {\n\t\t\t\tif (0 < bufferOffset && buffer != null) {\n\t\t\t\t\tconst view = buffer.subarray(0, bufferOffset)\n\t\t\t\t\tbuffer = null\n\t\t\t\t\tawait handler.write(view)\n\t\t\t\t}\n\t\t\t\tawait cleanup(\"Close\")\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tawait cleanup(\"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync abort(reason) {\n\t\t\tawait cleanup(\"Abort\", reason)\n\t\t}\n\t})\n}\n\n\nlet _isReadableByteStreamAvailable: boolean | null = null\nfunction isReadableByteStreamAvailable() {\n\tif (_isReadableByteStreamAvailable === null) {\n\t\ttry {\n\t\t\tnew ReadableStream({ type: \"bytes\" })\n\t\t\t_isReadableByteStreamAvailable = true\n\t\t}\n\t\tcatch {\n\t\t\t_isReadableByteStreamAvailable = false\n\t\t}\n\t}\n\n\treturn _isReadableByteStreamAvailable\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined | null) {\n\tif (signal?.aborted === true) {\n\t\tthrow (signal?.reason ?? newAbortSignalDefaultError())\n\t}\n}\n\nfunction newAbortSignalDefaultError(): Error {\n\treturn new DOMException(\"The operation was aborted.\", \"AbortError\")\n}\n\nfunction isThrownByAbortSignal(err: unknown, signal: AbortSignal | null | undefined): boolean {\n\treturn (signal?.aborted === true) &&\n\t\t(err === signal.reason || (err instanceof DOMException && err.name === \"AbortError\"));\n}\n\nfunction mapToArrayBuffer(\n\tbuffer: Uint8Array<ArrayBufferLike>\n): Uint8Array<ArrayBuffer> {\n\n\treturn buffer.buffer instanceof ArrayBuffer\n\t\t? buffer as Uint8Array<ArrayBu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,KAAK,IAAI;AAC/B,SAAC,GAAG,KAAK,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;AACvF;AAEA,SAAS,gBAAgB,CACxB,MAAmC,EAAA;AAGnC,IAAA,OAAO,MAAM,CAAC,MAAM,YAAY;AAC/B,UAAE;AACF,UAAE,IAAI,UAAU,CAAC,MAAM,CAAC;AAC1B;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["export type CreateReadableStreamHandlerSource = Uint8Array<ArrayBuffer> | null | undefined\n\nexport type CreateReadableStreamHandlerReleaseType = \"Close\" | \"Cancel\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateReadableStreamHandler = {\n\n\t/**\n\t * A callback invoked when the stream's consumer requests more data.\n\t * \n\t * - **Yielding data**: Return a `Uint8Array` containing the next chunk of bytes.\n\t * - **Ending the stream**: Return `null`, `undefined`, or an empty `Uint8Array` (`byteLength === 0`) to signal that no more data is available. This will automatically close the stream.\n\t * - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t * \n\t * @returns {PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource} The next chunk of bytes.\n\t */\n\tread: () => PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource,\n\n\t/**\n\t * An optional callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream's reader is successfully read to the end. (type: `\"Close\"`)\n\t * - The stream or its reader is explicitly canceled. (type: `\"Cancel\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a read operation. (type: `\"Error\"`)\n\t * \n\t * @param {CreateReadableStreamHandlerReleaseType} type The type of the release operation.\n\t * @param {unknown} reason The reason for the release operation.\n\t */\n\trelease?: (type: CreateReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void,\n}\n\nexport type CreateReadableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * @internal\n\t * @ignore\n\t */\n\t__internal_useByteStream__?: boolean\n}\n\n/**\n * Creates a `ReadableStream` that yields byte data using the provided custom handler.\n * \n * If you need to throw an error early when the provided `options.signal` is already aborted,\n * the caller must check and handle it manually.\n * \n * The resulting stream can provide a BYOB reader if supported by the runtime.\n * If unsupported, only a default reader is available.\n * \n * @param {CreateReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.\n * @param {CreateReadableStreamOptions} options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.\n * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.\n */\nexport function createReadableStream(\n\thandler: CreateReadableStreamHandler,\n\toptions?: CreateReadableStreamOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\n\tconst read = handler.read\n\tconst release = handler.release\n\n\tlet abortListener: (() => void) | null = null\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null\n\n\tlet cleanupPromise: Promise<void> | null = null\n\tfunction cleanup(\n\t\ttype: CreateReadableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (release != null) {\n\t\t\t\t\tawait release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\tconst useByteStream = (options?.__internal_useByteStream__ !== undefined)\n\t\t? options.__internal_useByteStream__\n\t\t: isReadableByteStreamAvailable()\n\n\tif (!useByteStream) {\n\t\treturn new ReadableStream({\n\n\t\t\tstart(controller) {\n\t\t\t\tif (options?.signal != null) {\n\t\t\t\t\tabortListener = () => {\n\t\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t\t}\n\t\t\t\t\toptions?.signal?.addEventListener(\"abort\", abortListener);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst data = await read()\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (data == null || data.byteLength === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(data)\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync cancel(reason) {\n\t\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t\t}\n\t\t})\n\t}\n\n\t// autoAllocateChunkSize を指定すると stream.getReader() でも byob が使われるようになるが、\n\t// この実装で byob を用いてもコピーが増えるだけで恩恵が少ないため指定しない。\n\t// また type: \"bytes\" で strategy を指定すると (正確には size を定義すると) エラーになる点にも注意。\n\treturn new ReadableStream({\n\t\ttype: \"bytes\",\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener)\n\t\t\t}\n\t\t},\n\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tbuffer = (await read()) ?? null\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t}\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tawait cleanup(\"Close\")\n\n\t\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されない。\n\t\t\t\t\t// controller.close() の後だと respond(0) を読んでもエラーにはならない。\n\t\t\t\t\t// https://github.com/whatwg/streams/issues/1170\n\t\t\t\t\tcontroller.close()\n\t\t\t\t\tcontroller.byobRequest?.respond(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst byob = controller.byobRequest\n\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されないことに注意\n\t\t\t\tif (byob != null) {\n\t\t\t\t\t// respond する前なので null にならない\n\t\t\t\t\tconst v = byob.view!!\n\t\t\t\t\tconst view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength)\n\t\t\t\t\tconst nread = Math.min(buffer.byteLength, view.byteLength)\n\n\t\t\t\t\tview.set(buffer.subarray(0, nread))\n\t\t\t\t\tbuffer = buffer.subarray(nread)\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tbyob.respond(nread)\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tcontroller.enqueue(buffer)\n\t\t\t\t\tbuffer = null\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\n\t\t\t\t// byobRequest が存在する場合、controller.close() を呼んだだけでは\n\t\t\t\t// Promise は解決されず、respond() も呼ぶ必要がある。\n\t\t\t\t// controller.error() も同様の挙動になる可能性がある。(要検証)\n\t\t\t\t// 少なくとも throw すれば Promise は解決されるため、現状はこの実装とする。\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync cancel(reason) {\n\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t}\n\t})\n}\n\n\nexport type CreateBYOBReadableStreamHandlerReleaseType = \"Close\" | \"Cancel\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateBYOBReadableStreamHandler = {\n\n\t/**\n\t * A callback invoked when the stream's consumer requests more data.\n\t *\n\t * - **Yielding data**: Write bytes into the provided `buffer` and return the number of bytes written (1 or greater). The returned value must not exceed `buffer.byteLength`.\n\t * - **Ending the stream**: Return `0` to signal that no more data is available. This will automatically close the stream.\n\t * - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t * \n\t * @param {Uint8Array<ArrayBuffer>} buffer The buffer to write the data into.\n\t * @returns {PromiseLike<number> | number} The number of bytes written.\n\t */\n\tread: (buffer: Uint8Array<ArrayBuffer>) => PromiseLike<number> | number\n\n\t/**\n\t * An optional callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream's reader is successfully read to the end. (type: `\"Close\"`)\n\t * - The stream or its reader is explicitly canceled. (type: `\"Cancel\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a read operation. (type: `\"Error\"`)\n\t * \n\t * @param {CreateBYOBReadableStreamHandlerReleaseType} type The type of the release operation.\n\t * @param {unknown} reason The reason for the release operation.\n\t */\n\trelease?: (type: CreateBYOBReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void,\n}\n\nexport type CreateBYOBReadableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * @internal\n\t * @ignore\n\t */\n\t__internal_useByteStream__?: boolean\n}\n\n/**\n * Creates a `ReadableStream` that yields byte data using a BYOB-style handler.\n *\n * If you need to throw an error early when the provided `options.signal` is already aborted,\n * the caller must check and handle it manually.\n * \n * The resulting stream can provide a BYOB reader if supported by the runtime.\n * If unsupported, only a default reader is available.\n *\n * @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.\n * @param {number} defaultBufferSize The size of the fallback buffer passed to `handler.read`. Must be a positive safe integer. Used as `autoAllocateChunkSize` when a bytes-type reader is available. If unsupported, used as the size of the internal buffer for a default reader.\n * @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.\n * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.\n */\nexport function createBYOBReadableStream(\n\thandler: CreateBYOBReadableStreamHandler,\n\tdefaultBufferSize: number,\n\toptions?: CreateBYOBReadableStreamOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\n\trequiresNonzeroSafeInt(defaultBufferSize, \"defaultBufferSize\")\n\tconst read = handler.read\n\tconst release = handler.release\n\n\tlet abortListener: (() => void) | null = null\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null\n\n\tlet cleanupPromise: Promise<void> | null = null\n\tfunction cleanup(\n\t\ttype: CreateBYOBReadableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (release != null) {\n\t\t\t\t\tawait release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\tconst useByteStream = (options?.__internal_useByteStream__ !== undefined)\n\t\t? options.__internal_useByteStream__\n\t\t: isReadableByteStreamAvailable()\n\n\tif (!useByteStream) {\n\t\treturn new ReadableStream({\n\n\t\t\tstart(controller) {\n\t\t\t\tif (options?.signal != null) {\n\t\t\t\t\tabortListener = () => {\n\t\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t\t}\n\t\t\t\t\toptions?.signal?.addEventListener(\"abort\", abortListener);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (buffer === null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(defaultBufferSize)\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst nread = await read(buffer)\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\trequiresSafeUint(nread, \"nread\")\n\t\t\t\t\tif (nread === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(buffer.slice(0, nread))\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync cancel(reason) {\n\t\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn new ReadableStream({\n\t\ttype: \"bytes\",\n\t\tautoAllocateChunkSize: defaultBufferSize,\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener)\n\t\t\t}\n\t\t},\n\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tconst byob = controller.byobRequest\n\t\t\t\tif (byob == null) {\n\t\t\t\t\tif (buffer == null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(defaultBufferSize)\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst nread = await read(buffer)\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\trequiresSafeUint(nread, \"nread\")\n\t\t\t\t\tif (nread === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(buffer.slice(0, nread))\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst v = byob.view\n\t\t\t\tif (v == null) return\n\t\t\t\tconst view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength)\n\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tconst nread = await read(view)\n\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\trequiresSafeUint(nread, \"nread\")\n\t\t\t\tif (nread === 0) {\n\t\t\t\t\tawait cleanup(\"Close\")\n\n\t\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されない。\n\t\t\t\t\t// controller.close() の後だと respond(0) を読んでもエラーにはならない。\n\t\t\t\t\t// https://github.com/whatwg/streams/issues/1170\n\t\t\t\t\tcontroller.close()\n\t\t\t\t\tcontroller.byobRequest?.respond(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tbyob.respond(nread)\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync cancel(reason) {\n\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t}\n\t})\n}\n\n\nexport type CreateWritableStreamHandlerReleaseType = \"Close\" | \"Abort\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateWritableStreamHandler = {\n\n\t/**\n\t * A callback invoked when a new chunk of byte data is ready to be written.\n\t * \n\t * - **Data Chunk**: Receives a `Uint8Array` containing the data. The exact size and memory reference of this chunk depend on the stream's `bufferSize` and `strictBufferSize` options.\n\t * - **Data Safety**: If `options.useBufferView` is `true`, the `chunk` might be a direct view (subarray) of the internal buffer. To prevent data corruption, do not retain references to this view outside this callback.\n\t * - **Handling Errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t * \n\t * @param {Uint8Array<ArrayBuffer>} chunk The chunk of byte data to write.\n\t */\n\twrite: (chunk: Uint8Array<ArrayBuffer>) => PromiseLike<void> | void,\n\n\t/**\n\t * A callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream or its writer is explicitly closed. (type: `\"Close\"`)\n\t * - The stream or its writer is explicitly aborted. (type: `\"Abort\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a write operation. (type: `\"Error\"`)\n\t * \n\t * @param {CreateWritableStreamHandlerReleaseType} type The type of the release operation.\n\t * @param {unknown} reason The reason for the release operation.\n\t */\n\trelease?: (\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t) => PromiseLike<void> | void,\n}\n\nexport type CreateWritableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * The size of the internal buffer in bytes. \n\t * Must be a zero or positive safe integer. \n\t * \n\t * Defaults to `0` (unbuffered).\n\t */\n\tbufferSize?: number,\n\n\t/**\n\t * If `true`, the stream strictly enforces the `bufferSize` for every chunk passed to the handler.\n\t * Only the final `write` call may receive a chunk smaller than the `bufferSize`.\n\t * \n\t * If `false`, chunks larger than the `bufferSize` will bypass the internal buffer and be processed directly.\n\t * \n\t * Defaults to `false`.\n\t */\n\tstrictBufferSize?: boolean,\n\n\t/**\n\t * If `true`, the handler's `write` method can receive a chunk as a view (subarray) of the internal buffer.\n\t * This reduces the number of memory copies, but the received chunk must not be referenced outside the `write` method.\n\t * If you need to retain the chunk data externally, you must make a copy of it within the `write` method.\n\t * \n\t * Defaults to `false`.\n\t */\n\tuseBufferView?: boolean,\n}\n\n/**\n * Creates a `WritableStream` that writes byte data using the provided custom handler.\n * \n * If you need to throw an error early when the provided `options.signal` is already aborted, \n * the caller must check and handle it manually.\n * \n * @param {CreateWritableStreamHandler} handler The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.\n * @param {CreateWritableStreamOptions} options Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.\n * @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.\n */\nexport function createWritableStream(\n\thandler: CreateWritableStreamHandler,\n\toptions?: CreateWritableStreamOptions,\n): WritableStream<Uint8Array<ArrayBufferLike>> {\n\n\tconst write = handler.write\n\tconst release = handler.release\n\tconst bufferSize = options?.bufferSize ?? 0\n\trequiresSafeUint(bufferSize, \"bufferSize\")\n\n\tlet abortListener: (() => void) | null = null;\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null;\n\tlet bufferOffset = 0;\n\n\tlet cleanupPromise: Promise<void> | null = null;\n\tfunction cleanup(\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions?.signal?.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (release != null) {\n\t\t\t\t\tawait release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\treturn new WritableStream<Uint8Array<ArrayBufferLike>>({\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal != null) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener);\n\t\t\t}\n\t\t},\n\n\t\tasync write(src) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t// bufferSize が 0 以下の場合や src が buffer より大きい場合は buffer を使わずに処理する。\n\t\t\t\tif (\n\t\t\t\t\tbufferSize <= 0 ||\n\t\t\t\t\t(bufferSize <= src.byteLength && options?.strictBufferSize !== true)\n\t\t\t\t) {\n\n\t\t\t\t\t// buffer に既にデータがある場合、それを処理する。\n\t\t\t\t\tif (buffer !== null && 0 < bufferOffset) {\n\t\t\t\t\t\tconst chunk = options?.useBufferView === true\n\t\t\t\t\t\t\t? buffer.subarray(0, bufferOffset)\n\t\t\t\t\t\t\t: buffer.slice(0, bufferOffset)\n\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\t\tawait write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tawait write(mapToArrayBuffer(src))\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tlet srcOffset = 0;\n\t\t\t\twhile (srcOffset < src.byteLength) {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (buffer === null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(bufferSize)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst n = Math.min(bufferSize - bufferOffset, src.byteLength - srcOffset)\n\t\t\t\t\tbuffer.set(src.subarray(srcOffset, srcOffset + n), bufferOffset)\n\t\t\t\t\tbufferOffset += n\n\t\t\t\t\tsrcOffset += n\n\n\t\t\t\t\tif (bufferOffset === bufferSize) {\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\t\tconst chunk = buffer\n\t\t\t\t\t\tif (options?.useBufferView !== true) {\n\t\t\t\t\t\t\tbuffer = null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync close() {\n\t\t\ttry {\n\t\t\t\tif (0 < bufferOffset && buffer != null) {\n\t\t\t\t\tconst view = buffer.subarray(0, bufferOffset)\n\t\t\t\t\tbuffer = null\n\t\t\t\t\tawait write(view)\n\t\t\t\t}\n\t\t\t\tawait cleanup(\"Close\")\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tawait cleanup(\"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync abort(reason) {\n\t\t\tawait cleanup(\"Abort\", reason)\n\t\t}\n\t})\n}\n\n\nlet _isReadableByteStreamAvailable: boolean | null = null\nfunction isReadableByteStreamAvailable(): boolean {\n\tif (_isReadableByteStreamAvailable === null) {\n\t\ttry {\n\t\t\tnew ReadableStream({ type: \"bytes\" })\n\t\t\t_isReadableByteStreamAvailable = true\n\t\t}\n\t\tcatch {\n\t\t\t_isReadableByteStreamAvailable = false\n\t\t}\n\t}\n\treturn _isReadableByteStreamAvailable\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined | null) {\n\tif (signal?.aborted === true) {\n\t\tthrow (signal?.reason ?? newAbortSignalDefaultError())\n\t}\n}\n\nfunction newAbortSignalDefaultError(): Error {\n\treturn new DOMException(\"The operation was aborted.\", \"AbortError\")\n}\n\nfunction isThrownByAbortSignal(err: unknown, signal: AbortSignal | null | undefined): boolean {\n\treturn (signal?.aborted === true) &&\n\t\t(err === signal.reason || (err instanceof DOMException && err.name === \"AbortError\"));\n}\n\nfunction mapToArrayBuffer(\n\tbuffer: Uint8Array<ArrayBufferLike>\n): Uint8Array<ArrayBuffer> {\n\n\treturn buffer.buffer instanceof ArrayBuffer\n\t\t? buffer as Uint8Array<ArrayBuffer>\n\t\t: new Uint8Array(buffer)\n}\n\nfunction requiresSafeUint(num: number, numName?: string): void {\n\tconst name = numName ?? \"value\";\n\n\tif (!Number.isSafeInteger(num)) {\n\t\tthrow new TypeError(`${name} must be a safe integer.`);\n\t}\n\tif (num < 0) {\n\t\tthrow new RangeError(`${name} must be a positive integer.`);\n\t}\n}\n\nfunction requiresNonzeroSafeInt(num: number, numName?: string): void {\n\tconst name = numName ?? \"value\";\n\n\tif (!Number.isSafeInteger(num)) {\n\t\tthrow new TypeError(`${name} must be a safe integer.`);\n\t}\n\tif (num <= 0) {\n\t\tthrow new RangeError(`${name} must be a non-zero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AAE,OAAO,KAAK,IAAI;AAC/B,SAAC,GAAG,KAAK,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;AACvF;AAEA,SAAS,gBAAgB,CACxB,MAAmC,EAAA;AAGnC,IAAA,OAAO,MAAM,CAAC,MAAM,YAAY;AAC/B,UAAE;AACF,UAAE,IAAI,UAAU,CAAC,MAAM,CAAC;AAC1B;AAEA,SAAS,gBAAgB,CAAC,GAAW,EAAE,OAAgB,EAAA;AACtD,IAAA,MAAM,IAAI,GAAG,OAAO,IAAI,OAAO;IAE/B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE;AAC/B,QAAA,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,CAAA,wBAAA,CAA0B,CAAC;IACvD;AACA,IAAA,IAAI,GAAG,GAAG,CAAC,EAAE;AACZ,QAAA,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,CAAA,4BAAA,CAA8B,CAAC;IAC5D;AACD;AAEA,SAAS,sBAAsB,CAAC,GAAW,EAAE,OAAgB,EAAA;AAC5D,IAAA,MAAM,IAAI,GAAG,OAAkB;IAE/B,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE;AAC/B,QAAA,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,CAAA,wBAAA,CAA0B,CAAC;IACvD;AACA,IAAA,IAAI,GAAG,IAAI,CAAC,EAAE;AACb,QAAA,MAAM,IAAI,UAAU,CAAC,GAAG,IAAI,CAAA,qCAAA,CAAuC,CAAC;IACrE;AACD;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export type CreateReadableStreamHandler = {
|
|
|
7
7
|
* - **Yielding data**: Return a `Uint8Array` containing the next chunk of bytes.
|
|
8
8
|
* - **Ending the stream**: Return `null`, `undefined`, or an empty `Uint8Array` (`byteLength === 0`) to signal that no more data is available. This will automatically close the stream.
|
|
9
9
|
* - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.
|
|
10
|
+
*
|
|
11
|
+
* @returns {PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource} The next chunk of bytes.
|
|
10
12
|
*/
|
|
11
13
|
read: () => PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource;
|
|
12
14
|
/**
|
|
@@ -18,6 +20,9 @@ export type CreateReadableStreamHandler = {
|
|
|
18
20
|
* - The stream or its reader is explicitly canceled. (type: `"Cancel"`)
|
|
19
21
|
* - The provided `AbortSignal` fires an `abort` event. (type: `"SignalAbort"`)
|
|
20
22
|
* - An error occurs during a read operation. (type: `"Error"`)
|
|
23
|
+
*
|
|
24
|
+
* @param {CreateReadableStreamHandlerReleaseType} type The type of the release operation.
|
|
25
|
+
* @param {unknown} reason The reason for the release operation.
|
|
21
26
|
*/
|
|
22
27
|
release?: (type: CreateReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void;
|
|
23
28
|
};
|
|
@@ -32,16 +37,68 @@ export type CreateReadableStreamOptions = {
|
|
|
32
37
|
/**
|
|
33
38
|
* Creates a `ReadableStream` that yields byte data using the provided custom handler.
|
|
34
39
|
*
|
|
35
|
-
* This function does not throw errors.
|
|
36
40
|
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
37
41
|
* the caller must check and handle it manually.
|
|
38
|
-
* The resulting stream includes a BYOB (Bring Your Own Buffer) reader if supported by the runtime.
|
|
39
42
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
+
* The resulting stream can provide a BYOB reader if supported by the runtime.
|
|
44
|
+
* If unsupported, only a default reader is available.
|
|
45
|
+
*
|
|
46
|
+
* @param {CreateReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.
|
|
47
|
+
* @param {CreateReadableStreamOptions} options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.
|
|
48
|
+
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
|
|
43
49
|
*/
|
|
44
50
|
export declare function createReadableStream(handler: CreateReadableStreamHandler, options?: CreateReadableStreamOptions): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
51
|
+
export type CreateBYOBReadableStreamHandlerReleaseType = "Close" | "Cancel" | "SignalAbort" | "Error";
|
|
52
|
+
export type CreateBYOBReadableStreamHandler = {
|
|
53
|
+
/**
|
|
54
|
+
* A callback invoked when the stream's consumer requests more data.
|
|
55
|
+
*
|
|
56
|
+
* - **Yielding data**: Write bytes into the provided `buffer` and return the number of bytes written (1 or greater). The returned value must not exceed `buffer.byteLength`.
|
|
57
|
+
* - **Ending the stream**: Return `0` to signal that no more data is available. This will automatically close the stream.
|
|
58
|
+
* - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.
|
|
59
|
+
*
|
|
60
|
+
* @param {Uint8Array<ArrayBuffer>} buffer The buffer to write the data into.
|
|
61
|
+
* @returns {PromiseLike<number> | number} The number of bytes written.
|
|
62
|
+
*/
|
|
63
|
+
read: (buffer: Uint8Array<ArrayBuffer>) => PromiseLike<number> | number;
|
|
64
|
+
/**
|
|
65
|
+
* An optional callback for performing cleanup operations.
|
|
66
|
+
*
|
|
67
|
+
* This function is guaranteed to be invoked at most once.
|
|
68
|
+
* It is automatically triggered when the stream terminates under any of the following conditions:
|
|
69
|
+
* - The stream's reader is successfully read to the end. (type: `"Close"`)
|
|
70
|
+
* - The stream or its reader is explicitly canceled. (type: `"Cancel"`)
|
|
71
|
+
* - The provided `AbortSignal` fires an `abort` event. (type: `"SignalAbort"`)
|
|
72
|
+
* - An error occurs during a read operation. (type: `"Error"`)
|
|
73
|
+
*
|
|
74
|
+
* @param {CreateBYOBReadableStreamHandlerReleaseType} type The type of the release operation.
|
|
75
|
+
* @param {unknown} reason The reason for the release operation.
|
|
76
|
+
*/
|
|
77
|
+
release?: (type: CreateBYOBReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void;
|
|
78
|
+
};
|
|
79
|
+
export type CreateBYOBReadableStreamOptions = {
|
|
80
|
+
/**
|
|
81
|
+
* An `AbortSignal` to abort the stream.
|
|
82
|
+
*
|
|
83
|
+
* When the abort event is fired, the handler's `release` function will be called.
|
|
84
|
+
*/
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Creates a `ReadableStream` that yields byte data using a BYOB-style handler.
|
|
89
|
+
*
|
|
90
|
+
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
91
|
+
* the caller must check and handle it manually.
|
|
92
|
+
*
|
|
93
|
+
* The resulting stream can provide a BYOB reader if supported by the runtime.
|
|
94
|
+
* If unsupported, only a default reader is available.
|
|
95
|
+
*
|
|
96
|
+
* @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.
|
|
97
|
+
* @param {number} defaultBufferSize The size of the fallback buffer passed to `handler.read`. Must be a positive safe integer. Used as `autoAllocateChunkSize` when a bytes-type reader is available. If unsupported, used as the size of the internal buffer for a default reader.
|
|
98
|
+
* @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.
|
|
99
|
+
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createBYOBReadableStream(handler: CreateBYOBReadableStreamHandler, defaultBufferSize: number, options?: CreateBYOBReadableStreamOptions): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
45
102
|
export type CreateWritableStreamHandlerReleaseType = "Close" | "Abort" | "SignalAbort" | "Error";
|
|
46
103
|
export type CreateWritableStreamHandler = {
|
|
47
104
|
/**
|
|
@@ -50,6 +107,8 @@ export type CreateWritableStreamHandler = {
|
|
|
50
107
|
* - **Data Chunk**: Receives a `Uint8Array` containing the data. The exact size and memory reference of this chunk depend on the stream's `bufferSize` and `strictBufferSize` options.
|
|
51
108
|
* - **Data Safety**: If `options.useBufferView` is `true`, the `chunk` might be a direct view (subarray) of the internal buffer. To prevent data corruption, do not retain references to this view outside this callback.
|
|
52
109
|
* - **Handling Errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.
|
|
110
|
+
*
|
|
111
|
+
* @param {Uint8Array<ArrayBuffer>} chunk The chunk of byte data to write.
|
|
53
112
|
*/
|
|
54
113
|
write: (chunk: Uint8Array<ArrayBuffer>) => PromiseLike<void> | void;
|
|
55
114
|
/**
|
|
@@ -61,6 +120,9 @@ export type CreateWritableStreamHandler = {
|
|
|
61
120
|
* - The stream or its writer is explicitly aborted. (type: `"Abort"`)
|
|
62
121
|
* - The provided `AbortSignal` fires an `abort` event. (type: `"SignalAbort"`)
|
|
63
122
|
* - An error occurs during a write operation. (type: `"Error"`)
|
|
123
|
+
*
|
|
124
|
+
* @param {CreateWritableStreamHandlerReleaseType} type The type of the release operation.
|
|
125
|
+
* @param {unknown} reason The reason for the release operation.
|
|
64
126
|
*/
|
|
65
127
|
release?: (type: CreateWritableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void;
|
|
66
128
|
};
|
|
@@ -73,6 +135,7 @@ export type CreateWritableStreamOptions = {
|
|
|
73
135
|
signal?: AbortSignal;
|
|
74
136
|
/**
|
|
75
137
|
* The size of the internal buffer in bytes.
|
|
138
|
+
* Must be a zero or positive safe integer.
|
|
76
139
|
*
|
|
77
140
|
* Defaults to `0` (unbuffered).
|
|
78
141
|
*/
|
|
@@ -98,12 +161,11 @@ export type CreateWritableStreamOptions = {
|
|
|
98
161
|
/**
|
|
99
162
|
* Creates a `WritableStream` that writes byte data using the provided custom handler.
|
|
100
163
|
*
|
|
101
|
-
* This function itself does not throw errors.
|
|
102
164
|
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
103
165
|
* the caller must check and handle it manually.
|
|
104
166
|
*
|
|
105
|
-
* @param handler
|
|
106
|
-
* @param options
|
|
107
|
-
* @returns A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
|
|
167
|
+
* @param {CreateWritableStreamHandler} handler The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.
|
|
168
|
+
* @param {CreateWritableStreamOptions} options Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.
|
|
169
|
+
* @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
|
|
108
170
|
*/
|
|
109
171
|
export declare function createWritableStream(handler: CreateWritableStreamHandler, options?: CreateWritableStreamOptions): WritableStream<Uint8Array<ArrayBufferLike>>;
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a `ReadableStream` that yields byte data using the provided custom handler.
|
|
3
3
|
*
|
|
4
|
-
* This function does not throw errors.
|
|
5
4
|
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
6
5
|
* the caller must check and handle it manually.
|
|
7
|
-
* The resulting stream includes a BYOB (Bring Your Own Buffer) reader if supported by the runtime.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* The resulting stream can provide a BYOB reader if supported by the runtime.
|
|
8
|
+
* If unsupported, only a default reader is available.
|
|
9
|
+
*
|
|
10
|
+
* @param {CreateReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.
|
|
11
|
+
* @param {CreateReadableStreamOptions} options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.
|
|
12
|
+
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
|
|
12
13
|
*/
|
|
13
14
|
function createReadableStream(handler, options) {
|
|
15
|
+
const read = handler.read;
|
|
16
|
+
const release = handler.release;
|
|
14
17
|
let abortListener = null;
|
|
15
18
|
let buffer = null;
|
|
16
19
|
let cleanupPromise = null;
|
|
@@ -22,14 +25,17 @@ function createReadableStream(handler, options) {
|
|
|
22
25
|
options.signal.removeEventListener("abort", abortListener);
|
|
23
26
|
abortListener = null;
|
|
24
27
|
}
|
|
25
|
-
if (
|
|
26
|
-
await
|
|
28
|
+
if (release != null) {
|
|
29
|
+
await release(type, reason);
|
|
27
30
|
}
|
|
28
31
|
})();
|
|
29
32
|
}
|
|
30
33
|
return cleanupPromise;
|
|
31
34
|
}
|
|
32
|
-
|
|
35
|
+
const useByteStream = (options?.__internal_useByteStream__ !== undefined)
|
|
36
|
+
? options.__internal_useByteStream__
|
|
37
|
+
: isReadableByteStreamAvailable();
|
|
38
|
+
if (!useByteStream) {
|
|
33
39
|
return new ReadableStream({
|
|
34
40
|
start(controller) {
|
|
35
41
|
if (options?.signal != null) {
|
|
@@ -44,7 +50,7 @@ function createReadableStream(handler, options) {
|
|
|
44
50
|
async pull(controller) {
|
|
45
51
|
try {
|
|
46
52
|
throwIfAborted(options?.signal);
|
|
47
|
-
const data = await
|
|
53
|
+
const data = await read();
|
|
48
54
|
throwIfAborted(options?.signal);
|
|
49
55
|
if (data == null || data.byteLength === 0) {
|
|
50
56
|
await cleanup("Close");
|
|
@@ -83,7 +89,7 @@ function createReadableStream(handler, options) {
|
|
|
83
89
|
try {
|
|
84
90
|
throwIfAborted(options?.signal);
|
|
85
91
|
if (buffer == null || buffer.byteLength === 0) {
|
|
86
|
-
buffer = (await
|
|
92
|
+
buffer = (await read()) ?? null;
|
|
87
93
|
throwIfAborted(options?.signal);
|
|
88
94
|
}
|
|
89
95
|
if (buffer == null || buffer.byteLength === 0) {
|
|
@@ -128,19 +134,163 @@ function createReadableStream(handler, options) {
|
|
|
128
134
|
}
|
|
129
135
|
});
|
|
130
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Creates a `ReadableStream` that yields byte data using a BYOB-style handler.
|
|
139
|
+
*
|
|
140
|
+
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
141
|
+
* the caller must check and handle it manually.
|
|
142
|
+
*
|
|
143
|
+
* The resulting stream can provide a BYOB reader if supported by the runtime.
|
|
144
|
+
* If unsupported, only a default reader is available.
|
|
145
|
+
*
|
|
146
|
+
* @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.
|
|
147
|
+
* @param {number} defaultBufferSize The size of the fallback buffer passed to `handler.read`. Must be a positive safe integer. Used as `autoAllocateChunkSize` when a bytes-type reader is available. If unsupported, used as the size of the internal buffer for a default reader.
|
|
148
|
+
* @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.
|
|
149
|
+
* @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
|
|
150
|
+
*/
|
|
151
|
+
function createBYOBReadableStream(handler, defaultBufferSize, options) {
|
|
152
|
+
requiresNonzeroSafeInt(defaultBufferSize, "defaultBufferSize");
|
|
153
|
+
const read = handler.read;
|
|
154
|
+
const release = handler.release;
|
|
155
|
+
let abortListener = null;
|
|
156
|
+
let buffer = null;
|
|
157
|
+
let cleanupPromise = null;
|
|
158
|
+
function cleanup(type, reason) {
|
|
159
|
+
if (cleanupPromise === null) {
|
|
160
|
+
cleanupPromise = (async () => {
|
|
161
|
+
buffer = null;
|
|
162
|
+
if (options?.signal != null && abortListener != null) {
|
|
163
|
+
options.signal.removeEventListener("abort", abortListener);
|
|
164
|
+
abortListener = null;
|
|
165
|
+
}
|
|
166
|
+
if (release != null) {
|
|
167
|
+
await release(type, reason);
|
|
168
|
+
}
|
|
169
|
+
})();
|
|
170
|
+
}
|
|
171
|
+
return cleanupPromise;
|
|
172
|
+
}
|
|
173
|
+
const useByteStream = (options?.__internal_useByteStream__ !== undefined)
|
|
174
|
+
? options.__internal_useByteStream__
|
|
175
|
+
: isReadableByteStreamAvailable();
|
|
176
|
+
if (!useByteStream) {
|
|
177
|
+
return new ReadableStream({
|
|
178
|
+
start(controller) {
|
|
179
|
+
if (options?.signal != null) {
|
|
180
|
+
abortListener = () => {
|
|
181
|
+
const reason = options?.signal?.reason ?? newAbortSignalDefaultError();
|
|
182
|
+
cleanup("SignalAbort", reason).catch(() => { });
|
|
183
|
+
controller.error(reason);
|
|
184
|
+
};
|
|
185
|
+
options?.signal?.addEventListener("abort", abortListener);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
async pull(controller) {
|
|
189
|
+
try {
|
|
190
|
+
throwIfAborted(options?.signal);
|
|
191
|
+
if (buffer === null) {
|
|
192
|
+
buffer = new Uint8Array(defaultBufferSize);
|
|
193
|
+
}
|
|
194
|
+
throwIfAborted(options?.signal);
|
|
195
|
+
const nread = await read(buffer);
|
|
196
|
+
throwIfAborted(options?.signal);
|
|
197
|
+
requiresSafeUint(nread, "nread");
|
|
198
|
+
if (nread === 0) {
|
|
199
|
+
await cleanup("Close");
|
|
200
|
+
controller.close();
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
controller.enqueue(buffer.slice(0, nread));
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
const isSignalAbort = isThrownByAbortSignal(e, options?.signal);
|
|
207
|
+
await cleanup(isSignalAbort ? "SignalAbort" : "Error", e).catch(() => { });
|
|
208
|
+
throw e;
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
async cancel(reason) {
|
|
212
|
+
await cleanup("Cancel", reason);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
return new ReadableStream({
|
|
217
|
+
type: "bytes",
|
|
218
|
+
autoAllocateChunkSize: defaultBufferSize,
|
|
219
|
+
start(controller) {
|
|
220
|
+
if (options?.signal) {
|
|
221
|
+
abortListener = () => {
|
|
222
|
+
const reason = options?.signal?.reason ?? newAbortSignalDefaultError();
|
|
223
|
+
cleanup("SignalAbort", reason).catch(() => { });
|
|
224
|
+
controller.error(reason);
|
|
225
|
+
};
|
|
226
|
+
options?.signal.addEventListener("abort", abortListener);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
async pull(controller) {
|
|
230
|
+
try {
|
|
231
|
+
throwIfAborted(options?.signal);
|
|
232
|
+
const byob = controller.byobRequest;
|
|
233
|
+
if (byob == null) {
|
|
234
|
+
if (buffer == null) {
|
|
235
|
+
buffer = new Uint8Array(defaultBufferSize);
|
|
236
|
+
}
|
|
237
|
+
throwIfAborted(options?.signal);
|
|
238
|
+
const nread = await read(buffer);
|
|
239
|
+
throwIfAborted(options?.signal);
|
|
240
|
+
requiresSafeUint(nread, "nread");
|
|
241
|
+
if (nread === 0) {
|
|
242
|
+
await cleanup("Close");
|
|
243
|
+
controller.close();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
controller.enqueue(buffer.slice(0, nread));
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const v = byob.view;
|
|
250
|
+
if (v == null)
|
|
251
|
+
return;
|
|
252
|
+
const view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
|
|
253
|
+
throwIfAborted(options?.signal);
|
|
254
|
+
const nread = await read(view);
|
|
255
|
+
throwIfAborted(options?.signal);
|
|
256
|
+
requiresSafeUint(nread, "nread");
|
|
257
|
+
if (nread === 0) {
|
|
258
|
+
await cleanup("Close");
|
|
259
|
+
// byobRequest がある場合、respond を呼ばないと promise が解決されない。
|
|
260
|
+
// controller.close() の後だと respond(0) を読んでもエラーにはならない。
|
|
261
|
+
// https://github.com/whatwg/streams/issues/1170
|
|
262
|
+
controller.close();
|
|
263
|
+
controller.byobRequest?.respond(0);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
byob.respond(nread);
|
|
267
|
+
}
|
|
268
|
+
catch (e) {
|
|
269
|
+
const isSignalAbort = isThrownByAbortSignal(e, options?.signal);
|
|
270
|
+
await cleanup(isSignalAbort ? "SignalAbort" : "Error", e).catch(() => { });
|
|
271
|
+
throw e;
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
async cancel(reason) {
|
|
275
|
+
await cleanup("Cancel", reason);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
131
279
|
/**
|
|
132
280
|
* Creates a `WritableStream` that writes byte data using the provided custom handler.
|
|
133
281
|
*
|
|
134
|
-
* This function itself does not throw errors.
|
|
135
282
|
* If you need to throw an error early when the provided `options.signal` is already aborted,
|
|
136
283
|
* the caller must check and handle it manually.
|
|
137
284
|
*
|
|
138
|
-
* @param handler
|
|
139
|
-
* @param options
|
|
140
|
-
* @returns A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
|
|
285
|
+
* @param {CreateWritableStreamHandler} handler The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.
|
|
286
|
+
* @param {CreateWritableStreamOptions} options Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.
|
|
287
|
+
* @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
|
|
141
288
|
*/
|
|
142
289
|
function createWritableStream(handler, options) {
|
|
143
|
-
const
|
|
290
|
+
const write = handler.write;
|
|
291
|
+
const release = handler.release;
|
|
292
|
+
const bufferSize = options?.bufferSize ?? 0;
|
|
293
|
+
requiresSafeUint(bufferSize, "bufferSize");
|
|
144
294
|
let abortListener = null;
|
|
145
295
|
let buffer = null;
|
|
146
296
|
let bufferOffset = 0;
|
|
@@ -153,8 +303,8 @@ function createWritableStream(handler, options) {
|
|
|
153
303
|
options?.signal?.removeEventListener("abort", abortListener);
|
|
154
304
|
abortListener = null;
|
|
155
305
|
}
|
|
156
|
-
if (
|
|
157
|
-
await
|
|
306
|
+
if (release != null) {
|
|
307
|
+
await release(type, reason);
|
|
158
308
|
}
|
|
159
309
|
})();
|
|
160
310
|
}
|
|
@@ -183,11 +333,11 @@ function createWritableStream(handler, options) {
|
|
|
183
333
|
? buffer.subarray(0, bufferOffset)
|
|
184
334
|
: buffer.slice(0, bufferOffset);
|
|
185
335
|
throwIfAborted(options?.signal);
|
|
186
|
-
await
|
|
336
|
+
await write(chunk);
|
|
187
337
|
bufferOffset = 0;
|
|
188
338
|
}
|
|
189
339
|
throwIfAborted(options?.signal);
|
|
190
|
-
await
|
|
340
|
+
await write(mapToArrayBuffer(src));
|
|
191
341
|
return;
|
|
192
342
|
}
|
|
193
343
|
let srcOffset = 0;
|
|
@@ -206,7 +356,7 @@ function createWritableStream(handler, options) {
|
|
|
206
356
|
if (options?.useBufferView !== true) {
|
|
207
357
|
buffer = null;
|
|
208
358
|
}
|
|
209
|
-
await
|
|
359
|
+
await write(chunk);
|
|
210
360
|
bufferOffset = 0;
|
|
211
361
|
}
|
|
212
362
|
}
|
|
@@ -222,7 +372,7 @@ function createWritableStream(handler, options) {
|
|
|
222
372
|
if (0 < bufferOffset && buffer != null) {
|
|
223
373
|
const view = buffer.subarray(0, bufferOffset);
|
|
224
374
|
buffer = null;
|
|
225
|
-
await
|
|
375
|
+
await write(view);
|
|
226
376
|
}
|
|
227
377
|
await cleanup("Close");
|
|
228
378
|
}
|
|
@@ -266,6 +416,24 @@ function mapToArrayBuffer(buffer) {
|
|
|
266
416
|
? buffer
|
|
267
417
|
: new Uint8Array(buffer);
|
|
268
418
|
}
|
|
419
|
+
function requiresSafeUint(num, numName) {
|
|
420
|
+
const name = numName ?? "value";
|
|
421
|
+
if (!Number.isSafeInteger(num)) {
|
|
422
|
+
throw new TypeError(`${name} must be a safe integer.`);
|
|
423
|
+
}
|
|
424
|
+
if (num < 0) {
|
|
425
|
+
throw new RangeError(`${name} must be a positive integer.`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
function requiresNonzeroSafeInt(num, numName) {
|
|
429
|
+
const name = numName;
|
|
430
|
+
if (!Number.isSafeInteger(num)) {
|
|
431
|
+
throw new TypeError(`${name} must be a safe integer.`);
|
|
432
|
+
}
|
|
433
|
+
if (num <= 0) {
|
|
434
|
+
throw new RangeError(`${name} must be a non-zero positive integer.`);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
269
437
|
|
|
270
|
-
export { createReadableStream, createWritableStream };
|
|
438
|
+
export { createBYOBReadableStream, createReadableStream, createWritableStream };
|
|
271
439
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export type CreateReadableStreamHandlerSource = Uint8Array<ArrayBuffer> | null | undefined\n\nexport type CreateReadableStreamHandlerReleaseType = \"Close\" | \"Cancel\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateReadableStreamHandler = {\n\n\t/**\n\t * A callback invoked when the stream's consumer requests more data.\n\t * \n\t * - **Yielding data**: Return a `Uint8Array` containing the next chunk of bytes.\n\t * - **Ending the stream**: Return `null`, `undefined`, or an empty `Uint8Array` (`byteLength === 0`) to signal that no more data is available. This will automatically close the stream.\n\t * - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t */\n\tread: () => PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource,\n\n\t/**\n\t * An optional callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream's reader is successfully read to the end. (type: `\"Close\"`)\n\t * - The stream or its reader is explicitly canceled. (type: `\"Cancel\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a read operation. (type: `\"Error\"`)\n\t */\n\trelease?: (type: CreateReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void,\n}\n\nexport type CreateReadableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal\n}\n\n/**\n * Creates a `ReadableStream` that yields byte data using the provided custom handler.\n * \n * This function does not throw errors. \n * If you need to throw an error early when the provided `options.signal` is already aborted,\n * the caller must check and handle it manually.\n * The resulting stream includes a BYOB (Bring Your Own Buffer) reader if supported by the runtime.\n * \n * @param handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.\n * @param options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.\n * @returns A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.\n */\nexport function createReadableStream(\n\thandler: CreateReadableStreamHandler,\n\toptions?: CreateReadableStreamOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\n\tlet abortListener: (() => void) | null = null\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null\n\n\tlet cleanupPromise: Promise<void> | null = null\n\tfunction cleanup(\n\t\ttype: CreateReadableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (handler.release != null) {\n\t\t\t\t\tawait handler.release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\tif (!isReadableByteStreamAvailable()) {\n\t\treturn new ReadableStream({\n\n\t\t\tstart(controller) {\n\t\t\t\tif (options?.signal != null) {\n\t\t\t\t\tabortListener = () => {\n\t\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t\t}\n\t\t\t\t\toptions?.signal?.addEventListener(\"abort\", abortListener);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst data = await handler.read()\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (data == null || data.byteLength === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(data)\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync cancel(reason) {\n\t\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t\t}\n\t\t})\n\t}\n\n\t// autoAllocateChunkSize を指定すると stream.getReader() でも byob が使われるようになるが、\n\t// この実装で byob を用いてもコピーが増えるだけで恩恵が少ないため指定しない。\n\t// また type: \"bytes\" で strategy を指定すると (正確には size を定義すると) エラーになる点にも注意。\n\treturn new ReadableStream({\n\t\ttype: \"bytes\",\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener)\n\t\t\t}\n\t\t},\n\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tbuffer = (await handler.read()) ?? null\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t}\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tawait cleanup(\"Close\")\n\n\t\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されない。\n\t\t\t\t\t// controller.close() の後だと respond(0) を読んでもエラーにはならない。\n\t\t\t\t\t// https://github.com/whatwg/streams/issues/1170\n\t\t\t\t\tcontroller.close()\n\t\t\t\t\tcontroller.byobRequest?.respond(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst byob = controller.byobRequest\n\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されないことに注意\n\t\t\t\tif (byob != null) {\n\t\t\t\t\t// respond する前なので null にならない\n\t\t\t\t\tconst v = byob.view!!\n\t\t\t\t\tconst view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength)\n\t\t\t\t\tconst nread = Math.min(buffer.byteLength, view.byteLength)\n\n\t\t\t\t\tview.set(buffer.subarray(0, nread))\n\t\t\t\t\tbuffer = buffer.subarray(nread)\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tbyob.respond(nread)\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tcontroller.enqueue(buffer)\n\t\t\t\t\tbuffer = null\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\n\t\t\t\t// byobRequest が存在する場合、controller.close() を呼んだだけでは\n\t\t\t\t// Promise は解決されず、respond() も呼ぶ必要がある。\n\t\t\t\t// controller.error() も同様の挙動になる可能性がある。(要検証)\n\t\t\t\t// 少なくとも throw すれば Promise は解決されるため、現状はこの実装とする。\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync cancel(reason) {\n\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t}\n\t})\n}\n\n\nexport type CreateWritableStreamHandlerReleaseType = \"Close\" | \"Abort\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateWritableStreamHandler = {\n\n\t/**\n\t * A callback invoked when a new chunk of byte data is ready to be written.\n\t * \n\t * - **Data Chunk**: Receives a `Uint8Array` containing the data. The exact size and memory reference of this chunk depend on the stream's `bufferSize` and `strictBufferSize` options.\n\t * - **Data Safety**: If `options.useBufferView` is `true`, the `chunk` might be a direct view (subarray) of the internal buffer. To prevent data corruption, do not retain references to this view outside this callback.\n\t * - **Handling Errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t */\n\twrite: (chunk: Uint8Array<ArrayBuffer>) => PromiseLike<void> | void,\n\n\t/**\n\t * A callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream or its writer is explicitly closed. (type: `\"Close\"`)\n\t * - The stream or its writer is explicitly aborted. (type: `\"Abort\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a write operation. (type: `\"Error\"`)\n\t */\n\trelease?: (\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t) => PromiseLike<void> | void,\n}\n\nexport type CreateWritableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * The size of the internal buffer in bytes.\n\t * \n\t * Defaults to `0` (unbuffered).\n\t */\n\tbufferSize?: number,\n\n\t/**\n\t * If `true`, the stream strictly enforces the `bufferSize` for every chunk passed to the handler.\n\t * Only the final `write` call may receive a chunk smaller than the `bufferSize`.\n\t * \n\t * If `false`, chunks larger than the `bufferSize` will bypass the internal buffer and be processed directly.\n\t * \n\t * Defaults to `false`.\n\t */\n\tstrictBufferSize?: boolean,\n\n\t/**\n\t * If `true`, the handler's `write` method can receive a chunk as a view (subarray) of the internal buffer.\n\t * This reduces the number of memory copies, but the received chunk must not be referenced outside the `write` method.\n\t * If you need to retain the chunk data externally, you must make a copy of it within the `write` method.\n\t * \n\t * Defaults to `false`.\n\t */\n\tuseBufferView?: boolean,\n}\n\n/**\n * Creates a `WritableStream` that writes byte data using the provided custom handler.\n * \n * This function itself does not throw errors.\n * If you need to throw an error early when the provided `options.signal` is already aborted, \n * the caller must check and handle it manually.\n * \n * @param handler - The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.\n * @param options - Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.\n * @returns A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.\n */\nexport function createWritableStream(\n\thandler: CreateWritableStreamHandler,\n\toptions?: CreateWritableStreamOptions,\n): WritableStream<Uint8Array<ArrayBufferLike>> {\n\n\tconst bufferSize = Math.max(0, Math.ceil(options?.bufferSize ?? 0))\n\n\tlet abortListener: (() => void) | null = null;\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null;\n\tlet bufferOffset = 0;\n\n\tlet cleanupPromise: Promise<void> | null = null;\n\tfunction cleanup(\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions?.signal?.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (handler.release != null) {\n\t\t\t\t\tawait handler.release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\treturn new WritableStream<Uint8Array<ArrayBufferLike>>({\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal != null) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener);\n\t\t\t}\n\t\t},\n\n\t\tasync write(src) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t// bufferSize が 0 以下の場合や src が buffer より大きい場合は buffer を使わずに処理する。\n\t\t\t\tif (\n\t\t\t\t\tbufferSize <= 0 ||\n\t\t\t\t\t(bufferSize <= src.byteLength && options?.strictBufferSize !== true)\n\t\t\t\t) {\n\n\t\t\t\t\t// buffer に既にデータがある場合、それを処理する。\n\t\t\t\t\tif (buffer !== null && 0 < bufferOffset) {\n\t\t\t\t\t\tconst chunk = options?.useBufferView === true\n\t\t\t\t\t\t\t? buffer.subarray(0, bufferOffset)\n\t\t\t\t\t\t\t: buffer.slice(0, bufferOffset)\n\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\t\tawait handler.write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tawait handler.write(mapToArrayBuffer(src))\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tlet srcOffset = 0;\n\t\t\t\twhile (srcOffset < src.byteLength) {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (buffer === null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(bufferSize)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst n = Math.min(bufferSize - bufferOffset, src.byteLength - srcOffset)\n\t\t\t\t\tbuffer.set(src.subarray(srcOffset, srcOffset + n), bufferOffset)\n\t\t\t\t\tbufferOffset += n\n\t\t\t\t\tsrcOffset += n\n\n\t\t\t\t\tif (bufferOffset === bufferSize) {\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\t\tconst chunk = buffer\n\t\t\t\t\t\tif (options?.useBufferView !== true) {\n\t\t\t\t\t\t\tbuffer = null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait handler.write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync close() {\n\t\t\ttry {\n\t\t\t\tif (0 < bufferOffset && buffer != null) {\n\t\t\t\t\tconst view = buffer.subarray(0, bufferOffset)\n\t\t\t\t\tbuffer = null\n\t\t\t\t\tawait handler.write(view)\n\t\t\t\t}\n\t\t\t\tawait cleanup(\"Close\")\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tawait cleanup(\"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync abort(reason) {\n\t\t\tawait cleanup(\"Abort\", reason)\n\t\t}\n\t})\n}\n\n\nlet _isReadableByteStreamAvailable: boolean | null = null\nfunction isReadableByteStreamAvailable() {\n\tif (_isReadableByteStreamAvailable === null) {\n\t\ttry {\n\t\t\tnew ReadableStream({ type: \"bytes\" })\n\t\t\t_isReadableByteStreamAvailable = true\n\t\t}\n\t\tcatch {\n\t\t\t_isReadableByteStreamAvailable = false\n\t\t}\n\t}\n\n\treturn _isReadableByteStreamAvailable\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined | null) {\n\tif (signal?.aborted === true) {\n\t\tthrow (signal?.reason ?? newAbortSignalDefaultError())\n\t}\n}\n\nfunction newAbortSignalDefaultError(): Error {\n\treturn new DOMException(\"The operation was aborted.\", \"AbortError\")\n}\n\nfunction isThrownByAbortSignal(err: unknown, signal: AbortSignal | null | undefined): boolean {\n\treturn (signal?.aborted === true) &&\n\t\t(err === signal.reason || (err instanceof DOMException && err.name === \"AbortError\"));\n}\n\nfunction mapToArrayBuffer(\n\tbuffer: Uint8Array<ArrayBufferLike>\n): Uint8Array<ArrayBuffer> {\n\n\treturn buffer.buffer instanceof ArrayBuffer\n\t\t? buffer as Uint8Array<ArrayBuffer>\n\t\t: new Uint8Array(buffer)\n}\n"],"names":[],"mappings":"AAsCA;;;;;;;;;;;AAWG;AACG,SAAU,oBAAoB,CACnC,OAAoC,EACpC,OAAqC,EAAA;IAGrC,IAAI,aAAa,GAAwB,IAAI;IAC7C,IAAI,MAAM,GAAmC,IAAI;IAEjD,IAAI,cAAc,GAAyB,IAAI;AAC/C,IAAA,SAAS,OAAO,CACf,IAA4C,EAC5C,MAAgB,EAAA;AAGhB,QAAA,IAAI,cAAc,KAAK,IAAI,EAAE;AAC5B,YAAA,cAAc,GAAG,CAAC,YAAW;gBAC5B,MAAM,GAAG,IAAI;gBACb,IAAI,OAAO,EAAE,MAAM,IAAI,IAAI,IAAI,aAAa,IAAI,IAAI,EAAE;oBACrD,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC;oBAC1D,aAAa,GAAG,IAAI;gBACrB;AACA,gBAAA,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI,EAAE;oBAC5B,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;gBACpC;YACD,CAAC,GAAG;QACL;AACA,QAAA,OAAO,cAAc;IACtB;AAEA,IAAA,IAAI,CAAC,6BAA6B,EAAE,EAAE;QACrC,OAAO,IAAI,cAAc,CAAC;AAEzB,YAAA,KAAK,CAAC,UAAU,EAAA;AACf,gBAAA,IAAI,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE;oBAC5B,aAAa,GAAG,MAAK;wBACpB,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,0BAA0B,EAAE;AACtE,wBAAA,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC,KAAK,CAA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AClC,IAAA,OAAO,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC;AACpE;AAEA,SAAS,qBAAqB,CAAC,GAAY,EAAE,MAAsC,EAAA;AAClF,IAAA,OAAO,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI;AAC/B,SAAC,GAAG,KAAK,MAAM,CAAC,MAAM,KAAK,GAAG,YAAY,YAAY,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;AACvF;AAEA,SAAS,gBAAgB,CACxB,MAAmC,EAAA;AAGnC,IAAA,OAAO,MAAM,CAAC,MAAM,YAAY;AAC/B,UAAE;AACF,UAAE,IAAI,UAAU,CAAC,MAAM,CAAC;AAC1B;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["export type CreateReadableStreamHandlerSource = Uint8Array<ArrayBuffer> | null | undefined\n\nexport type CreateReadableStreamHandlerReleaseType = \"Close\" | \"Cancel\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateReadableStreamHandler = {\n\n\t/**\n\t * A callback invoked when the stream's consumer requests more data.\n\t * \n\t * - **Yielding data**: Return a `Uint8Array` containing the next chunk of bytes.\n\t * - **Ending the stream**: Return `null`, `undefined`, or an empty `Uint8Array` (`byteLength === 0`) to signal that no more data is available. This will automatically close the stream.\n\t * - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t * \n\t * @returns {PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource} The next chunk of bytes.\n\t */\n\tread: () => PromiseLike<CreateReadableStreamHandlerSource> | CreateReadableStreamHandlerSource,\n\n\t/**\n\t * An optional callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream's reader is successfully read to the end. (type: `\"Close\"`)\n\t * - The stream or its reader is explicitly canceled. (type: `\"Cancel\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a read operation. (type: `\"Error\"`)\n\t * \n\t * @param {CreateReadableStreamHandlerReleaseType} type The type of the release operation.\n\t * @param {unknown} reason The reason for the release operation.\n\t */\n\trelease?: (type: CreateReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void,\n}\n\nexport type CreateReadableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * @internal\n\t * @ignore\n\t */\n\t__internal_useByteStream__?: boolean\n}\n\n/**\n * Creates a `ReadableStream` that yields byte data using the provided custom handler.\n * \n * If you need to throw an error early when the provided `options.signal` is already aborted,\n * the caller must check and handle it manually.\n * \n * The resulting stream can provide a BYOB reader if supported by the runtime.\n * If unsupported, only a default reader is available.\n * \n * @param {CreateReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateReadableStreamHandler` for details.\n * @param {CreateReadableStreamOptions} options Optional settings: `signal`. See `CreateReadableStreamOptions` for details.\n * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.\n */\nexport function createReadableStream(\n\thandler: CreateReadableStreamHandler,\n\toptions?: CreateReadableStreamOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\n\tconst read = handler.read\n\tconst release = handler.release\n\n\tlet abortListener: (() => void) | null = null\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null\n\n\tlet cleanupPromise: Promise<void> | null = null\n\tfunction cleanup(\n\t\ttype: CreateReadableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (release != null) {\n\t\t\t\t\tawait release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\tconst useByteStream = (options?.__internal_useByteStream__ !== undefined)\n\t\t? options.__internal_useByteStream__\n\t\t: isReadableByteStreamAvailable()\n\n\tif (!useByteStream) {\n\t\treturn new ReadableStream({\n\n\t\t\tstart(controller) {\n\t\t\t\tif (options?.signal != null) {\n\t\t\t\t\tabortListener = () => {\n\t\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t\t}\n\t\t\t\t\toptions?.signal?.addEventListener(\"abort\", abortListener);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst data = await read()\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (data == null || data.byteLength === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(data)\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync cancel(reason) {\n\t\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t\t}\n\t\t})\n\t}\n\n\t// autoAllocateChunkSize を指定すると stream.getReader() でも byob が使われるようになるが、\n\t// この実装で byob を用いてもコピーが増えるだけで恩恵が少ないため指定しない。\n\t// また type: \"bytes\" で strategy を指定すると (正確には size を定義すると) エラーになる点にも注意。\n\treturn new ReadableStream({\n\t\ttype: \"bytes\",\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener)\n\t\t\t}\n\t\t},\n\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tbuffer = (await read()) ?? null\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t}\n\t\t\t\tif (buffer == null || buffer.byteLength === 0) {\n\t\t\t\t\tawait cleanup(\"Close\")\n\n\t\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されない。\n\t\t\t\t\t// controller.close() の後だと respond(0) を読んでもエラーにはならない。\n\t\t\t\t\t// https://github.com/whatwg/streams/issues/1170\n\t\t\t\t\tcontroller.close()\n\t\t\t\t\tcontroller.byobRequest?.respond(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst byob = controller.byobRequest\n\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されないことに注意\n\t\t\t\tif (byob != null) {\n\t\t\t\t\t// respond する前なので null にならない\n\t\t\t\t\tconst v = byob.view!!\n\t\t\t\t\tconst view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength)\n\t\t\t\t\tconst nread = Math.min(buffer.byteLength, view.byteLength)\n\n\t\t\t\t\tview.set(buffer.subarray(0, nread))\n\t\t\t\t\tbuffer = buffer.subarray(nread)\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tbyob.respond(nread)\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tcontroller.enqueue(buffer)\n\t\t\t\t\tbuffer = null\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\n\t\t\t\t// byobRequest が存在する場合、controller.close() を呼んだだけでは\n\t\t\t\t// Promise は解決されず、respond() も呼ぶ必要がある。\n\t\t\t\t// controller.error() も同様の挙動になる可能性がある。(要検証)\n\t\t\t\t// 少なくとも throw すれば Promise は解決されるため、現状はこの実装とする。\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync cancel(reason) {\n\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t}\n\t})\n}\n\n\nexport type CreateBYOBReadableStreamHandlerReleaseType = \"Close\" | \"Cancel\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateBYOBReadableStreamHandler = {\n\n\t/**\n\t * A callback invoked when the stream's consumer requests more data.\n\t *\n\t * - **Yielding data**: Write bytes into the provided `buffer` and return the number of bytes written (1 or greater). The returned value must not exceed `buffer.byteLength`.\n\t * - **Ending the stream**: Return `0` to signal that no more data is available. This will automatically close the stream.\n\t * - **Handling errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t * \n\t * @param {Uint8Array<ArrayBuffer>} buffer The buffer to write the data into.\n\t * @returns {PromiseLike<number> | number} The number of bytes written.\n\t */\n\tread: (buffer: Uint8Array<ArrayBuffer>) => PromiseLike<number> | number\n\n\t/**\n\t * An optional callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream's reader is successfully read to the end. (type: `\"Close\"`)\n\t * - The stream or its reader is explicitly canceled. (type: `\"Cancel\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a read operation. (type: `\"Error\"`)\n\t * \n\t * @param {CreateBYOBReadableStreamHandlerReleaseType} type The type of the release operation.\n\t * @param {unknown} reason The reason for the release operation.\n\t */\n\trelease?: (type: CreateBYOBReadableStreamHandlerReleaseType, reason?: unknown) => PromiseLike<void> | void,\n}\n\nexport type CreateBYOBReadableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * @internal\n\t * @ignore\n\t */\n\t__internal_useByteStream__?: boolean\n}\n\n/**\n * Creates a `ReadableStream` that yields byte data using a BYOB-style handler.\n *\n * If you need to throw an error early when the provided `options.signal` is already aborted,\n * the caller must check and handle it manually.\n * \n * The resulting stream can provide a BYOB reader if supported by the runtime.\n * If unsupported, only a default reader is available.\n *\n * @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.\n * @param {number} defaultBufferSize The size of the fallback buffer passed to `handler.read`. Must be a positive safe integer. Used as `autoAllocateChunkSize` when a bytes-type reader is available. If unsupported, used as the size of the internal buffer for a default reader.\n * @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.\n * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.\n */\nexport function createBYOBReadableStream(\n\thandler: CreateBYOBReadableStreamHandler,\n\tdefaultBufferSize: number,\n\toptions?: CreateBYOBReadableStreamOptions,\n): ReadableStream<Uint8Array<ArrayBuffer>> {\n\n\trequiresNonzeroSafeInt(defaultBufferSize, \"defaultBufferSize\")\n\tconst read = handler.read\n\tconst release = handler.release\n\n\tlet abortListener: (() => void) | null = null\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null\n\n\tlet cleanupPromise: Promise<void> | null = null\n\tfunction cleanup(\n\t\ttype: CreateBYOBReadableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions.signal.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (release != null) {\n\t\t\t\t\tawait release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\tconst useByteStream = (options?.__internal_useByteStream__ !== undefined)\n\t\t? options.__internal_useByteStream__\n\t\t: isReadableByteStreamAvailable()\n\n\tif (!useByteStream) {\n\t\treturn new ReadableStream({\n\n\t\t\tstart(controller) {\n\t\t\t\tif (options?.signal != null) {\n\t\t\t\t\tabortListener = () => {\n\t\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t\t}\n\t\t\t\t\toptions?.signal?.addEventListener(\"abort\", abortListener);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync pull(controller) {\n\t\t\t\ttry {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (buffer === null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(defaultBufferSize)\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst nread = await read(buffer)\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\trequiresSafeUint(nread, \"nread\")\n\t\t\t\t\tif (nread === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(buffer.slice(0, nread))\n\t\t\t\t}\n\t\t\t\tcatch (e) {\n\t\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tasync cancel(reason) {\n\t\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn new ReadableStream({\n\t\ttype: \"bytes\",\n\t\tautoAllocateChunkSize: defaultBufferSize,\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener)\n\t\t\t}\n\t\t},\n\n\t\tasync pull(controller) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tconst byob = controller.byobRequest\n\t\t\t\tif (byob == null) {\n\t\t\t\t\tif (buffer == null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(defaultBufferSize)\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tconst nread = await read(buffer)\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\trequiresSafeUint(nread, \"nread\")\n\t\t\t\t\tif (nread === 0) {\n\t\t\t\t\t\tawait cleanup(\"Close\")\n\t\t\t\t\t\tcontroller.close()\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tcontroller.enqueue(buffer.slice(0, nread))\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tconst v = byob.view\n\t\t\t\tif (v == null) return\n\t\t\t\tconst view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength)\n\n\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\tconst nread = await read(view)\n\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\trequiresSafeUint(nread, \"nread\")\n\t\t\t\tif (nread === 0) {\n\t\t\t\t\tawait cleanup(\"Close\")\n\n\t\t\t\t\t// byobRequest がある場合、respond を呼ばないと promise が解決されない。\n\t\t\t\t\t// controller.close() の後だと respond(0) を読んでもエラーにはならない。\n\t\t\t\t\t// https://github.com/whatwg/streams/issues/1170\n\t\t\t\t\tcontroller.close()\n\t\t\t\t\tcontroller.byobRequest?.respond(0)\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tbyob.respond(nread)\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync cancel(reason) {\n\t\t\tawait cleanup(\"Cancel\", reason)\n\t\t}\n\t})\n}\n\n\nexport type CreateWritableStreamHandlerReleaseType = \"Close\" | \"Abort\" | \"SignalAbort\" | \"Error\"\n\nexport type CreateWritableStreamHandler = {\n\n\t/**\n\t * A callback invoked when a new chunk of byte data is ready to be written.\n\t * \n\t * - **Data Chunk**: Receives a `Uint8Array` containing the data. The exact size and memory reference of this chunk depend on the stream's `bufferSize` and `strictBufferSize` options.\n\t * - **Data Safety**: If `options.useBufferView` is `true`, the `chunk` might be a direct view (subarray) of the internal buffer. To prevent data corruption, do not retain references to this view outside this callback.\n\t * - **Handling Errors**: If an error is thrown inside this function, the stream will enter an error state and terminate.\n\t * \n\t * @param {Uint8Array<ArrayBuffer>} chunk The chunk of byte data to write.\n\t */\n\twrite: (chunk: Uint8Array<ArrayBuffer>) => PromiseLike<void> | void,\n\n\t/**\n\t * A callback for performing cleanup operations.\n\t * \n\t * This function is guaranteed to be invoked at most once. \n\t * It is automatically triggered when the stream terminates under any of the following conditions:\n\t * - The stream or its writer is explicitly closed. (type: `\"Close\"`)\n\t * - The stream or its writer is explicitly aborted. (type: `\"Abort\"`)\n\t * - The provided `AbortSignal` fires an `abort` event. (type: `\"SignalAbort\"`)\n\t * - An error occurs during a write operation. (type: `\"Error\"`)\n\t * \n\t * @param {CreateWritableStreamHandlerReleaseType} type The type of the release operation.\n\t * @param {unknown} reason The reason for the release operation.\n\t */\n\trelease?: (\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t) => PromiseLike<void> | void,\n}\n\nexport type CreateWritableStreamOptions = {\n\n\t/**\n\t * An `AbortSignal` to abort the stream.\n\t * \n\t * When the abort event is fired, the handler's `release` function will be called.\n\t */\n\tsignal?: AbortSignal,\n\n\t/**\n\t * The size of the internal buffer in bytes. \n\t * Must be a zero or positive safe integer. \n\t * \n\t * Defaults to `0` (unbuffered).\n\t */\n\tbufferSize?: number,\n\n\t/**\n\t * If `true`, the stream strictly enforces the `bufferSize` for every chunk passed to the handler.\n\t * Only the final `write` call may receive a chunk smaller than the `bufferSize`.\n\t * \n\t * If `false`, chunks larger than the `bufferSize` will bypass the internal buffer and be processed directly.\n\t * \n\t * Defaults to `false`.\n\t */\n\tstrictBufferSize?: boolean,\n\n\t/**\n\t * If `true`, the handler's `write` method can receive a chunk as a view (subarray) of the internal buffer.\n\t * This reduces the number of memory copies, but the received chunk must not be referenced outside the `write` method.\n\t * If you need to retain the chunk data externally, you must make a copy of it within the `write` method.\n\t * \n\t * Defaults to `false`.\n\t */\n\tuseBufferView?: boolean,\n}\n\n/**\n * Creates a `WritableStream` that writes byte data using the provided custom handler.\n * \n * If you need to throw an error early when the provided `options.signal` is already aborted, \n * the caller must check and handle it manually.\n * \n * @param {CreateWritableStreamHandler} handler The stream handler: `write`, `release`. See `CreateWritableStreamHandler` for details.\n * @param {CreateWritableStreamOptions} options Optional settings: `signal`, `bufferSize`, `strictBufferSize`, `useBufferView`. See `CreateWritableStreamOptions` for details.\n * @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.\n */\nexport function createWritableStream(\n\thandler: CreateWritableStreamHandler,\n\toptions?: CreateWritableStreamOptions,\n): WritableStream<Uint8Array<ArrayBufferLike>> {\n\n\tconst write = handler.write\n\tconst release = handler.release\n\tconst bufferSize = options?.bufferSize ?? 0\n\trequiresSafeUint(bufferSize, \"bufferSize\")\n\n\tlet abortListener: (() => void) | null = null;\n\tlet buffer: Uint8Array<ArrayBuffer> | null = null;\n\tlet bufferOffset = 0;\n\n\tlet cleanupPromise: Promise<void> | null = null;\n\tfunction cleanup(\n\t\ttype: CreateWritableStreamHandlerReleaseType,\n\t\treason?: unknown\n\t): Promise<void> {\n\n\t\tif (cleanupPromise === null) {\n\t\t\tcleanupPromise = (async () => {\n\t\t\t\tbuffer = null\n\t\t\t\tif (options?.signal != null && abortListener != null) {\n\t\t\t\t\toptions?.signal?.removeEventListener(\"abort\", abortListener)\n\t\t\t\t\tabortListener = null\n\t\t\t\t}\n\t\t\t\tif (release != null) {\n\t\t\t\t\tawait release(type, reason)\n\t\t\t\t}\n\t\t\t})()\n\t\t}\n\t\treturn cleanupPromise\n\t}\n\n\treturn new WritableStream<Uint8Array<ArrayBufferLike>>({\n\n\t\tstart(controller) {\n\t\t\tif (options?.signal != null) {\n\t\t\t\tabortListener = () => {\n\t\t\t\t\tconst reason = options?.signal?.reason ?? newAbortSignalDefaultError()\n\t\t\t\t\tcleanup(\"SignalAbort\", reason).catch(() => { })\n\t\t\t\t\tcontroller.error(reason)\n\t\t\t\t}\n\t\t\t\toptions?.signal.addEventListener(\"abort\", abortListener);\n\t\t\t}\n\t\t},\n\n\t\tasync write(src) {\n\t\t\ttry {\n\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t// bufferSize が 0 以下の場合や src が buffer より大きい場合は buffer を使わずに処理する。\n\t\t\t\tif (\n\t\t\t\t\tbufferSize <= 0 ||\n\t\t\t\t\t(bufferSize <= src.byteLength && options?.strictBufferSize !== true)\n\t\t\t\t) {\n\n\t\t\t\t\t// buffer に既にデータがある場合、それを処理する。\n\t\t\t\t\tif (buffer !== null && 0 < bufferOffset) {\n\t\t\t\t\t\tconst chunk = options?.useBufferView === true\n\t\t\t\t\t\t\t? buffer.subarray(0, bufferOffset)\n\t\t\t\t\t\t\t: buffer.slice(0, bufferOffset)\n\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\t\tawait write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tawait write(mapToArrayBuffer(src))\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tlet srcOffset = 0;\n\t\t\t\twhile (srcOffset < src.byteLength) {\n\t\t\t\t\tthrowIfAborted(options?.signal)\n\t\t\t\t\tif (buffer === null) {\n\t\t\t\t\t\tbuffer = new Uint8Array(bufferSize)\n\t\t\t\t\t}\n\n\t\t\t\t\tconst n = Math.min(bufferSize - bufferOffset, src.byteLength - srcOffset)\n\t\t\t\t\tbuffer.set(src.subarray(srcOffset, srcOffset + n), bufferOffset)\n\t\t\t\t\tbufferOffset += n\n\t\t\t\t\tsrcOffset += n\n\n\t\t\t\t\tif (bufferOffset === bufferSize) {\n\t\t\t\t\t\tthrowIfAborted(options?.signal)\n\n\t\t\t\t\t\tconst chunk = buffer\n\t\t\t\t\t\tif (options?.useBufferView !== true) {\n\t\t\t\t\t\t\tbuffer = null\n\t\t\t\t\t\t}\n\t\t\t\t\t\tawait write(chunk)\n\t\t\t\t\t\tbufferOffset = 0\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tconst isSignalAbort = isThrownByAbortSignal(e, options?.signal)\n\t\t\t\tawait cleanup(isSignalAbort ? \"SignalAbort\" : \"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync close() {\n\t\t\ttry {\n\t\t\t\tif (0 < bufferOffset && buffer != null) {\n\t\t\t\t\tconst view = buffer.subarray(0, bufferOffset)\n\t\t\t\t\tbuffer = null\n\t\t\t\t\tawait write(view)\n\t\t\t\t}\n\t\t\t\tawait cleanup(\"Close\")\n\t\t\t}\n\t\t\tcatch (e) {\n\t\t\t\tawait cleanup(\"Error\", e).catch(() => { })\n\t\t\t\tthrow e\n\t\t\t}\n\t\t},\n\n\t\tasync abort(reason) {\n\t\t\tawait cleanup(\"Abort\", reason)\n\t\t}\n\t})\n}\n\n\nlet _isReadableByteStreamAvailable: boolean | null = null\nfunction isReadableByteStreamAvailable(): boolean {\n\tif (_isReadableByteStreamAvailable === null) {\n\t\ttry {\n\t\t\tnew ReadableStream({ type: \"bytes\" })\n\t\t\t_isReadableByteStreamAvailable = true\n\t\t}\n\t\tcatch {\n\t\t\t_isReadableByteStreamAvailable = false\n\t\t}\n\t}\n\treturn _isReadableByteStreamAvailable\n}\n\nfunction throwIfAborted(signal: AbortSignal | undefined | null) {\n\tif (signal?.aborted === true) {\n\t\tthrow (signal?.reason ?? newAbortSignalDefaultError())\n\t}\n}\n\nfunction newAbortSignalDefaultError(): Error {\n\treturn new DOMException(\"The operation was aborted.\", \"AbortError\")\n}\n\nfunction isThrownByAbortSignal(err: unknown, signal: AbortSignal | null | undefined): boolean {\n\treturn (signal?.aborted === true) &&\n\t\t(err === signal.reason || (err instanceof DOMException && err.name === \"AbortError\"));\n}\n\nfunction mapToArrayBuffer(\n\tbuffer: Uint8Array<ArrayBufferLike>\n): Uint8Array<ArrayBuffer> {\n\n\treturn buffer.buffer instanceof ArrayBuffer\n\t\t? buffer as Uint8Array<ArrayBuffer>\n\t\t: new Uint8Array(buffer)\n}\n\nfunction requiresSafeUint(num: number, numName?: string): void {\n\tconst name = numName ?? \"value\";\n\n\tif (!Number.isSafeInteger(num)) {\n\t\tthrow new TypeError(`${name} must be a safe integer.`);\n\t}\n\tif (num < 0) {\n\t\tthrow new RangeError(`${name} must be a positive integer.`);\n\t}\n}\n\nfunction requiresNonzeroSafeInt(num: number, numName?: string): void {\n\tconst name = numName ?? \"value\";\n\n\tif (!Number.isSafeInteger(num)) {\n\t\tthrow new TypeError(`${name} must be a safe integer.`);\n\t}\n\tif (num <= 0) {\n\t\tthrow new RangeError(`${name} must be a non-zero positive integer.`);\n\t}\n}"],"names":[],"mappings":"AAiDA;;;;;;;;;;;;AAYG;AACG,SAAU,oBAAoB,CACnC,OAAoC,EACpC,OAAqC,EAAA;AAGrC,IAAA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI;AACzB,IAAA,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO;IAE/B,IAAI,aAAa,GAAwB,IAAI;IAC7C,IAAI,MAAM,GAAmC,IAAI;IAEjD,IAAI,cAAc,GAAyB,IAAI;AAC/C,IAAA,SAAS,OAAO,CACf,IAA4C,EAC5C,MAAgB,EAAA;AAGhB,QAAA,IAAI,cAAc,KAAK,IAAI,EAAE;AAC5B,YAAA,cAAc,GAAG,CAAC,YAAW;gBAC5B,MAAM,GAAG,IAAI;gBACb,IAAI,OAAO,EAAE,MAAM,IAAI,IAAI,IAAI,aAAa,IAAI,IAAI,EAAE;oBACrD,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,aAAa,CAAC;oBAC1D,aAAa,GAAG,IAAI;gBACrB;AACA,gBAAA,IAAI,OAAO,IAAI,IAAI,EAAE;AACpB,oBAAA,MAAM,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;gBAC5B;YACD,CAAC,GAAG;QACL;AACA,QAAA,OAAO,cAAc;IACtB;IAEA,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,0BAA0B,KAAK,SAAS;UACrE,OAAO,CAAC;UACR,6BAA6B,EAAE;IAElC,IAAI,CAAC,aAAa,EAAE;QACnB,OAAO,IAAI,cAAc,CAAC;AAEzB,YAAA,KAAK,CAAC,UAAU,EAAA;AACf,gBAAA,IAAI,OAAO,EAAE,MAAM,IAAI,IAAI,EAAE;oBAC5B,aAAa,GAAG,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
{
|
|
2
2
|
"name": "create-web-stream",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"author": "OkaYu",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"description": "Create Web Readable/Writable streams from simple handlers and options.",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "rollup -c",
|
|
36
36
|
"pretest": "pnpm build",
|
|
37
|
-
"prepublishOnly": "pnpm run build"
|
|
37
|
+
"prepublishOnly": "pnpm run build",
|
|
38
|
+
"test": "node --test"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"rollup": "^4.0.0",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"typescript": "^5.0.0"
|
|
44
45
|
},
|
|
45
46
|
"engines": {
|
|
46
|
-
"node": ">=18.
|
|
47
|
+
"node": ">=18.9.0"
|
|
47
48
|
},
|
|
48
49
|
"sideEffects": false
|
|
49
50
|
}
|