@poe-platform/safe-bash 0.1.745 → 0.1.746

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.
Files changed (59) hide show
  1. package/README.md +5 -1
  2. package/dist/image-ast/browser/sharp.d.ts +1 -1
  3. package/dist/image-ast/index.js +133 -35
  4. package/dist/image-ast/sharp.d.ts +1 -1
  5. package/dist/safe-bash/chunks/{chunk-EAUCLWEZ.js → chunk-3ZNXN3XO.js} +423 -245
  6. package/dist/safe-bash/chunks/{chunk-2F7Q532M.js → chunk-4GK4FAT6.js} +3 -3
  7. package/dist/safe-bash/chunks/{chunk-WCNFCN2G.js → chunk-BS6QFRNX.js} +2 -2
  8. package/dist/safe-bash/chunks/{chunk-IZZ7KX4E.js → chunk-JCXAGOEK.js} +40 -3
  9. package/dist/safe-bash/chunks/{chunk-I3DOFJSJ.js → chunk-MUWJPSGN.js} +2 -2
  10. package/dist/safe-bash/chunks/{chunk-7RP6WOWK.js → chunk-OF2PDE3W.js} +2 -2
  11. package/dist/safe-bash/chunks/{src-FTMTU65U.js → src-T2WAWJXF.js} +2 -2
  12. package/dist/safe-bash/command-chunks/{chunk-DRCPJVZF.js → chunk-44N2IRVP.js} +17 -5
  13. package/dist/safe-bash/command-chunks/{chunk-LYKC7WJB.js → chunk-6742OVAC.js} +37 -3
  14. package/dist/safe-bash/command-chunks/{chunk-BMBXSLVX.js → chunk-6QU5OLPJ.js} +2 -2
  15. package/dist/safe-bash/command-chunks/{chunk-YHANNN7I.js → chunk-S3BO2NJT.js} +7 -0
  16. package/dist/safe-bash/commands/basic.d.ts +2 -0
  17. package/dist/safe-bash/commands/basic.js +236 -9
  18. package/dist/safe-bash/commands/pr/index.browser.js +1 -1
  19. package/dist/safe-bash/commands/streams.js +9 -56
  20. package/dist/safe-bash/commands/table-text/index.js +5 -1
  21. package/dist/safe-bash/commands/text.js +13 -2
  22. package/dist/safe-bash/commands/time-env/shared.js +2 -2
  23. package/dist/safe-bash/commands/time-env/sleep.js +6 -4
  24. package/dist/safe-bash/commands/timeout/index.d.ts +7 -0
  25. package/dist/safe-bash/commands/timeout/index.js +52 -32
  26. package/dist/safe-bash/commands/timeout/scheduler.js +7 -6
  27. package/dist/safe-bash/core.browser.js +2697 -543
  28. package/dist/safe-bash/opt-in/commands/shuf/random.js +2 -3
  29. package/dist/safe-bash/opt-in/shell/extensions/read/index.js +1 -1
  30. package/dist/safe-bash/opt-in/shell/extensions/trap/index.d.ts +1 -2
  31. package/dist/safe-bash/opt-in/shell/extensions/trap/index.js +1 -8
  32. package/dist/safe-bash/playwright/adapter.d.ts +2 -0
  33. package/dist/safe-bash/playwright/private-target-transport.d.ts +1 -0
  34. package/dist/safe-bash/playwright/private-target-transport.js +21 -21
  35. package/dist/safe-bash/shell/runtime.d.ts +20 -1
  36. package/dist/safe-bash/shell/runtime.js +3014 -532
  37. package/dist/safe-bash/shell/sync-jq-expression.d.ts +6 -0
  38. package/dist/safe-bash/shell/sync-jq-expression.js +46 -0
  39. package/dist/safe-bash-command-cal/index.js +32 -12
  40. package/dist/safe-bash-command-hostname/index.js +22 -7
  41. package/dist/safe-bash-command-id/index.js +28 -9
  42. package/dist/safe-bash-command-pandoc/command.js +1 -1
  43. package/dist/safe-bash-command-pandoc/index.js +1 -1
  44. package/dist/safe-bash-command-ssconvert/command.d.ts +2 -2
  45. package/dist/safe-bash-command-ssconvert/contracts.d.ts +4 -0
  46. package/dist/safe-bash-command-ssconvert/engine.d.ts +2 -2
  47. package/dist/safe-bash-command-ssconvert/index.js +410 -237
  48. package/dist/safe-bash-command-whoami/index.js +26 -12
  49. package/dist/safe-bash-query-engine/index.js +3 -3
  50. package/dist/safe-bash-query-engine/interpreter.js +1 -1
  51. package/dist/safe-bash-query-engine/parser.js +1 -1
  52. package/dist/safe-bash-query-engine/query-core.js +3 -3
  53. package/dist/safe-playwright-cloudflare/browser-private-transport.js +8 -13
  54. package/dist/safe-playwright-cloudflare/browser-storage-control.js +13 -4
  55. package/dist/safe-playwright-cloudflare/browser-trace-archive.js +1 -1
  56. package/package.json +18 -14
  57. package/dist/image-ast/streams/node.d.ts +0 -10
  58. package/dist/image-ast/streams/node.js +0 -5
  59. package/dist/image-ast/streams/web.js +0 -94
