documonster 0.20.2 → 0.21.0

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 (144) hide show
  1. package/README.md +1 -1
  2. package/README_zh.md +1 -1
  3. package/THIRD_PARTY_NOTICES.md +34 -2
  4. package/dist/esm/modules/archive/core/byte-queue.js +2 -1
  5. package/dist/esm/modules/archive/unzip/stream.browser.js +6 -0
  6. package/dist/esm/modules/csv/parse/async.js +2 -1
  7. package/dist/esm/modules/excel/bridge/csv-bridge.js +1 -1
  8. package/dist/esm/modules/excel/core/xlsx-io.browser.js +5 -9
  9. package/dist/esm/modules/excel/core/xlsx-io.js +1 -3
  10. package/dist/esm/modules/excel/core/xlsx-stream.js +3 -1
  11. package/dist/esm/modules/excel/stream/workbook-reader.browser.js +10 -10
  12. package/dist/esm/modules/excel/stream/workbook-reader.js +30 -6
  13. package/dist/esm/modules/stream/browser/collector.js +3 -5
  14. package/dist/esm/modules/stream/browser/compose.js +13 -228
  15. package/dist/esm/modules/stream/browser/duplex-pair.js +71 -0
  16. package/dist/esm/modules/stream/browser/factories.js +35 -217
  17. package/dist/esm/modules/stream/browser/pipeline.js +43 -478
  18. package/dist/esm/modules/stream/browser/utils.js +21 -247
  19. package/dist/esm/modules/stream/browser/web.js +25 -0
  20. package/dist/esm/modules/stream/buffered-stream.js +8 -6
  21. package/dist/esm/modules/stream/core/factories.js +166 -0
  22. package/dist/esm/modules/stream/core/pipeline-api.js +32 -0
  23. package/dist/esm/modules/stream/core/sink-adapter.js +94 -24
  24. package/dist/esm/modules/stream/core/stream-helpers.js +160 -0
  25. package/dist/esm/modules/stream/core/utils.js +0 -23
  26. package/dist/esm/modules/stream/core/web-conversions.js +31 -0
  27. package/dist/esm/modules/stream/core/web-pipeline.js +90 -0
  28. package/dist/esm/modules/stream/index.base.js +2 -2
  29. package/dist/esm/modules/stream/index.browser.js +13 -19
  30. package/dist/esm/modules/stream/index.js +6 -10
  31. package/dist/esm/modules/stream/kernel/classes.js +618 -0
  32. package/dist/esm/modules/stream/kernel/compose-impl.js +225 -0
  33. package/dist/esm/modules/stream/kernel/destroy.js +255 -0
  34. package/dist/esm/modules/stream/kernel/duplexify.js +355 -0
  35. package/dist/esm/modules/stream/kernel/end-of-stream.js +212 -0
  36. package/dist/esm/modules/stream/kernel/errors.js +215 -0
  37. package/dist/esm/modules/stream/kernel/from.js +202 -0
  38. package/dist/esm/modules/stream/kernel/legacy.js +35 -0
  39. package/dist/esm/modules/stream/kernel/operators.js +285 -0
  40. package/dist/esm/modules/stream/kernel/pipeline-impl.js +561 -0
  41. package/dist/esm/modules/stream/kernel/readable-impl.js +963 -0
  42. package/dist/esm/modules/stream/kernel/state.js +253 -0
  43. package/dist/esm/modules/stream/kernel/stream-utils.js +212 -0
  44. package/dist/esm/modules/stream/kernel/web-adapters.js +584 -0
  45. package/dist/esm/modules/stream/kernel/writable.js +651 -0
  46. package/dist/esm/modules/stream/node/collector.js +7 -1
  47. package/dist/esm/modules/stream/node/compose.js +21 -206
  48. package/dist/esm/modules/stream/node/factories.js +34 -238
  49. package/dist/esm/modules/stream/node/pipeline.js +40 -94
  50. package/dist/esm/modules/stream/node/utils.js +15 -239
  51. package/dist/esm/modules/stream/node/web.js +27 -0
  52. package/dist/esm/modules/stream/pull-stream.js +15 -9
  53. package/dist/esm/modules/word/writer/streaming-writer.js +3 -0
  54. package/dist/iife/THIRD_PARTY_NOTICES.md +34 -2
  55. package/dist/iife/documonster.archive.iife.min.js +4 -4
  56. package/dist/iife/documonster.csv.iife.min.js +19 -19
  57. package/dist/iife/documonster.draw.iife.min.js +1 -1
  58. package/dist/iife/documonster.excel.iife.min.js +50 -50
  59. package/dist/iife/documonster.formula.iife.min.js +1 -1
  60. package/dist/iife/documonster.markdown.iife.min.js +1 -1
  61. package/dist/iife/documonster.mermaid.iife.min.js +1 -1
  62. package/dist/iife/documonster.pdf.iife.min.js +1 -1
  63. package/dist/iife/documonster.stream.iife.min.js +2 -2
  64. package/dist/iife/documonster.word.iife.min.js +60 -60
  65. package/dist/iife/documonster.xml.iife.min.js +1 -1
  66. package/dist/types/modules/excel/core/xlsx-io.browser.d.ts +5 -9
  67. package/dist/types/modules/excel/core/xlsx-io.d.ts +1 -3
  68. package/dist/types/modules/excel/core/xlsx-stream.d.ts +3 -2
  69. package/dist/types/modules/excel/stream/workbook-reader.browser.d.ts +2 -1
  70. package/dist/types/modules/excel/stream/workbook-reader.d.ts +2 -1
  71. package/dist/types/modules/stream/browser/collector.d.ts +1 -1
  72. package/dist/types/modules/stream/browser/compose.d.ts +14 -15
  73. package/dist/types/modules/stream/browser/duplex-pair.d.ts +10 -0
  74. package/dist/types/modules/stream/browser/factories.d.ts +22 -79
  75. package/dist/types/modules/stream/browser/pipeline.d.ts +8 -40
  76. package/dist/types/modules/stream/browser/utils.d.ts +6 -47
  77. package/dist/types/modules/stream/browser/web.d.ts +18 -0
  78. package/dist/types/modules/stream/core/add-abort-signal.d.ts +2 -1
  79. package/dist/types/modules/stream/core/consumers.d.ts +1 -1
  80. package/dist/types/modules/stream/core/event-utils.d.ts +2 -1
  81. package/dist/types/modules/stream/core/factories.d.ts +129 -0
  82. package/dist/types/modules/stream/core/pipeline-api.d.ts +10 -0
  83. package/dist/types/modules/stream/core/sink-adapter.d.ts +18 -1
  84. package/dist/types/modules/stream/core/stream-helpers.d.ts +76 -0
  85. package/dist/types/modules/stream/core/utils.d.ts +0 -9
  86. package/dist/types/modules/stream/core/web-conversions.d.ts +68 -0
  87. package/dist/types/modules/stream/core/web-pipeline.d.ts +27 -0
  88. package/dist/types/modules/stream/index.base.d.ts +6 -4
  89. package/dist/types/modules/stream/index.browser.d.ts +13 -14
  90. package/dist/types/modules/stream/index.d.ts +7 -10
  91. package/dist/types/modules/stream/kernel/classes.d.ts +220 -0
  92. package/dist/types/modules/stream/kernel/compose-impl.d.ts +10 -0
  93. package/dist/types/modules/stream/kernel/destroy.d.ts +21 -0
  94. package/dist/types/modules/stream/kernel/duplexify.d.ts +31 -0
  95. package/dist/types/modules/stream/kernel/end-of-stream.d.ts +28 -0
  96. package/dist/types/modules/stream/kernel/errors.d.ts +42 -0
  97. package/dist/types/modules/stream/kernel/from.d.ts +17 -0
  98. package/dist/types/modules/stream/kernel/legacy.d.ts +20 -0
  99. package/dist/types/modules/stream/kernel/operators.d.ts +44 -0
  100. package/dist/types/modules/stream/kernel/pipeline-impl.d.ts +32 -0
  101. package/dist/types/modules/stream/kernel/readable-impl.d.ts +34 -0
  102. package/dist/types/modules/stream/kernel/state.d.ts +223 -0
  103. package/dist/types/modules/stream/kernel/stream-utils.d.ts +34 -0
  104. package/dist/types/modules/stream/kernel/web-adapters.d.ts +65 -0
  105. package/dist/types/modules/stream/kernel/writable.d.ts +107 -0
  106. package/dist/types/modules/stream/node/collector.d.ts +7 -2
  107. package/dist/types/modules/stream/node/compose.d.ts +31 -5
  108. package/dist/types/modules/stream/node/factories.d.ts +22 -85
  109. package/dist/types/modules/stream/node/pipeline.d.ts +4 -15
  110. package/dist/types/modules/stream/node/utils.d.ts +9 -49
  111. package/dist/types/modules/stream/node/web.d.ts +18 -0
  112. package/dist/types/modules/stream/pull-stream.d.ts +2 -2
  113. package/dist/types/modules/stream/types.d.ts +24 -6
  114. package/package.json +5 -3
  115. package/dist/esm/modules/stream/browser/_lazy.js +0 -30
  116. package/dist/esm/modules/stream/browser/chunk-buffer.js +0 -223
  117. package/dist/esm/modules/stream/browser/duplex.js +0 -979
  118. package/dist/esm/modules/stream/browser/helpers.js +0 -44
  119. package/dist/esm/modules/stream/browser/microtask-context.js +0 -60
  120. package/dist/esm/modules/stream/browser/passthrough.js +0 -16
  121. package/dist/esm/modules/stream/browser/pipe-manager.js +0 -161
  122. package/dist/esm/modules/stream/browser/readable.js +0 -2208
  123. package/dist/esm/modules/stream/browser/transform.js +0 -1241
  124. package/dist/esm/modules/stream/browser/writable.js +0 -1316
  125. package/dist/esm/modules/stream/core/end-args.js +0 -24
  126. package/dist/esm/modules/stream/node/writable.js +0 -125
  127. package/dist/esm/modules/stream/utils.base.js +0 -126
  128. package/dist/esm/modules/stream/utils.browser.js +0 -80
  129. package/dist/esm/modules/stream/utils.js +0 -81
  130. package/dist/types/modules/stream/browser/_lazy.d.ts +0 -20
  131. package/dist/types/modules/stream/browser/chunk-buffer.d.ts +0 -61
  132. package/dist/types/modules/stream/browser/duplex.d.ts +0 -299
  133. package/dist/types/modules/stream/browser/helpers.d.ts +0 -13
  134. package/dist/types/modules/stream/browser/microtask-context.d.ts +0 -44
  135. package/dist/types/modules/stream/browser/passthrough.d.ts +0 -11
  136. package/dist/types/modules/stream/browser/pipe-manager.d.ts +0 -38
  137. package/dist/types/modules/stream/browser/readable.d.ts +0 -379
  138. package/dist/types/modules/stream/browser/transform.d.ts +0 -314
  139. package/dist/types/modules/stream/browser/writable.d.ts +0 -238
  140. package/dist/types/modules/stream/core/end-args.d.ts +0 -20
  141. package/dist/types/modules/stream/node/writable.d.ts +0 -53
  142. package/dist/types/modules/stream/utils.base.d.ts +0 -63
  143. package/dist/types/modules/stream/utils.browser.d.ts +0 -23
  144. package/dist/types/modules/stream/utils.d.ts +0 -24
