create-web-stream 1.1.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 CHANGED
@@ -2,7 +2,7 @@ Note: **I’m using a translation tool, so there may be some inappropriate expre
2
2
 
3
3
  # create-web-stream
4
4
 
5
- A library for creating Web API `ReadableStream` and `WritableStream` instances from simple handlers and options. Supports BYOB readers, buffered writers, `AbortSignal` integration, and guaranteed cleanup callbacks.
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.
6
6
 
7
7
  ## Installation
8
8
 
@@ -18,41 +18,49 @@ yarn add create-web-stream
18
18
 
19
19
  ### createReadableStream
20
20
 
21
- Creates a `ReadableStream` that yields byte data from the handler's `read` callback. Use `release` for cleanup when the stream ends.
21
+ Creates a `ReadableStream` that yields byte data from the handler's `read` callback.
22
22
 
23
23
  ```ts
24
24
  import { createReadableStream } from "create-web-stream"
25
25
 
26
- const stream = createReadableStream({
27
- read() {
28
- // Return the next chunk. Return null, undefined, or empty Uint8Array to end the stream
29
- return new Uint8Array([1, 2, 3])
30
- },
31
- release(type, reason) {
32
- console.log("end:", type, reason)
33
- },
34
- }, { signal: myAbortSignal })
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
+ )
35
40
  ```
36
41
 
37
42
  ### createBYOBReadableStream
38
43
 
39
- Creates a BYOB-style `ReadableStream` that reads directly into a buffer provided by the consumer. `read(buffer)` returns the number of bytes written.
44
+ Creates a BYOB-style `ReadableStream` that reads directly into a buffer provided by the consumer.
40
45
 
41
46
  ```ts
42
47
  import { createBYOBReadableStream } from "create-web-stream"
43
48
 
44
49
  const stream = createBYOBReadableStream(
50
+ // Handler
45
51
  {
46
- read(buffer) {
52
+ async read(buffer) {
47
53
  // Write into buffer and return the number of bytes written. Return 0 to end the stream
48
54
  buffer.set(new Uint8Array([1, 2, 3]), 0)
49
55
  return 3
50
56
  },
51
- release(type, reason) {
52
- console.log("end:", type, reason)
57
+ async release(type, reason) {
58
+ // Clearnup
53
59
  },
54
60
  },
55
- 4096, // bufferSize for fallback
61
+ // bufferSize for fallback
62
+ 4096,
63
+ // Options
56
64
  { signal: myAbortSignal }
57
65
  )
58
66
  ```
@@ -65,19 +73,21 @@ Creates a `WritableStream` that passes byte data to the handler's `write` callba
65
73
  import { createWritableStream } from "create-web-stream"
66
74
 