@@ -4,6 +4,7 @@ import {
4
4
 
5
5
  // packages/safe-bash-command-whoami/dist/index.js
6
6
  init_buffer();
7
+ import { isFsError } from "../safe-bash-contracts/errors.js";
7
8
  import { commandRuntimeIdentity, writeText } from "../safe-bash-contracts/index.js";
8
9
  function settings(options = {}) {
9
10
  const limits = {
@@ -31,19 +32,23 @@ Packaged by Safe-Bash (Sandbox VFS-ish/GNU runtime)
31
32
  async function resolvePasswdUser(context, euid, maxBytes) {
32
33
  try {
33
34
  const bytes = await context.fs.readFile("/etc/passwd", { signal: context.signal });
34
- if (bytes.byteLength <= maxBytes) {
35
- const text = new TextDecoder().decode(bytes);
36
- for (const line of text.split("\n")) {
37
- const trimmed = line.trim();
38
- if (!trimmed || trimmed.startsWith("#"))
39
- continue;
40
- const parts = trimmed.split(":");
41
- if (parts.length >= 3 && Number(parts[2]) === euid) {
42
- return parts[0];
43
- }
35
+ context.signal.throwIfAborted();
36
+ if (bytes.byteLength > maxBytes)
37
+ throw new RangeError("/etc/passwd exceeds size limit");
38
+ const text = new TextDecoder().decode(bytes);
39
+ for (const line of text.split("\n")) {
40
+ const trimmed = line.trim();
41
+ if (!trimmed || trimmed.startsWith("#"))
42
+ continue;
43
+ const parts = trimmed.split(":");
44
+ if (parts.length >= 3 && Number(parts[2]) === euid) {
45
+ return parts[0];
44
46
  }
45
47
  }
46
- } catch {
48
+ } catch (error) {
49
+ context.signal.throwIfAborted();
50
+ if (!isFsError(error, "ENOENT"))
51
+ throw error;
47
52
  }
48
53
  return void 0;
49
54
  }
@@ -96,7 +101,16 @@ function createWhoamiCommand(options = {}) {
96
101
  const euid = options.euid ?? options.uid ?? (rawEuid !== void 0 && /^\d+$/.test(rawEuid) ? Number(rawEuid) : void 0);
97
102
  let username;
98
103
  if (euid !== void 0) {
99
- username = await resolvePasswdUser(context, euid, limits.maxPasswdBytes);
104
+ try {
105
+ username = await resolvePasswdUser(context, euid, limits.maxPasswdBytes);
106
+ } catch (error) {
107
+ context.signal.throwIfAborted();
108
+ if (!(error instanceof RangeError))
109
+ throw error;
110
+ await writeText(context.stderr, `whoami: ${error.message}
111
+ `);
112
+ return { exitCode: 1 };
113
+ }
100
114
  if (!username) {
101
115
  if (euid === 0)
102
116
  username = "root";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-BMBXSLVX.js";
5
- import "../safe-bash/command-chunks/chunk-YHANNN7I.js";
6
- import "../safe-bash/command-chunks/chunk-LYKC7WJB.js";
4
+ } from "../safe-bash/command-chunks/chunk-6QU5OLPJ.js";
5
+ import "../safe-bash/command-chunks/chunk-S3BO2NJT.js";
6
+ import "../safe-bash/command-chunks/chunk-6742OVAC.js";
7
7
  import "../safe-bash/command-chunks/chunk-TPDKSK66.js";
8
8
  import "../safe-bash/command-chunks/chunk-A7SJ2FC6.js";
9
9
  import "../safe-bash/command-chunks/chunk-XZ7QGZMG.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Interpreter
3
- } from "../safe-bash/command-chunks/chunk-LYKC7WJB.js";
3
+ } from "../safe-bash/command-chunks/chunk-6742OVAC.js";
4
4
  import "../safe-bash/command-chunks/chunk-TPDKSK66.js";
5
5
  import "../safe-bash/command-chunks/chunk-A7SJ2FC6.js";
6
6
  import "../safe-bash/command-chunks/chunk-XZ7QGZMG.js";
@@ -2,7 +2,7 @@ import {
2
2
  functions,
3
3
  moduleProgram,
4
4
  parse
5
- } from "../safe-bash/command-chunks/chunk-YHANNN7I.js";
5
+ } from "../safe-bash/command-chunks/chunk-S3BO2NJT.js";
6
6
  import "../safe-bash/command-chunks/chunk-OMJILKF3.js";
7
7
  import "../safe-bash/command-chunks/chunk-E4JIJFSF.js";
8
8
  import "../safe-bash/command-chunks/chunk-R2FMX7XC.js";
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-BMBXSLVX.js";
5
- import "../safe-bash/command-chunks/chunk-YHANNN7I.js";
6
- import "../safe-bash/command-chunks/chunk-LYKC7WJB.js";
4
+ } from "../safe-bash/command-chunks/chunk-6QU5OLPJ.js";
5
+ import "../safe-bash/command-chunks/chunk-S3BO2NJT.js";
6
+ import "../safe-bash/command-chunks/chunk-6742OVAC.js";
7
7
  import "../safe-bash/command-chunks/chunk-TPDKSK66.js";
8
8
  import "../safe-bash/command-chunks/chunk-A7SJ2FC6.js";
9
9
  import "../safe-bash/command-chunks/chunk-XZ7QGZMG.js";
@@ -15,20 +15,14 @@ function protocolObject(data, maxBytes, maxGraphNodes, maxGraphDepth) {
15
15
  });
16
16
  }
17
17
  export function createBrowserPrivateTransport(options = {}) {
18
- const { maxClients = 8, ...guardOptions } = options;
19
- const maxTargets = options.maxPrivateTargets ?? 256;
18
+ const { maxClients = Infinity, ...guardOptions } = options;
19
+ const maxTargets = options.maxPrivateTargets ?? Infinity;
20
20
  const maxBytes = options.maxMessageBytes ?? Infinity;
21
- const creationTimeoutMs = options.creationTimeoutMs ?? 10000;
22
- for (const [name, value] of Object.entries({
23
- ...guardOptions,
24
- maxClients,
25
- maxTargets,
26
- ...(options.maxMessageBytes === undefined ? {} : { maxBytes }),
27
- creationTimeoutMs,
28
- })) {
29
- if (!Number.isSafeInteger(value) ||
21
+ const creationTimeoutMs = options.creationTimeoutMs ?? Infinity;
22
+ for (const [name, value] of Object.entries(options)) {
23
+ if (value !== undefined && value !== Infinity && (!Number.isSafeInteger(value) ||
30
24
  value <= 0 ||
31
- (name.endsWith("TimeoutMs") && value > 2147483647))
25
+ (name.endsWith("TimeoutMs") && value > 2147483647)))
32
26
  throw new TypeError(`Invalid private browser limit: ${name}`);
33
27
  }
34
28
  const clients = new Set();
@@ -258,7 +252,8 @@ export function createBrowserPrivateTransport(options = {}) {
258
252
  active: true,
259
253
  tokens: new Map(),
260
254
  destroyed: new Set(),
261
- deadline: AbortSignal.timeout(creationTimeoutMs),
255
+ deadline: Number.isFinite(creationTimeoutMs)
256
+ ? AbortSignal.timeout(creationTimeoutMs) : new AbortController().signal,
262
257
  expire: () => fail(new Error("Private target creation identity timed out")),
263
258
  };
264
259
  creation = entry;
@@ -75,6 +75,11 @@ export function createBrowserStorageControl(options) {
75
75
  let closing;
76
76
  let timer;
77
77
  let timedCommandId;
78
+ let clock = performance.now();
79
+ function now() {
80
+ clock = Math.max(clock, performance.now());
81
+ return clock;
82
+ }
78
83
  function scheduleDeadline() {
79
84
  if (!Number.isFinite(limits.commandTimeoutMs) || closed)
80
85
  return;
@@ -88,15 +93,19 @@ export function createBrowserStorageControl(options) {
88
93
  if (!first)
89
94
  return;
90
95
  const [id, command] = first;
91
- const remaining = limits.commandTimeoutMs - (performance.now() - command.started);
96
+ const previous = now();
97
+ const remaining = limits.commandTimeoutMs - (previous - command.started);
98
+ const step = Math.min(Math.max(0, remaining), 2147483647);
92
99
  timer = setTimeout(() => {
93
100
  timer = undefined;
94
101
  timedCommandId = undefined;
95
- if (performance.now() - command.started >= limits.commandTimeoutMs)
102
+ // Timer completion advances the logical clock even when workerd freezes performance.now().
103
+ clock = Math.max(now(), previous + step);
104
+ if (clock - command.started >= limits.commandTimeoutMs)
96
105
  expireCommand(id, command.method);
97
106
  // Long deadlines are chunked to avoid the native timer's signed-int overflow.
98
107
  scheduleDeadline();
99
- }, Math.min(Math.max(0, remaining), 2147483647));
108
+ }, step);
100
109
  }
101
110
  function notifyDetached(reason) {
102
111
  const event = {
@@ -251,7 +260,7 @@ export function createBrowserStorageControl(options) {
251
260
  bytes,
252
261
  sessionId,
253
262
  method,
254
- started: performance.now(),
263
+ started: now(),
255
264
  });
256
265
  pendingBytes += bytes;
257
266
  scheduleDeadline();
@@ -30,7 +30,7 @@ export async function writeTraceArchive(options) {
30
30
  const zipLimits = {
31
31
  maxArchiveBytes: limits.maxArchiveBytes, maxEntryBytes: limits.maxBytes,
32
32
  maxTotalBytes: limits.maxBytes, maxMembers: limits.maxFiles,
33
- maxPathBytes: 65535, maxDepth: 32, maxPaxBytes: 65535, maxTextBytes: 65535,
33
+ maxPathBytes: Infinity, maxDepth: Infinity, maxPaxBytes: Infinity, maxTextBytes: Infinity,
34
34
  chunkSize: 65536,
35
35
  };
36
36
  const entries = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.745",
3
+ "version": "0.1.746",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -72,25 +72,31 @@
72
72
  },
73
73
  "./contracts": {
74
74
  "types": {
75
+ "workerd": "./dist/safe-bash/contracts/index.d.ts",
75
76
  "browser": "./dist/safe-bash/contracts/index.d.ts",
76
77
  "default": "./dist/safe-bash/contracts/node.d.ts"
77
78
  },
79
+ "workerd": "./dist/safe-bash/contracts/index.js",
78
80
  "browser": "./dist/safe-bash/contracts/index.js",
79
81
  "import": "./dist/safe-bash/contracts/node.js"
80
82
  },
81
83
  "./contracts/index": {
82
84
  "types": {
85
+ "workerd": "./dist/safe-bash/contracts/index.d.ts",
83
86
  "browser": "./dist/safe-bash/contracts/index.d.ts",
84
87
  "default": "./dist/safe-bash/contracts/node.d.ts"
85
88
  },
89
+ "workerd": "./dist/safe-bash/contracts/index.js",
86
90
  "browser": "./dist/safe-bash/contracts/index.js",
87
91
  "import": "./dist/safe-bash/contracts/node.js"
88
92
  },
89
93
  "./contracts/path": {
90
94
  "types": {
95
+ "workerd": "./dist/safe-bash/contracts/path.d.ts",
91
96
  "browser": "./dist/safe-bash/contracts/path.d.ts",
92
97
  "default": "./dist/safe-bash/contracts/node-path.d.ts"
93
98
  },
99
+ "workerd": "./dist/safe-bash/contracts/path.js",
94
100
  "browser": "./dist/safe-bash/contracts/path.js",
95
101
  "import": "./dist/safe-bash/contracts/node-path.js"
96
102
  },
@@ -100,9 +106,9 @@
100
106
  },
101
107
  "./commands/op": {
102
108
  "types": "./dist/safe-bash/commands/op/index.d.ts",
103
- "import": "./dist/safe-bash/commands/op/index.js",
104
109
  "workerd": "./dist/safe-bash/commands/op/index.browser.js",
105
- "browser": "./dist/safe-bash/commands/op/index.browser.js"
110
+ "browser": "./dist/safe-bash/commands/op/index.browser.js",
111
+ "import": "./dist/safe-bash/commands/op/index.js"
106
112
  },
107
113
  "./commands/network": {
108
114
  "types": {
@@ -278,6 +284,7 @@
278
284
  },
279
285
  "./node": {
280
286
  "types": "./dist/safe-bash/node.d.ts",
287
+ "workerd": null,
281
288
  "browser": null,
282
289
  "import": "./dist/safe-bash/node.js"
283
290
  },
@@ -313,6 +320,7 @@
313
320
  },
314
321
  "./commands/docx": {
315
322
  "types": "./dist/safe-bash/commands/docx/index.d.ts",
323
+ "workerd": "./dist/safe-bash/commands/docx/index.browser.js",
316
324
  "browser": "./dist/safe-bash/commands/docx/index.browser.js",
317
325
  "import": "./dist/safe-bash/commands/docx/index.js"
318
326
  },
@@ -322,21 +330,25 @@
322
330
  },
323
331
  "./commands/python": {
324
332
  "types": "./dist/safe-bash/commands/python/index.d.ts",
333
+ "workerd": "./dist/safe-bash/commands/python/index.browser.js",
325
334
  "browser": "./dist/safe-bash/commands/python/index.browser.js",
326
335
  "import": "./dist/safe-bash/commands/python/index.js"
327
336
  },
328
337
  "./commands/python/worker": {
329
338
  "types": "./dist/safe-bash/commands/python/worker.d.ts",
339
+ "workerd": "./dist/safe-bash/commands/python/worker.browser.js",
330
340
  "browser": "./dist/safe-bash/commands/python/worker.browser.js",
331
341
  "import": "./dist/safe-bash/commands/python/worker.js"
332
342
  },
333
343
  "./commands/python/node": {
334
344
  "types": "./dist/safe-bash/commands/python/node.d.ts",
345
+ "workerd": null,
335
346
  "browser": null,
336
347
  "import": "./dist/safe-bash/commands/python/node.js"
337
348
  },
338
349
  "./commands/python/docker": {
339
350
  "types": "./dist/safe-bash/commands/python/docker.d.ts",
351
+ "workerd": null,
340
352
  "browser": null,
341
353
  "import": "./dist/safe-bash/commands/python/docker.js"
342
354
  },
@@ -346,6 +358,7 @@
346
358
  },
347
359
  "./commands/playwright": {
348
360
  "types": "./dist/safe-bash/commands/playwright/index.d.ts",
361
+ "workerd": "./dist/safe-bash/commands/playwright/index.js",
349
362
  "browser": "./dist/safe-bash/commands/playwright/index.js",
350
363
  "import": "./dist/safe-bash/commands/playwright/index.js"
351
364
  },
@@ -407,6 +420,7 @@
407
420
  },
