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
@@ -1,379 +0,0 @@
1
- /**
2
- * Browser Stream - Readable
3
- */
4
- import type { IDuplex, ReadableStreamOptions, WritableLike } from "../types.js";
5
- import { EventEmitter } from "../../../utils/event-emitter.js";
6
- /**
7
- * A wrapper around Web ReadableStream that provides Node.js-like API
8
- */
9
- export declare class Readable<T = Uint8Array> extends EventEmitter {
10
- /**
11
- * Allow duck-typed instanceof checks.
12
- * Node.js Duplex passes `instanceof Readable` via prototype chain.
13
- * Our browser Duplex composes a Readable, so we use Symbol.hasInstance
14
- * to check for key Readable-like methods/properties.
15
- */
16
- static [Symbol.hasInstance](instance: unknown): boolean;
17
- private _stream;
18
- private _reader;
19
- private _buf;
20
- private _reading;
21
- private _ended;
22
- private _endEmitted;
23
- private _destroyed;
24
- private _errored;
25
- private _closed;
26
- private _flowing;
27
- private _resumeScheduled;
28
- private _hasFlowed;
29
- private _pipes;
30
- private _encoding;
31
- private _decoder;
32
- private _didRead;
33
- private _pushMode;
34
- private _webStreamMode;
35
- private _objectMode;
36
- private _highWaterMark;
37
- private _autoDestroy;
38
- private _emitClose;
39
- private _read?;
40
- private _hasReadImpl;
41
- private _constructFunc?;
42
- private _constructed;
43
- private _asyncIterState;
44
- constructor(options?: ReadableStreamOptions & {
45
- stream?: ReadableStream<T>;
46
- autoDestroy?: boolean;
47
- emitClose?: boolean;
48
- signal?: AbortSignal;
49
- encoding?: string;
50
- read?: (this: Readable<T>, size?: number) => void;
51
- destroy?: (this: Readable<T>, error: Error | null, callback: (error?: Error | null) => void) => void;
52
- construct?: (this: Readable<T>, callback: (error?: Error | null) => void) => void;
53
- });
54
- /**
55
- * Run _construct if provided (via options or subclass override).
56
- * Delays _read calls until the callback fires.
57
- */
58
- private _maybeConstruct;
59
- /**
60
- * Check if a subclass defines _construct on its own prototype.
61
- * Node.js does NOT have _construct on any stream prototype — it only exists
62
- * when provided via constructor options or defined by a subclass.
63
- */
64
- private _hasSubclassConstruct;
65
- /**
66
- * Check if a subclass defines _read on its own prototype.
67
- * The base Readable.prototype._read throws ERR_METHOD_NOT_IMPLEMENTED,
68
- * so we must stop before it. Only return true if an intermediate prototype
69
- * (the user's subclass) owns _read.
70
- */
71
- private _hasSubclassRead;
72
- /**
73
- * Wire up an AbortSignal to destroy this stream on abort.
74
- */
75
- private _setupAbortSignal;
76
- /**
77
- * Create a Readable from an iterable (static factory method)
78
- */
79
- static from<T>(iterable: Iterable<T> | AsyncIterable<T> | ReadableStream<T> | Blob, options?: ReadableStreamOptions): Readable<T>;
80
- /**
81
- * Check if a stream has been disturbed (read from).
82
- * Matches Node.js native: readableDidRead || readableAborted.
83
- * readableAborted = (destroyed || errored) && !endEmitted.
84
- */
85
- static isDisturbed(stream: Readable<any>): boolean;
86
- /**
87
- * Check if a stream is still readable (not destroyed, not ended).
88
- * Matches Node.js Readable.isReadable() (available since v21).
89
- * Returns null for non-stream inputs (matching Node.js behavior).
90
- */
91
- static isReadable(stream: unknown): boolean | null;
92
- /**
93
- * Convert a Web ReadableStream to Node.js Readable
94
- */
95
- static fromWeb<T>(webStream: ReadableStream<T>, options?: ReadableStreamOptions): Readable<T>;
96
- /**
97
- * Convert a Node.js Readable to Web ReadableStream
98
- */
99
- static toWeb<T>(nodeStream: Readable<T>): ReadableStream<T>;
100
- /**
101
- * Static wrap method - wraps an old-style stream into a Readable.
102
- * Matches Node.js Readable.wrap(stream, options).
103
- */
104
- static wrap<T>(src: any, options?: ReadableStreamOptions): Readable<T>;
105
- /**
106
- * Push data to the stream (when using controllable stream)
107
- */
108
- push(chunk: T | null, encoding?: string): boolean;
109
- private _emitEndOnce;
110
- /**
111
- * Put a chunk back at the front of the buffer
112
- */
113
- unshift(chunk: T, encoding?: string): void;
114
- /**
115
- * Safely invoke _read(), catching synchronous exceptions.
116
- * Node.js catches sync throws in _read and emits an error event, then
117
- * destroys the stream. We mirror that behaviour here.
118
- */
119
- private _callRead;
120
- /**
121
- * Read data from the stream.
122
- *
123
- * Node.js behavior:
124
- * - read() / read(undefined) — in object mode returns one object;
125
- * in binary mode returns all buffered data as one chunk
126
- * - read(0) — returns null, may trigger internal _read()
127
- * - read(n) — returns exactly n bytes (binary) or null if not enough;
128
- * in object mode returns one object (size ignored)
129
- */
130
- read(size?: number): T | null;
131
- /**
132
- * Flush the stream decoder's internal remainder and clear it.
133
- * Returns the flushed string, or null if nothing to flush.
134
- * Called when the stream ends, both from the event path (_emitEndOnce)
135
- * and the async iterator path (_initAsyncIterState).
136
- */
137
- private _flushDecoder;
138
- /**
139
- * Set encoding for string output.
140
- * Creates a private TextDecoder instance for streaming decode to avoid
141
- * sharing mutable state across concurrent streams.
142
- */
143
- setEncoding(encoding: string): this;
144
- private _applyEncoding;
145
- /**
146
- * Wrap an old-style stream
147
- */
148
- wrap(stream: any): this;
149
- /**
150
- * Pause the stream
151
- */
152
- pause(): this;
153
- /**
154
- * Resume the stream
155
- */
156
- resume(): this;
157
- /**
158
- * Override on() to automatically resume when 'data' listener is added
159
- * This matches Node.js behavior where adding a 'data' listener puts
160
- * the stream into flowing mode.
161
- */
162
- on(event: string | symbol, listener: (...args: any[]) => void): this;
163
- /**
164
- * Check if paused
165
- */
166
- isPaused(): boolean;
167
- /**
168
- * Pipe to a writable stream, transform stream, or duplex stream.
169
- * Accepts any writable-like object (duck-typed, matching Node.js behavior).
170
- */
171
- pipe<W extends WritableLike>(destination: W, options?: {
172
- end?: boolean;
173
- }): W;
174
- /**
175
- * Unpipe from destination
176
- */
177
- unpipe(destination?: WritableLike): this;
178
- /**
179
- * Destroy the stream
180
- */
181
- destroy(error?: Error): this;
182
- /**
183
- * Override in subclass to customise destroy behaviour.
184
- * Call `callback(err)` when cleanup is complete.
185
- */
186
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
187
- /**
188
- * Reverse the effects of destroy() so the stream can potentially be reused.
189
- * Matches Node.js _undestroy() which resets destroyed and closed flags.
190
- */
191
- _undestroy(): void;
192
- /** Check if _destroy has been overridden by a subclass or constructor option. */
193
- private _hasDestroyHook;
194
- private _readableOverride;
195
- get readable(): boolean;
196
- set readable(val: boolean);
197
- get readableEnded(): boolean;
198
- get readableLength(): number;
199
- /** Whether the stream has been destroyed */
200
- get destroyed(): boolean;
201
- set destroyed(val: boolean);
202
- /** The error that destroyed the stream, or null */
203
- get errored(): Error | null;
204
- /** Whether the stream has been closed */
205
- get closed(): boolean;
206
- /** Whether the stream is in flowing mode */
207
- get readableFlowing(): boolean | null;
208
- set readableFlowing(value: boolean | null);
209
- /** Whether the stream was aborted (destroyed or errored before 'end' was emitted) */
210
- get readableAborted(): boolean;
211
- /** Whether read() has ever been called */
212
- get readableDidRead(): boolean;
213
- /** Current encoding or null */
214
- get readableEncoding(): string | null;
215
- /** Returns array of objects containing info about buffered data */
216
- get readableObjectMode(): boolean;
217
- get readableHighWaterMark(): number;
218
- /**
219
- * Get the internal buffer contents as an array (matches Node.js BufferList behavior)
220
- */
221
- get readableBuffer(): T[];
222
- /**
223
- * Release the internal reader lock, clearing _reader.
224
- * Safe to call even when no reader is held.
225
- */
226
- private _releaseReader;
227
- private _startReading;
228
- /**
229
- * Async iterator support.
230
- *
231
- * Node.js parity: multiple calls to `[Symbol.asyncIterator]()` return
232
- * independent iterators that *compete* for chunks from the same underlying
233
- * stream. Each chunk is delivered to exactly one waiting iterator (FIFO).
234
- * A single shared `data` listener is attached on the first call; subsequent
235
- * calls reuse the same shared state.
236
- */
237
- [Symbol.asyncIterator](): AsyncIterableIterator<T>;
238
- private _chunkSizeForBackpressure;
239
- private _maybeResumeIterState;
240
- /**
241
- * Create and attach the shared async-iterator state.
242
- * A single `data` listener routes chunks to the first waiting resolver
243
- * (FIFO) or enqueues them. This matches Node.js semantics where multiple
244
- * iterators compete for the same data stream.
245
- */
246
- private _initAsyncIterState;
247
- /** Remove shared listeners and discard state. */
248
- private _teardownAsyncIterState;
249
- /**
250
- * Synchronous dispose — destroys the stream.
251
- * Matches Node.js Symbol.dispose support (v20+, experimental).
252
- */
253
- [Symbol.dispose](): void;
254
- /**
255
- * Async dispose hook for `await using`.
256
- * Destroys the stream and resolves after the 'close' event.
257
- */
258
- [Symbol.asyncDispose](): Promise<void>;
259
- /**
260
- * Explicit iterator method (same as Symbol.asyncIterator)
261
- */
262
- iterator(options?: {
263
- destroyOnReturn?: boolean;
264
- }): AsyncIterableIterator<T>;
265
- /**
266
- * Map each chunk through a function, returning a new Readable.
267
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
268
- */
269
- map<U>(fn: (data: T, options: {
270
- signal: AbortSignal;
271
- }) => U | Promise<U>, options?: {
272
- concurrency?: number;
273
- highWaterMark?: number;
274
- signal?: AbortSignal;
275
- }): Readable<U>;
276
- /**
277
- * Filter chunks by a predicate, returning a new Readable.
278
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
279
- */
280
- filter(fn: (data: T, options: {
281
- signal: AbortSignal;
282
- }) => boolean | Promise<boolean>, options?: {
283
- concurrency?: number;
284
- highWaterMark?: number;
285
- signal?: AbortSignal;
286
- }): Readable<T>;
287
- /**
288
- * Iterate all chunks. Returns a promise that resolves when the stream ends.
289
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
290
- */
291
- forEach(fn: (data: T, options: {
292
- signal: AbortSignal;
293
- }) => void | Promise<void>, options?: {
294
- concurrency?: number;
295
- signal?: AbortSignal;
296
- }): Promise<undefined>;
297
- /**
298
- * Collect all chunks into an array.
299
- */
300
- toArray(options?: {
301
- signal?: AbortSignal;
302
- }): Promise<T[]>;
303
- /**
304
- * Returns true if any chunk passes the predicate. Short-circuits on first match.
305
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
306
- */
307
- some(fn: (data: T, options: {
308
- signal: AbortSignal;
309
- }) => boolean | Promise<boolean>, options?: {
310
- concurrency?: number;
311
- signal?: AbortSignal;
312
- }): Promise<boolean>;
313
- /**
314
- * Find the first chunk matching the predicate. Short-circuits on match.
315
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
316
- */
317
- find(fn: (data: T, options: {
318
- signal: AbortSignal;
319
- }) => boolean | Promise<boolean>, options?: {
320
- concurrency?: number;
321
- signal?: AbortSignal;
322
- }): Promise<T | undefined>;
323
- /**
324
- * Returns true if all chunks pass the predicate. Short-circuits on first failure.
325
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
326
- */
327
- every(fn: (data: T, options: {
328
- signal: AbortSignal;
329
- }) => boolean | Promise<boolean>, options?: {
330
- concurrency?: number;
331
- signal?: AbortSignal;
332
- }): Promise<boolean>;
333
- /**
334
- * Map each chunk to multiple outputs (flattening), returning a new Readable.
335
- * Supports concurrent execution via `options.concurrency` (matching Node.js).
336
- */
337
- flatMap<U>(fn: (data: T, options: {
338
- signal: AbortSignal;
339
- }) => Iterable<U> | AsyncIterable<U> | Readable<U> | Promise<Iterable<U> | AsyncIterable<U>>, options?: {
340
- concurrency?: number;
341
- signal?: AbortSignal;
342
- }): Readable<U>;
343
- /**
344
- * Skip the first `limit` chunks, returning a new Readable.
345
- */
346
- drop(limit: number, options?: {
347
- signal?: AbortSignal;
348
- }): Readable<T>;
349
- /**
350
- * Take only the first `limit` chunks, returning a new Readable.
351
- */
352
- take(limit: number, options?: {
353
- signal?: AbortSignal;
354
- }): Readable<T>;
355
- /**
356
- * Reduce the stream to a single value.
357
- */
358
- reduce<U = T>(fn: (previous: U, data: T, options: {
359
- signal: AbortSignal;
360
- }) => U | Promise<U>, initial?: U, options?: {
361
- signal?: AbortSignal;
362
- }): Promise<U>;
363
- /**
364
- * Returns a new readable containing [index, chunk] pairs.
365
- * Matches Node.js Readable.prototype.asIndexedPairs() (experimental).
366
- */
367
- asIndexedPairs(options?: {
368
- signal?: AbortSignal;
369
- }): Readable<[number, T]>;
370
- /**
371
- * Compose this readable with a stream/transform, returning a Duplex.
372
- * Matches Node.js behavior where compose() returns a Duplex.
373
- */
374
- compose<U>(stream: WritableLike | ((source: AsyncIterable<T>) => AsyncIterable<U>), _options?: {
375
- signal?: AbortSignal;
376
- }): IDuplex<U, T>;
377
- }
378
- export declare function toAsyncIterable<T>(iterable: Iterable<T> | AsyncIterable<T>): AsyncIterable<T>;
379
- export declare function pumpAsyncIterableToReadable<T>(readable: Readable<T>, iterable: AsyncIterable<T>): void;
@@ -1,314 +0,0 @@
1
- /**
2
- * Browser Stream - Transform
3
- */
4
- import { Duplex } from "./duplex.js";
5
- import { Readable } from "./readable.js";
6
- import { Writable } from "./writable.js";
7
- import type { DuplexStreamOptions, IDuplex, WritableLike } from "../types.js";
8
- import { EventEmitter } from "../../../utils/event-emitter.js";
9
- /**
10
- * A wrapper around Web TransformStream that provides Node.js-like API
11
- */
12
- export declare class Transform<TInput = Uint8Array, TOutput = Uint8Array> extends EventEmitter {
13
- /**
14
- * Allow duck-typed instanceof checks.
15
- * Makes `transform instanceof Transform` return true, and also
16
- * `transform instanceof Duplex` via Duplex's own Symbol.hasInstance.
17
- */
18
- static [Symbol.hasInstance](instance: unknown): boolean;
19
- allowHalfOpen: boolean;
20
- private _destroyed;
21
- private _closed;
22
- private _ended;
23
- private _errored;
24
- private _dataForwardingSetup;
25
- private _emitClose;
26
- private _autoDestroy;
27
- private _endGeneration;
28
- private _endCallback;
29
- private _webStream;
30
- private _sideForwardingCleanup;
31
- private _constructFunc?;
32
- /** Cached result of _hasSubclassTransform (called per-chunk, so worth caching) */
33
- private _isSubclassTransform;
34
- /**
35
- * Deferred write callback, stored when the readable buffer is full (backpressure).
36
- * Released when the internal readable's _read() is called (i.e. when the consumer
37
- * pulls data), matching Node.js Transform's kCallback mechanism.
38
- */
39
- private _afterTransformCallback;
40
- private _transformImpl;
41
- private _flushImpl;
42
- /**
43
- * Push data to the readable side (Node.js compatibility).
44
- * Intended to be called from within transform/flush.
45
- */
46
- push(chunk: TOutput | null, encoding?: string): boolean;
47
- constructor(options?: DuplexStreamOptions & {
48
- emitClose?: boolean;
49
- autoDestroy?: boolean;
50
- encoding?: string;
51
- decodeStrings?: boolean;
52
- defaultEncoding?: string;
53
- signal?: AbortSignal;
54
- transform?: ((chunk: TInput) => TOutput | Promise<TOutput>) | ((this: Transform<TInput, TOutput>, chunk: TInput, encoding: string, callback: (error?: Error | null, data?: TOutput) => void) => void);
55
- flush?: (() => TOutput | void | Promise<TOutput | void>) | ((this: Transform<TInput, TOutput>, callback: (error?: Error | null, data?: TOutput) => void) => void);
56
- write?: (this: Transform<TInput, TOutput>, chunk: TInput, encoding: string, callback: (error?: Error | null) => void) => void;
57
- writev?: (this: Transform<TInput, TOutput>, chunks: Array<{
58
- chunk: TInput;
59
- encoding: string;
60
- }>, callback: (error?: Error | null) => void) => void;
61
- final?: (this: Transform<TInput, TOutput>, callback: (error?: Error | null) => void) => void;
62
- destroy?: (this: Transform<TInput, TOutput>, error: Error | null, callback: (error?: Error | null) => void) => void;
63
- construct?: (this: Transform<TInput, TOutput>, callback: (error?: Error | null) => void) => void;
64
- });
65
- private _setupAbortSignal;
66
- private _setupSideForwarding;
67
- private _scheduleEnd;
68
- private _emitErrorOnce;
69
- private _hasSubclassTransform;
70
- private _hasSubclassFlush;
71
- /**
72
- * Run the transform function. Returns `undefined` when the transform
73
- * completed synchronously, or a `Promise<void>` when it is async.
74
- * Keeping the sync path truly synchronous is critical so that the Writable
75
- * write-queue callback fires synchronously and _scheduleEnd cannot race
76
- * ahead of writes added during 'data' callbacks.
77
- */
78
- private _runTransformSync;
79
- private _runFlush;
80
- /**
81
- * Override on() to lazily forward readable 'data' events.
82
- * Avoids starting flowing mode unless requested.
83
- */
84
- on(event: string | symbol, listener: (...args: any[]) => void): this;
85
- /**
86
- * Write to the writable side
87
- */
88
- write(chunk: TInput, callback?: (error?: Error | null) => void): boolean;
89
- write(chunk: TInput, encoding?: string, callback?: (error?: Error | null) => void): boolean;
90
- /**
91
- * End the transform stream.
92
- * Defers closing via _scheduleEnd to allow writes triggered during
93
- * 'data' callbacks to complete before the writable side is ended.
94
- */
95
- end(callback?: () => void): this;
96
- end(chunk: TInput, callback?: () => void): this;
97
- end(chunk: TInput, encoding?: string, callback?: () => void): this;
98
- /**
99
- * Read from the transform stream.
100
- * Backpressure release is handled by _read() on the internal readable,
101
- * which is called automatically by the Readable when it needs more data.
102
- */
103
- read(size?: number): TOutput | null;
104
- /**
105
- * Pipe readable side to destination.
106
- * Accepts any writable-like object (duck-typed, matching Node.js behavior).
107
- */
108
- pipe<W extends WritableLike>(destination: W, options?: {
109
- end?: boolean;
110
- }): W;
111
- /**
112
- * Unpipe from destination
113
- */
114
- unpipe(destination?: WritableLike): this;
115
- /**
116
- * Check if paused
117
- */
118
- isPaused(): boolean;
119
- /**
120
- * Resume reading from the readable side
121
- */
122
- resume(): this;
123
- /**
124
- * Pause reading from the readable side
125
- */
126
- pause(): this;
127
- /**
128
- * Destroy the stream
129
- */
130
- destroy(error?: Error): this;
131
- /**
132
- * Override in subclass to customise destroy behaviour.
133
- * Call `callback(err)` when cleanup is complete.
134
- */
135
- _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
136
- /**
137
- * Reverse the effects of destroy() so the stream can potentially be reused.
138
- * Matches Node.js _undestroy() which resets destroyed and closed flags.
139
- */
140
- _undestroy(): void;
141
- /** Check if _destroy has been overridden by a subclass or constructor option. */
142
- private _hasDestroyHook;
143
- /**
144
- * Check if a subclass defines _construct on its own prototype.
145
- * Node.js does NOT have _construct on any stream prototype — it only exists
146
- * when provided via constructor options or defined by a subclass.
147
- */
148
- private _hasConstructHook;
149
- /**
150
- * Synchronous dispose — destroys the stream.
151
- * Matches Node.js Symbol.dispose support (v20+, experimental).
152
- */
153
- [Symbol.dispose](): void;
154
- /**
155
- * Async dispose support (using await).
156
- * Destroys the stream and resolves after the 'close' event.
157
- */
158
- [Symbol.asyncDispose](): Promise<void>;
159
- get readable(): boolean;
160
- set readable(val: boolean);
161
- get writable(): boolean;
162
- set writable(val: boolean);
163
- get readableEnded(): boolean;
164
- get writableEnded(): boolean;
165
- get writableFinished(): boolean;
166
- get readableLength(): number;
167
- get writableLength(): number;
168
- get readableHighWaterMark(): number;
169
- get writableHighWaterMark(): number;
170
- get readableObjectMode(): boolean;
171
- get readableFlowing(): boolean | null;
172
- get destroyed(): boolean;
173
- set destroyed(val: boolean);
174
- /**
175
- * Cork the writable side
176
- */
177
- cork(): void;
178
- /**
179
- * Uncork the writable side
180
- */
181
- uncork(): void;
182
- /**
183
- * Set encoding for the readable side
184
- */
185
- setEncoding(encoding: string): this;
186
- /**
187
- * Set default encoding for the writable side
188
- */
189
- setDefaultEncoding(encoding: string): this;
190
- /**
191
- * Put a chunk back at the front of the readable buffer
192
- */
193
- unshift(chunk: TOutput, encoding?: string): void;
194
- /**
195
- * Wrap a legacy stream
196
- */
197
- wrap(stream: any): this;
198
- /**
199
- * Create an async iterator with options
200
- */
201
- iterator(options?: {
202
- destroyOnReturn?: boolean;
203
- }): AsyncIterableIterator<TOutput>;
204
- get writableCorked(): number;
205
- get writableNeedDrain(): boolean;
206
- get writableObjectMode(): boolean;
207
- get readableAborted(): boolean;
208
- get readableDidRead(): boolean;
209
- get readableEncoding(): string | null;
210
- get errored(): Error | null;
211
- get closed(): boolean;
212
- get readableBuffer(): TOutput[];
213
- get writableBuffer(): TInput[];
214
- /**
215
- * Async iterator support
216
- */
217
- [Symbol.asyncIterator](): AsyncIterableIterator<TOutput>;
218
- map<U>(fn: (data: TOutput, options: {
219
- signal: AbortSignal;
220
- }) => U | Promise<U>, options?: {
221
- concurrency?: number;
222
- highWaterMark?: number;
223
- signal?: AbortSignal;
224
- }): Readable<U>;
225
- filter(fn: (data: TOutput, options: {
226
- signal: AbortSignal;
227
- }) => boolean | Promise<boolean>, options?: {
228
- concurrency?: number;
229
- highWaterMark?: number;
230
- signal?: AbortSignal;
231
- }): Readable<TOutput>;
232
- forEach(fn: (data: TOutput, options: {
233
- signal: AbortSignal;
234
- }) => void | Promise<void>, options?: {
235
- concurrency?: number;
236
- signal?: AbortSignal;
237
- }): Promise<undefined>;
238
- toArray(options?: {
239
- signal?: AbortSignal;
240
- }): Promise<TOutput[]>;
241
- some(fn: (data: TOutput, options: {
242
- signal: AbortSignal;
243
- }) => boolean | Promise<boolean>, options?: {
244
- concurrency?: number;
245
- signal?: AbortSignal;
246
- }): Promise<boolean>;
247
- find(fn: (data: TOutput, options: {
248
- signal: AbortSignal;
249
- }) => boolean | Promise<boolean>, options?: {
250
- concurrency?: number;
251
- signal?: AbortSignal;
252
- }): Promise<TOutput | undefined>;
253
- every(fn: (data: TOutput, options: {
254
- signal: AbortSignal;
255
- }) => boolean | Promise<boolean>, options?: {
256
- concurrency?: number;
257
- signal?: AbortSignal;
258
- }): Promise<boolean>;
259
- flatMap<U>(fn: (data: TOutput, options: {
260
- signal: AbortSignal;
261
- }) => Iterable<U> | AsyncIterable<U> | Readable<U> | Promise<Iterable<U> | AsyncIterable<U>>, options?: {
262
- concurrency?: number;
263
- signal?: AbortSignal;
264
- }): Readable<U>;
265
- drop(limit: number, options?: {
266
- signal?: AbortSignal;
267
- }): Readable<TOutput>;
268
- take(limit: number, options?: {
269
- signal?: AbortSignal;
270
- }): Readable<TOutput>;
271
- reduce<U = TOutput>(fn: (previous: U, data: TOutput, options: {
272
- signal: AbortSignal;
273
- }) => U | Promise<U>, initial?: U, options?: {
274
- signal?: AbortSignal;
275
- }): Promise<U>;
276
- compose<U>(stream: WritableLike | ((source: AsyncIterable<TOutput>) => AsyncIterable<U>), options?: {
277
- signal?: AbortSignal;
278
- }): IDuplex<U, TOutput>;
279
- /**
280
- * Check if a stream has been disturbed (data read or piped).
281
- * Delegates to Readable.isDisturbed, checking internal _readable for Duplex/Transform.
282
- */
283
- static isDisturbed(stream: unknown): boolean;
284
- /**
285
- * Create a Transform from various sources (delegates to Duplex.from).
286
- * Matches Node.js where Transform inherits static from() from Duplex.
287
- */
288
- static from<TIn = Uint8Array, TOut = Uint8Array>(source: AsyncIterable<TIn> | Iterable<TIn> | {
289
- readable?: Readable<TIn>;
290
- writable?: Writable<TOut>;
291
- }): Duplex<TIn, TOut>;
292
- /**
293
- * Convert a Web TransformStream to Node.js Transform
294
- */
295
- static fromWeb<TIn = Uint8Array, TOut = Uint8Array>(webStream: TransformStream<TIn, TOut>, options?: DuplexStreamOptions): Transform<TIn, TOut>;
296
- /**
297
- * Convert a Node.js Transform to Web TransformStream
298
- */
299
- static toWeb<TIn = Uint8Array, TOut = Uint8Array>(nodeStream: Transform<TIn, TOut>): TransformStream<TIn, TOut>;
300
- /**
301
- * Base transform method - can be overridden by subclasses.
302
- * Default behavior: throw ERR_METHOD_NOT_IMPLEMENTED (matches Node.js).
303
- * Node.js throws synchronously rather than calling callback(err).
304
- */
305
- _transform(_chunk: TInput, _encoding: string, _callback: (error?: Error | null, data?: TOutput) => void): void;
306
- /**
307
- * Base final method - matches Node.js Transform.prototype._final.
308
- * In Node.js this calls _flush (if defined), pushes null, and calls cb.
309
- * In our browser implementation, the actual final logic is handled by
310
- * the finalHandler passed to the internal Writable, so this method
311
- * exists primarily for API surface parity and subclass override detection.
312
- */
313
- _final(callback: (error?: Error | null) => void): void;
314
- }