67
75
  const stream = createWritableStream(
76
+ // Handler
68
77
  {
69
- write(chunk) {
70
- console.log("write:", chunk.byteLength, "bytes")
78
+ async write(chunk) {
79
+ console.log("write: ", chunk.byteLength, "bytes")
71
80
  },
72
- release(type, reason) {
73
- console.log("end:", type, reason)
81
+ async release(type, reason) {
82
+ // Clearnup
74
83
  },
75
84
  },
85
+ // Options
76
86
  {
77
87
  signal: myAbortSignal,
78
- bufferSize: 4096, // 0 for no buffering (default)
79
- strictBufferSize: false, // true to always pass chunks of exactly bufferSize (except the last)
80
- useBufferView: false, // true to pass a buffer view to write and reduce copies
88
+ bufferSize: 0, // Unbuffered
89
+ strictBufferSize: false,
90
+ useBufferView: false,
81
91
  }
82
92
  )
83
93
  ```
package/dist/index.cjs CHANGED
@@ -14,6 +14,8 @@
14
14
  * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
15
15
  */
16
16
  function createReadableStream(handler, options) {
17
+ const read = handler.read;
18
+ const release = handler.release;
17
19
  let abortListener = null;
18
20
  let buffer = null;
19
21
  let cleanupPromise = null;
@@ -25,8 +27,8 @@ function createReadableStream(handler, options) {
25
27
  options.signal.removeEventListener("abort", abortListener);
26
28
  abortListener = null;
27
29
  }
28
- if (handler.release != null) {
29
- await handler.release(type, reason);
30
+ if (release != null) {
31
+ await release(type, reason);
30
32
  }
31
33
  })();
32
34
  }
@@ -50,7 +52,7 @@ function createReadableStream(handler, options) {
50
52
  async pull(controller) {
51
53
  try {
52
54
  throwIfAborted(options?.signal);
53
- const data = await handler.read();
55
+ const data = await read();
54
56
  throwIfAborted(options?.signal);
55
57
  if (data == null || data.byteLength === 0) {
56
58
  await cleanup("Close");
@@ -89,7 +91,7 @@ function createReadableStream(handler, options) {
89
91
  try {
90
92
  throwIfAborted(options?.signal);
91
93
  if (buffer == null || buffer.byteLength === 0) {
92
- buffer = (await handler.read()) ?? null;
94
+ buffer = (await read()) ?? null;
93
95
  throwIfAborted(options?.signal);
94
96
  }
95
97
  if (buffer == null || buffer.byteLength === 0) {
@@ -144,13 +146,14 @@ function createReadableStream(handler, options) {
144
146
  * If unsupported, only a default reader is available.
145
147
  *
146
148
  * @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.
147
- * @param {number} defaultBufferSize The default size of the 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.
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.
148
150
  * @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.
149
151
  * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
150
152
  */
151
153
  function createBYOBReadableStream(handler, defaultBufferSize, options) {
152
- defaultBufferSize = Math.ceil(defaultBufferSize);
153
154
  requiresNonzeroSafeInt(defaultBufferSize, "defaultBufferSize");
155
+ const read = handler.read;
156
+ const release = handler.release;
154
157
  let abortListener = null;
155
158
  let buffer = null;
156
159
  let cleanupPromise = null;
@@ -162,8 +165,8 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
162
165
  options.signal.removeEventListener("abort", abortListener);
163
166
  abortListener = null;
164
167
  }
165
- if (handler.release != null) {
166
- await handler.release(type, reason);
168
+ if (release != null) {
169
+ await release(type, reason);
167
170
  }
168
171
  })();
169
172
  }
@@ -191,7 +194,7 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
191
194
  buffer = new Uint8Array(defaultBufferSize);
192
195
  }
193
196
  throwIfAborted(options?.signal);
194
- const nread = await handler.read(buffer);
197
+ const nread = await read(buffer);
195
198
  throwIfAborted(options?.signal);
196
199
  requiresSafeUint(nread, "nread");
197
200
  if (nread === 0) {
@@ -234,7 +237,7 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
234
237
  buffer = new Uint8Array(defaultBufferSize);
235
238
  }
236
239
  throwIfAborted(options?.signal);
237
- const nread = await handler.read(buffer);
240
+ const nread = await read(buffer);
238
241
  throwIfAborted(options?.signal);
239
242
  requiresSafeUint(nread, "nread");
240
243
  if (nread === 0) {
@@ -246,9 +249,11 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
246
249
  return;
247
250
  }
248
251
  const v = byob.view;
252
+ if (v == null)
253
+ return;
249
254
  const view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
250
255
  throwIfAborted(options?.signal);
251
- const nread = await handler.read(view);
256
+ const nread = await read(view);
252
257
  throwIfAborted(options?.signal);
253
258
  requiresSafeUint(nread, "nread");
254
259
  if (nread === 0) {
@@ -284,6 +289,8 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
284
289
  * @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
285
290
  */
286
291
  function createWritableStream(handler, options) {
292
+ const write = handler.write;
293
+ const release = handler.release;
287
294
  const bufferSize = options?.bufferSize ?? 0;
288
295
  requiresSafeUint(bufferSize, "bufferSize");
289
296
  let abortListener = null;
@@ -298,8 +305,8 @@ function createWritableStream(handler, options) {
298
305
  options?.signal?.removeEventListener("abort", abortListener);
299
306
  abortListener = null;
300
307
  }
301
- if (handler.release != null) {
302
- await handler.release(type, reason);
308
+ if (release != null) {
309
+ await release(type, reason);
303
310
  }
304
311
  })();
305
312
  }
@@ -328,11 +335,11 @@ function createWritableStream(handler, options) {
328
335
  ? buffer.subarray(0, bufferOffset)
329
336
  : buffer.slice(0, bufferOffset);
330
337
  throwIfAborted(options?.signal);
331
- await handler.write(chunk);
338
+ await write(chunk);
332
339
  bufferOffset = 0;
333
340
  }
334
341
  throwIfAborted(options?.signal);
335
- await handler.write(mapToArrayBuffer(src));
342
+ await write(mapToArrayBuffer(src));
336
343
  return;
337
344
  }
338
345
  let srcOffset = 0;
@@ -351,7 +358,7 @@ function createWritableStream(handler, options) {
351
358
  if (options?.useBufferView !== true) {
352
359
  buffer = null;
353
360
  }
354
- await handler.write(chunk);
361
+ await write(chunk);
355
362
  bufferOffset = 0;
356
363
  }
357
364
  }
@@ -367,7 +374,7 @@ function createWritableStream(handler, options) {
367
374
  if (0 < bufferOffset && buffer != null) {
368
375
  const view = buffer.subarray(0, bufferOffset);
369
376
  buffer = null;
370
- await handler.write(view);
377
+ await write(view);
371
378
  }
372
379
  await cleanup("Close");
373
380
  }
@@ -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\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\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\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 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 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 default size of the 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\tdefaultBufferSize = Math.ceil(defaultBufferSize)\n\trequiresNonzeroSafeInt(defaultBufferSize, \"defaultBufferSize\")\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 (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\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 handler.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 handler.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\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 handler.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 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 (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(): 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;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;gBACp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,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;;;;;;"}
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 positive integer.`);\n\t}\n}"],"names":[],"mappings":";;AAiDA;;;;;;;;;;;;AAYG;AACG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,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
@@ -94,7 +94,7 @@ export type CreateBYOBReadableStreamOptions = {
94
94
  * If unsupported, only a default reader is available.
95
95
  *
96
96
  * @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.
97
- * @param {number} defaultBufferSize The default size of the 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.
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
98
  * @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.
99
99
  * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
100
100
  */
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@
12
12
  * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
13
13
  */
14
14
  function createReadableStream(handler, options) {
15
+ const read = handler.read;
16
+ const release = handler.release;
15
17
  let abortListener = null;
16
18
  let buffer = null;
17
19
  let cleanupPromise = null;
@@ -23,8 +25,8 @@ function createReadableStream(handler, options) {
23
25
  options.signal.removeEventListener("abort", abortListener);
24
26
  abortListener = null;
25
27
  }
26
- if (handler.release != null) {
27
- await handler.release(type, reason);
28
+ if (release != null) {
29
+ await release(type, reason);
28
30
  }
29
31
  })();
30
32
  }