408
421
  "./playwright": {
409
422
  "types": "./dist/safe-bash/commands/playwright/index.d.ts",
423
+ "workerd": "./dist/safe-bash/commands/playwright/index.js",
410
424
  "browser": "./dist/safe-bash/commands/playwright/index.js",
411
425
  "import": "./dist/safe-bash/commands/playwright/index.js"
412
426
  },
@@ -631,7 +645,7 @@
631
645
  "access": "public"
632
646
  },
633
647
  "dependencies": {
634
- "@poe-platform/safe-fs": "0.1.745",
648
+ "@poe-platform/safe-fs": "0.1.746",
635
649
  "pdf-lib": "1.17.1",
636
650
  "@types/node": "^25.2.2",
637
651
  "pako": "3.0.1",
@@ -659,16 +673,6 @@
659
673
  "types": "./dist/safe-bash-command-git/runtime.d.ts",
660
674
  "workerd": "./dist/safe-bash-command-git/runtime.workerd.js",
661
675
  "default": "./dist/safe-bash-command-git/runtime.js"
662
- },
663
- "#image-ast-streams": {
664
- "types": {
665
- "workerd": "./dist/image-ast/browser/streams/web.d.ts",
666
- "browser": "./dist/image-ast/browser/streams/web.d.ts",
667
- "default": "./dist/image-ast/streams/node.d.ts"
668
- },
669
- "workerd": "./dist/image-ast/streams/web.js",
670
- "browser": "./dist/image-ast/streams/web.js",
671
- "default": "./dist/image-ast/streams/node.js"
672
676
  }