@@ -0,0 +1,618 @@
1
+ /**
2
+ * Stream kernel - the stream classes
3
+ *
4
+ * Ports of Node.js `Readable`, `Duplex`, `Transform` and `PassThrough`. They
5
+ * share one module because they depend on each other both ways:
6
+ * `Readable.prototype.compose` builds a `Duplex`, which is a `Readable`. Node
7
+ * resolves that with a lazy CommonJS `require`; here the classes sit together
8
+ * and hand themselves to `compose` / `pipeline` / `Duplex.from` as a
9
+ * `StreamKernel`, so the dependency is static and there is no registration a
10
+ * bundler could tree-shake away.
11
+ *
12
+ * The algorithms live in `readable-impl.ts` and `writable.ts`; these classes
13
+ * hold the public surface.
14
+ */
15
+ var _a;
16
+ import { composeImpl } from "./compose-impl.js";
17
+ import { construct, destroy, destroyer, errorOrDestroy, undestroy } from "./destroy.js";
18
+ import { duplexify } from "./duplexify.js";
19
+ import { eos } from "./end-of-stream.js";
20
+ import { createAbortError, errInvalidArgType, errMethodNotImplemented } from "./errors.js";
21
+ import { from } from "./from.js";
22
+ import { Stream } from "./legacy.js";
23
+ import * as operators from "./operators.js";
24
+ import { addChunkPushByteMode, addChunkPushObjectMode, addChunkUnshiftByteMode, addChunkUnshiftObjectMode, emitReadable, initReadable, onReadableConstructed, pipeImpl, readImpl, scheduleResume, streamToAsyncIterator, updateReadableListening } from "./readable-impl.js";
25
+ import { ReadableState, decoderEnd, decoderWrite, getHighWaterMark, kIsDuplex, nextTick, normalizeEncodingName } from "./state.js";
26
+ import { duplexFromWeb, duplexToWeb, readableFromWeb, readableToWeb } from "./web-adapters.js";
27
+ import { Writable, createWritableState, initWritable, onWritableConstructed } from "./writable.js";
28
+ import { createStreamDecoder } from "../../../utils/binary.js";
29
+ /**
30
+ * Type parameters default to `any`, as Node's own (non-generic) classes do, so
31
+ * code written for both builds type-checks the same; pass them to opt in.
32
+ */
33
+ export class Readable extends Stream {
34
+ constructor(options) {
35
+ super();
36
+ if (new.target[kIsDuplex]) {
37
+ // Duplex sets up both sides and runs one construct() for them.
38
+ this._readableState = new ReadableState(options, true);
39
+ return;
40
+ }
41
+ this._readableState = new ReadableState(options, false);
42
+ initReadable(this, options);
43
+ if (this._construct != null) {
44
+ construct(this, () => onReadableConstructed(this));
45
+ }
46
+ }
47
+ static from(iterable, options) {
48
+ return from(Readable, iterable, options);
49
+ }
50
+ /**
51
+ * Untyped, as Node declares it: what it yields depends on the mode (bytes by
52
+ * default, decoded strings with an `encoding`). The module's
53
+ * `readableFromWeb` types each case.
54
+ */
55
+ static fromWeb(readableStream, options) {
56
+ return readableFromWeb(Readable, readableStream, options, "node");
57
+ }
58
+ static toWeb(streamReadable, options) {
59
+ return readableToWeb(streamReadable, options, "node");
60
+ }
61
+ static wrap(src, options) {
62
+ return new Readable({
63
+ objectMode: src.readableObjectMode ?? src.objectMode ?? true,
64
+ ...options,
65
+ destroy(err, callback) {
66
+ destroyer(src, err);
67
+ callback(err);
68
+ }
69
+ }).wrap(src);
70
+ }
71
+ // ---------------------------------------------------------------------------
72
+ // Producer side
73
+ // ---------------------------------------------------------------------------
74
+ /**
75
+ * Add a chunk to the read buffer. Returns `false` once the buffer reaches
76
+ * `highWaterMark`; the producer should then wait for the next `_read()`.
77
+ */
78
+ push(chunk, encoding) {
79
+ const state = this._readableState;
80
+ return state.objectMode
81
+ ? addChunkPushObjectMode(this, state, chunk, encoding)
82
+ : addChunkPushByteMode(this, state, chunk, encoding);
83
+ }
84
+ /** Put a chunk back at the front of the read buffer. */
85
+ unshift(chunk, encoding) {
86
+ const state = this._readableState;
87
+ return state.objectMode
88
+ ? addChunkUnshiftObjectMode(this, state, chunk)
89
+ : addChunkUnshiftByteMode(this, state, chunk, encoding);
90
+ }
91
+ _read(_size) {
92
+ throw errMethodNotImplemented("_read()");
93
+ }
94
+ // ---------------------------------------------------------------------------
95
+ // Consumer side
96
+ // ---------------------------------------------------------------------------
97
+ read(n) {
98
+ return readImpl(this, n);
99
+ }
100
+ isPaused() {
101
+ const state = this._readableState;
102
+ return state.paused === true || state.flowing === false;
103
+ }
104
+ setEncoding(encoding) {
105
+ const state = this._readableState;
106
+ const decoder = createStreamDecoder(encoding);
107
+ state.decoder = decoder;
108
+ state.encoding = normalizeEncodingName(encoding);
109
+ // Re-decode what is already buffered so every later read is a string.
110
+ let content = "";
111
+ for (let i = state.bufferIndex; i < state.buffer.length; i++) {
112
+ const data = state.buffer[i];
113
+ content += typeof data === "string" ? data : decoderWrite(decoder, data);
114
+ }
115
+ if (state.ended) {
116
+ content += decoderEnd(decoder);
117
+ }
118
+ state.buffer.length = 0;
119
+ state.bufferIndex = 0;
120
+ if (content !== "") {
121
+ state.buffer.push(content);
122
+ }
123
+ state.length = content.length;
124
+ return this;
125
+ }
126
+ resume() {
127
+ const state = this._readableState;
128
+ if (state.destroyed) {
129
+ return this;
130
+ }
131
+ if (state.flowing !== true) {
132
+ // Flow only if nobody listens for 'readable'.
133
+ state.flowing = !state.readableListening;
134
+ scheduleResume(this, state);
135
+ }
136
+ state.paused = false;
137
+ return this;
138
+ }
139
+ pause() {
140
+ const state = this._readableState;
141
+ if (state.destroyed) {
142
+ return this;
143
+ }
144
+ if (state.flowing !== false) {
145
+ state.flowing = false;
146
+ this.emit("pause");
147
+ }
148
+ state.paused = true;
149
+ return this;
150
+ }
151
+ pipe(dest, pipeOpts) {
152
+ pipeImpl(this, dest, pipeOpts);
153
+ return dest;
154
+ }
155
+ unpipe(dest) {
156
+ const state = this._readableState;
157
+ if (state.pipes.length === 0) {
158
+ return this;
159
+ }
160
+ if (!dest) {
161
+ const dests = state.pipes;
162
+ state.pipes = [];
163
+ this.pause();
164
+ for (const d of dests) {
165
+ d.emit("unpipe", this, { hasUnpiped: false });
166
+ }
167
+ return this;
168
+ }
169
+ const index = state.pipes.indexOf(dest);
170
+ if (index === -1) {
171
+ return this;
172
+ }
173
+ state.pipes.splice(index, 1);
174
+ if (state.pipes.length === 0) {
175
+ this.pause();
176
+ }
177
+ dest.emit("unpipe", this, { hasUnpiped: false });
178
+ return this;
179
+ }
180
+ on(event, listener) {
181
+ Stream.prototype.on.call(this, event, listener);
182
+ const state = this._readableState;
183
+ if (event === "data") {
184
+ state.dataListening = true;
185
+ // Let resume() be a no-op below when someone listens for 'readable'.
186
+ state.readableListening = this.listenerCount("readable") > 0 || state.readableListening;
187
+ if (state.flowing !== false) {
188
+ this.resume();
189
+ }
190
+ }
191
+ else if (event === "readable") {
192
+ if (!state.endEmitted && !state.readableListening) {
193
+ state.readableListening = true;
194
+ state.needReadable = true;
195
+ state.flowing = false;
196
+ state.emittedReadable = false;
197
+ if (state.length) {
198
+ emitReadable(this);
199
+ }
200
+ else if (!state.reading) {
201
+ nextTick(() => this.read(0));
202
+ }
203
+ }
204
+ }
205
+ return this;
206
+ }
207
+ removeListener(event, listener) {
208
+ Stream.prototype.removeListener.call(this, event, listener);
209
+ const state = this._readableState;
210
+ if (event === "readable") {
211
+ // Deferred so a once('readable') → read() → once('readable') cycle keeps
212
+ // the stream paused rather than flipping into flowing mode in between.
213
+ nextTick(() => updateReadableListening(this));
214
+ }
215
+ else if (event === "data" && this.listenerCount("data") === 0) {
216
+ state.dataListening = false;
217
+ }
218
+ return this;
219
+ }
220
+ removeAllListeners(event) {
221
+ Stream.prototype.removeAllListeners.call(this, event);
222
+ if (event === "readable" || event === undefined) {
223
+ nextTick(() => updateReadableListening(this));
224
+ }
225
+ return this;
226
+ }
227
+ /** Adopt an old-style (`'data'` / `'end'` emitting) stream as this stream's source. */
228
+ wrap(stream) {
229
+ let paused = false;
230
+ stream.on("data", (chunk) => {
231
+ if (!this.push(chunk) && stream.pause) {
232
+ paused = true;
233
+ stream.pause();
234
+ }
235
+ });
236
+ stream.on("end", () => {
237
+ this.push(null);
238
+ });
239
+ stream.on("error", (err) => {
240
+ errorOrDestroy(this, err);
241
+ });
242
+ stream.on("close", () => {
243
+ this.destroy();
244
+ });
245
+ stream.on("destroy", () => {
246
+ this.destroy();
247
+ });
248
+ this._read = () => {
249
+ if (paused && stream.resume) {
250
+ paused = false;
251
+ stream.resume();
252
+ }
253
+ };
254
+ // Proxy the wrapped stream's other methods, as Node does.
255
+ for (const key of Object.keys(stream)) {
256
+ if (this[key] === undefined && typeof stream[key] === "function") {
257
+ this[key] = stream[key].bind(stream);
258
+ }
259
+ }
260
+ return this;
261
+ }
262
+ // ---------------------------------------------------------------------------
263
+ // Lifecycle
264
+ // ---------------------------------------------------------------------------
265
+ destroy(error, callback) {
266
+ destroy.call(this, error, callback);
267
+ return this;
268
+ }
269
+ _undestroy() {
270
+ undestroy.call(this);
271
+ }
272
+ _destroy(error, callback) {
273
+ callback(error);
274
+ }
275
+ // ---------------------------------------------------------------------------
276
+ // Async iteration and helpers
277
+ // ---------------------------------------------------------------------------
278
+ [Symbol.asyncIterator]() {
279
+ return streamToAsyncIterator(this, undefined, wrapLegacy);
280
+ }
281
+ iterator(options) {
282
+ if (options !== undefined && (options === null || typeof options !== "object")) {
283
+ throw errInvalidArgType("options", "Object", options);
284
+ }
285
+ return streamToAsyncIterator(this, options, wrapLegacy);
286
+ }
287
+ map(fn, options) {
288
+ return Readable.from(operators.map.call(this, fn, options));
289
+ }
290
+ filter(fn, options) {
291
+ return Readable.from(operators.filter.call(this, fn, options));
292
+ }
293
+ flatMap(fn, options) {
294
+ return Readable.from(operators.flatMap.call(this, fn, options));
295
+ }
296
+ drop(limit, options) {
297
+ return Readable.from(operators.drop.call(this, limit, options));
298
+ }
299
+ take(limit, options) {
300
+ return Readable.from(operators.take.call(this, limit, options));
301
+ }
302
+ forEach(fn, options) {
303
+ return operators.forEach.call(this, fn, options);
304
+ }
305
+ toArray(options) {
306
+ return operators.toArray.call(this, options);
307
+ }
308
+ some(fn, options) {
309
+ return operators.some.call(this, fn, options);
310
+ }
311
+ every(fn, options) {
312
+ return operators.every.call(this, fn, options);
313
+ }
314
+ find(fn, options) {
315
+ return operators.find.call(this, fn, options);
316
+ }
317
+ reduce(fn, ...rest) {
318
+ return operators.reduce.call(this, fn, ...rest);
319
+ }
320
+ compose(stream, options) {
321
+ if (options != null && typeof options !== "object") {
322
+ throw errInvalidArgType("options", "Object", options);
323
+ }
324
+ if (options?.signal != null && !(options.signal instanceof AbortSignal)) {
325
+ throw errInvalidArgType("options.signal", "AbortSignal", options.signal);
326
+ }
327
+ const composed = composeImpl(kernel, this, stream);
328
+ const signal = options?.signal;
329
+ if (signal) {
330
+ if (signal.aborted) {
331
+ composed.destroy(createAbortError(signal.reason));
332
+ }
333
+ else {
334
+ const onAbort = () => {
335
+ composed.destroy(createAbortError(signal.reason));
336
+ };
337
+ signal.addEventListener("abort", onAbort, { once: true });
338
+ eos(composed, () => signal.removeEventListener("abort", onAbort));
339
+ }
340
+ }
341
+ return composed;
342
+ }
343
+ // ---------------------------------------------------------------------------
344
+ // State accessors
345
+ // ---------------------------------------------------------------------------
346
+ get readable() {
347
+ const r = this._readableState;
348
+ // r.readable === false: the readable side of a Duplex was disabled.
349
+ return !!r && r.readable !== false && !r.destroyed && !r.errorEmitted && !r.endEmitted;
350
+ }
351
+ set readable(value) {
352
+ if (this._readableState) {
353
+ this._readableState.readable = !!value;
354
+ }
355
+ }
356
+ get readableDidRead() {
357
+ return this._readableState.dataEmitted;
358
+ }
359
+ get readableAborted() {
360
+ const r = this._readableState;
361
+ return !!(r.readable !== false && (r.destroyed || r.errored) && !r.endEmitted);
362
+ }
363
+ get readableHighWaterMark() {
364
+ return this._readableState.highWaterMark;
365
+ }
366
+ get readableBuffer() {
367
+ const r = this._readableState;
368
+ return r.buffer.slice(r.bufferIndex);
369
+ }
370
+ get readableFlowing() {
371
+ return this._readableState.flowing;
372
+ }
373
+ set readableFlowing(value) {
374
+ if (this._readableState) {
375
+ this._readableState.flowing = value;
376
+ }
377
+ }
378
+ get readableLength() {
379
+ return this._readableState.length;
380
+ }
381
+ get readableObjectMode() {
382
+ return this._readableState ? this._readableState.objectMode : false;
383
+ }
384
+ get readableEncoding() {
385
+ return this._readableState ? this._readableState.encoding : null;
386
+ }
387
+ get errored() {
388
+ return this._readableState ? this._readableState.errored : null;
389
+ }
390
+ get closed() {
391
+ return this._readableState ? this._readableState.closed : false;
392
+ }
393
+ get destroyed() {
394
+ return this._readableState ? this._readableState.destroyed : false;
395
+ }
396
+ set destroyed(value) {
397
+ if (this._readableState) {
398
+ this._readableState.destroyed = value;
399
+ }
400
+ }
401
+ get readableEnded() {
402
+ return this._readableState ? this._readableState.endEmitted : false;
403
+ }
404
+ }
405
+ Readable.prototype.addListener = Readable.prototype.on;
406
+ Readable.prototype.off = Readable.prototype.removeListener;
407
+ if (typeof Symbol.asyncDispose === "symbol") {
408
+ Object.defineProperty(Readable.prototype, Symbol.asyncDispose, {
409
+ configurable: true,
410
+ writable: true,
411
+ value: async function () {
412
+ let error = null;
413
+ if (!this.destroyed) {
414
+ error = this.readableEnded ? null : createAbortError();
415
+ this.destroy(error);
416
+ }
417
+ await new Promise((resolve, reject) => {
418
+ eos(this, err => (err && err !== error ? reject(err) : resolve()));
419
+ });
420
+ }
421
+ });
422
+ }
423
+ function wrapLegacy(legacy) {
424
+ return Readable.wrap(legacy, { objectMode: true });
425
+ }
426
+ // oxlint-disable-next-line typescript/no-unsafe-declaration-merging
427
+ export class Duplex extends Readable {
428
+ constructor(options) {
429
+ super(options);
430
+ this._writableState = createWritableState(this, options, true);
431
+ if (options) {
432
+ this.allowHalfOpen = options.allowHalfOpen !== false;
433
+ if (options.readable === false) {
434
+ this._readableState.readable = false;
435
+ this._readableState.ended = true;
436
+ this._readableState.endEmitted = true;
437
+ }
438
+ if (options.writable === false) {
439
+ this._writableState.writable = false;
440
+ this._writableState.ending = true;
441
+ this._writableState.ended = true;
442
+ this._writableState.finished = true;
443
+ }
444
+ initReadable(this, options);
445
+ initWritable(this, options);
446
+ }
447
+ else {
448
+ this.allowHalfOpen = true;
449
+ }
450
+ if (this._construct != null) {
451
+ construct(this, () => {
452
+ onReadableConstructed(this);
453
+ onWritableConstructed(this);
454
+ });
455
+ }
456
+ }
457
+ static from(body) {
458
+ return duplexify(kernel, body, "body");
459
+ }
460
+ static fromWeb(pair, options) {
461
+ return duplexFromWeb(Duplex, pair, options, "node");
462
+ }
463
+ static toWeb(duplex) {
464
+ return duplexToWeb(duplex, "node");
465
+ }
466
+ get destroyed() {
467
+ if (this._readableState === undefined || this._writableState === undefined) {
468
+ return false;
469
+ }
470
+ return this._readableState.destroyed && this._writableState.destroyed;
471
+ }
472
+ set destroyed(value) {
473
+ if (this._readableState && this._writableState) {
474
+ this._readableState.destroyed = value;
475
+ this._writableState.destroyed = value;
476
+ }
477
+ }
478
+ }
479
+ _a = kIsDuplex;
480
+ Duplex[_a] = true;
481
+ // The accessors Node's Duplex takes from Writable; `destroyed`, `closed` and
482
+ // `errored` stay Duplex/Readable's, and `writableAborted` is Writable-only.
483
+ const DUPLEX_WRITABLE_ACCESSORS = new Set([
484
+ "writable",
485
+ "writableHighWaterMark",
486
+ "writableObjectMode",
487
+ "writableBuffer",
488
+ "writableLength",
489
+ "writableFinished",
490
+ "writableCorked",
491
+ "writableEnded",
492
+ "writableNeedDrain"
493
+ ]);
494
+ // Install the writable half: the same function objects as Writable's, so a
495
+ // Duplex runs exactly the Writable algorithm on its own WritableState.
496
+ for (const key of Object.getOwnPropertyNames(Writable.prototype)) {
497
+ if (key === "constructor") {
498
+ continue;
499
+ }
500
+ const descriptor = Object.getOwnPropertyDescriptor(Writable.prototype, key);
501
+ if (descriptor.get || descriptor.set) {
502
+ if (DUPLEX_WRITABLE_ACCESSORS.has(key)) {
503
+ Object.defineProperty(Duplex.prototype, key, descriptor);
504
+ }
505
+ }
506
+ else if (!Duplex.prototype[key]) {
507
+ Object.defineProperty(Duplex.prototype, key, descriptor);
508
+ }
509
+ }
510
+ Duplex.prototype.destroy = Writable.prototype.destroy;
511
+ export class Transform extends Duplex {
512
+ constructor(options) {
513
+ // A Transform buffers on the readable side only; with a readable mark of 0
514
+ // the writable side must not buffer either, or data would sit there twice.
515
+ if (options) {
516
+ const readableHighWaterMark = getHighWaterMark(options, !!(options.objectMode || options.readableObjectMode), "readableHighWaterMark", true);
517
+ if (readableHighWaterMark === 0) {
518
+ options = {
519
+ ...options,
520
+ highWaterMark: undefined,
521
+ readableHighWaterMark,
522
+ writableHighWaterMark: options.writableHighWaterMark || 0
523
+ };
524
+ }
525
+ }
526
+ super(options);
527
+ // _read is implemented and nothing else precedes the first call.
528
+ this._readableState.sync = false;
529
+ this._transformCallback = null;
530
+ if (options) {
531
+ if (typeof options.transform === "function") {
532
+ this._transform = options.transform;
533
+ }
534
+ if (typeof options.flush === "function") {
535
+ this._flush = options.flush;
536
+ }
537
+ }
538
+ // Flush when the writable side finishes. Listening for 'prefinish' rather
539
+ // than relying on _final keeps subclasses that override _final working.
540
+ this.on("prefinish", prefinish);
541
+ }
542
+ _transform(_chunk, _encoding, _callback) {
543
+ throw errMethodNotImplemented("_transform()");
544
+ }
545
+ _final(cb) {
546
+ if (typeof this._flush === "function" && !this.destroyed) {
547
+ this._flush((er, data) => {
548
+ if (er) {
549
+ if (cb) {
550
+ cb(er);
551
+ }
552
+ else {
553
+ this.destroy(er);
554
+ }
555
+ return;
556
+ }
557
+ if (data != null) {
558
+ this.push(data);
559
+ }
560
+ this.push(null);
561
+ cb?.();
562
+ });
563
+ }
564
+ else {
565
+ this.push(null);
566
+ cb?.();
567
+ }
568
+ }
569
+ _write(chunk, encoding, callback) {
570
+ const rState = this._readableState;
571
+ const wState = this._writableState;
572
+ const length = rState.length;
573
+ this._transform(chunk, encoding, (err, val) => {
574
+ if (err) {
575
+ callback(err);
576
+ return;
577
+ }
578
+ if (val != null) {
579
+ this.push(val);
580
+ }
581
+ if (rState.ended) {
582
+ // push(null) happened: let that state settle before the next write.
583
+ nextTick(callback);
584
+ }
585
+ else if (wState.ended || length === rState.length || rState.length < rState.highWaterMark) {
586
+ callback();
587
+ }
588
+ else {
589
+ // The readable side is full: hold the write until it is read from.
590
+ this._transformCallback = callback;
591
+ }
592
+ });
593
+ }
594
+ _read(_size) {
595
+ if (this._transformCallback) {
596
+ const callback = this._transformCallback;
597
+ this._transformCallback = null;
598
+ callback();
599
+ }
600
+ }
601
+ }
602
+ function prefinish() {
603
+ if (this._final !== Transform.prototype._final) {
604
+ Transform.prototype._final.call(this);
605
+ }
606
+ }
607
+ // =============================================================================
608
+ // PassThrough
609
+ // =============================================================================
610
+ /** A Transform that hands every chunk on unchanged. */
611
+ export class PassThrough extends Transform {
612
+ _transform(chunk, _encoding, callback) {
613
+ callback(null, chunk);
614
+ }
615
+ }
616
+ /** The classes, for the algorithms that construct streams of their own. */
617
+ const kernel = { Readable, Writable, Duplex, PassThrough };
618
+ export { kernel };