@@ -48,7 +50,7 @@ function createReadableStream(handler, options) {
48
50
  async pull(controller) {
49
51
  try {
50
52
  throwIfAborted(options?.signal);
51
- const data = await handler.read();
53
+ const data = await read();
52
54
  throwIfAborted(options?.signal);
53
55
  if (data == null || data.byteLength === 0) {
54
56
  await cleanup("Close");
@@ -87,7 +89,7 @@ function createReadableStream(handler, options) {
87
89
  try {
88
90
  throwIfAborted(options?.signal);
89
91
  if (buffer == null || buffer.byteLength === 0) {
90
- buffer = (await handler.read()) ?? null;
92
+ buffer = (await read()) ?? null;
91
93
  throwIfAborted(options?.signal);
92
94
  }
93
95
  if (buffer == null || buffer.byteLength === 0) {
@@ -142,13 +144,14 @@ function createReadableStream(handler, options) {
142
144
  * If unsupported, only a default reader is available.
143
145
  *
144
146
  * @param {CreateBYOBReadableStreamHandler} handler The stream handler: `read`, `release`. See `CreateBYOBReadableStreamHandler` for details.
145
- * @param {number} defaultBufferSize The default size of the 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.
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.
146
148
  * @param {CreateBYOBReadableStreamOptions} options Optional settings: `signal`. See `CreateBYOBReadableStreamOptions` for details.
147
149
  * @returns {ReadableStream<Uint8Array<ArrayBuffer>>} A `ReadableStream<Uint8Array<ArrayBuffer>>` configured with the provided handler and options.
148
150
  */
149
151
  function createBYOBReadableStream(handler, defaultBufferSize, options) {
150
- defaultBufferSize = Math.ceil(defaultBufferSize);
151
152
  requiresNonzeroSafeInt(defaultBufferSize, "defaultBufferSize");
153
+ const read = handler.read;
154
+ const release = handler.release;
152
155
  let abortListener = null;
153
156
  let buffer = null;
154
157
  let cleanupPromise = null;
@@ -160,8 +163,8 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
160
163
  options.signal.removeEventListener("abort", abortListener);
161
164
  abortListener = null;
162
165
  }
163
- if (handler.release != null) {
164
- await handler.release(type, reason);
166
+ if (release != null) {
167
+ await release(type, reason);
165
168
  }
166
169
  })();
167
170
  }
@@ -189,7 +192,7 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
189
192
  buffer = new Uint8Array(defaultBufferSize);
190
193
  }
191
194
  throwIfAborted(options?.signal);
192
- const nread = await handler.read(buffer);
195
+ const nread = await read(buffer);
193
196
  throwIfAborted(options?.signal);
194
197
  requiresSafeUint(nread, "nread");
195
198
  if (nread === 0) {
@@ -232,7 +235,7 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
232
235
  buffer = new Uint8Array(defaultBufferSize);
233
236
  }
234
237
  throwIfAborted(options?.signal);
235
- const nread = await handler.read(buffer);
238
+ const nread = await read(buffer);
236
239
  throwIfAborted(options?.signal);
237
240
  requiresSafeUint(nread, "nread");
238
241
  if (nread === 0) {
@@ -244,9 +247,11 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
244
247
  return;
245
248
  }
246
249
  const v = byob.view;
250
+ if (v == null)
251
+ return;
247
252
  const view = new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
248
253
  throwIfAborted(options?.signal);
249
- const nread = await handler.read(view);
254
+ const nread = await read(view);
250
255
  throwIfAborted(options?.signal);
251
256
  requiresSafeUint(nread, "nread");
252
257
  if (nread === 0) {
@@ -282,6 +287,8 @@ function createBYOBReadableStream(handler, defaultBufferSize, options) {
282
287
  * @returns {WritableStream<Uint8Array<ArrayBufferLike>>} A `WritableStream<Uint8Array<ArrayBufferLike>>` instance configured with the provided handler and options.
283
288
  */
284
289
  function createWritableStream(handler, options) {
290
+ const write = handler.write;
291
+ const release = handler.release;
285
292
  const bufferSize = options?.bufferSize ?? 0;
286
293
  requiresSafeUint(bufferSize, "bufferSize");
287
294
  let abortListener = null;
@@ -296,8 +303,8 @@ function createWritableStream(handler, options) {
296
303
  options?.signal?.removeEventListener("abort", abortListener);
297
304
  abortListener = null;
298
305
  }
299
- if (handler.release != null) {
300
- await handler.release(type, reason);
306
+ if (release != null) {
307
+ await release(type, reason);
301
308
  }
302
309
  })();
303
310
  }
@@ -326,11 +333,11 @@ function createWritableStream(handler, options) {
326
333
  ? buffer.subarray(0, bufferOffset)
327
334
  : buffer.slice(0, bufferOffset);
328
335
  throwIfAborted(options?.signal);
329
- await handler.write(chunk);
336
+ await write(chunk);
330
337
  bufferOffset = 0;
331
338
  }
332
339
  throwIfAborted(options?.signal);
333
- await handler.write(mapToArrayBuffer(src));
340
+ await write(mapToArrayBuffer(src));
334
341
  return;
335
342
  }
336
343
  let srcOffset = 0;
@@ -349,7 +356,7 @@ function createWritableStream(handler, options) {
349
356
  if (options?.useBufferView !== true) {
350
357
  buffer = null;
351
358
  }
352
- await handler.write(chunk);
359
+ await write(chunk);
353
360
  bufferOffset = 0;
354
361
  }
355
362
  }
@@ -365,7 +372,7 @@ function createWritableStream(handler, options) {
365
372
  if (0 < bufferOffset && buffer != null) {
366
373
  const view = buffer.subarray(0, bufferOffset);
367
374
  buffer = null;
368
- await handler.write(view);
375
+ await write(view);
369
376
  }
370
377
  await cleanup("Close");
371
378
  }
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\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\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\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 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 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 default size of the 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\tdefaultBufferSize = Math.ceil(defaultBufferSize)\n\trequiresNonzeroSafeInt(defaultBufferSize, \"defaultBufferSize\")\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 (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\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 handler.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 handler.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\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 handler.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 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 (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(): 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":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AAgB,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;;;;"}
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,IAA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,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-web-stream",
3
- "version": "1.1.0",
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.",