673
677
  },
674
678
  "peerDependencies": {
@@ -1,10 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- export { EventEmitter } from "node:events";
3
- export { Duplex } from "node:stream";
4
- export declare const outputBytes: {
5
- (array: import("node:buffer").WithImplicitCoercion<ArrayLike<number>>): Buffer<ArrayBuffer>;
6
- <TArrayBuffer extends import("node:buffer").WithImplicitCoercion<ArrayBufferLike>>(arrayBuffer: TArrayBuffer, byteOffset?: number, length?: number): Buffer<import("node:buffer").ImplicitArrayBuffer<TArrayBuffer>>;
7
- (string: import("node:buffer").WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;
8
- (arrayOrString: import("node:buffer").WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;
9
- };
10
- export declare const isBuffer: (obj: any) => obj is Buffer;
@@ -1,5 +0,0 @@
1
- import { Buffer } from "node:buffer";
2
- export { EventEmitter } from "node:events";
3
- export { Duplex } from "node:stream";
4
- export const outputBytes = Buffer.from;
5
- export const isBuffer = Buffer.isBuffer;
@@ -1,94 +0,0 @@
1
- export const outputBytes = Uint8Array.from.bind(Uint8Array);
2
- export const isBuffer = (_input) => false;
3
- export class EventEmitter {
4
- listeners = new Map();
5
- on(event, listener) {
6
- let listeners = this.listeners.get(event);
7
- if (!listeners)
8
- this.listeners.set(event, listeners = new Set());
9
- listeners.add(listener);
10
- return this;
11
- }
12
- once(event, listener) {
13
- const once = (...args) => { this.removeListener(event, once); listener(...args); };
14
- return this.on(event, once);
15
- }
16
- removeListener(event, listener) {
17
- this.listeners.get(event)?.delete(listener);
18
- return this;
19
- }
20
- emit(event, ...args) {
21
- const listeners = [...this.listeners.get(event) ?? []];
22
- for (const listener of listeners)
23
- listener(...args);
24
- return listeners.length > 0;
25
- }
26
- }
27
- /** Browser Sharp streams use standard Web Streams for pressure and cancellation. */
28
- export class Duplex extends EventEmitter {
29
- readable;
30
- writable;
31
- writableFinished = false;
32
- controller;
33
- closed = false;
34
- constructor() {
35
- super();
36
- this.readable = new ReadableStream({
37
- start: controller => { this.controller = controller; },
38
- pull: () => { this._read(); },
39
- cancel: reason => { this.destroy(reason instanceof Error ? reason : undefined); },
40
- }, { highWaterMark: 0 });
41
- this.writable = new WritableStream({
42
- write: chunk => new Promise((resolve, reject) => {
43
- this._write(chunk, "utf8", error => {
44
- if (error) {
45
- this.destroy(error);
46
- reject(error);
47
- }
48
- else
49
- resolve();
50
- });
51
- }),
52
- close: () => { this.writableFinished = true; this.emit("finish"); },
53
- abort: reason => { this.destroy(reason instanceof Error ? reason : undefined); },
54
- });
55
- }
56
- _write(_chunk, _encoding, callback) {
57
- callback(new Error("Writable operation is not implemented"));
58
- }
59
- _read() { throw new Error("Readable operation is not implemented"); }
60
- push(chunk) {
61
- if (this.closed)
62
- return false;
63
- if (chunk === null) {
64
- this.closed = true;
65
- this.controller.close();
66
- }
67
- else
68
- this.controller.enqueue(new Uint8Array(chunk));
69
- return (this.controller.desiredSize ?? 0) > 0;
70
- }
71
- destroy(error) {
72
- if (!this.closed) {
73
- this.closed = true;
74
- this.controller.error(error ?? new Error("Stream cancelled"));
75
- this.emit("error", error ?? new Error("Stream cancelled"));
76
- }
77
- return this;
78
- }
79
- async *[Symbol.asyncIterator]() {
80
- const reader = this.readable.getReader();
81
- try {
82
- while (true) {
83
- const result = await reader.read();
84
- if (result.done)
85
- return;
86
- yield result.value;
87
- }
88
- }
89
- finally {
90
- await reader.cancel();
91
- reader.releaseLock();
92
- }
93
- }
94
- }