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,24 +0,0 @@
1
- /**
2
- * Stream common - end() argument parsing
3
- *
4
- * Extracts the optional chunk and callback from the overloaded end() signature.
5
- * Shared by browser Writable, Transform, and Duplex.
6
- */
7
- /**
8
- * Parse the overloaded `end()` arguments into a normalised form.
9
- *
10
- * Supports the three standard overload shapes:
11
- * end(callback?)
12
- * end(chunk, callback?)
13
- * end(chunk, encoding?, callback?)
14
- */
15
- export function parseEndArgs(chunkOrCallback, encodingOrCallback, callback) {
16
- const chunk = typeof chunkOrCallback === "function" ? undefined : chunkOrCallback;
17
- const encoding = typeof encodingOrCallback === "string" ? encodingOrCallback : undefined;
18
- const cb = typeof chunkOrCallback === "function"
19
- ? chunkOrCallback
20
- : typeof encodingOrCallback === "function"
21
- ? encodingOrCallback
22
- : callback;
23
- return { chunk, encoding, cb };
24
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * Node.js Stream - Writable
3
- *
4
- * Extended Writable class with browser-compatible API.
5
- */
6
- import { Writable as NodeWritable } from "stream";
7
- import { getDefaultHighWaterMark } from "../core/utils.js";
8
- /**
9
- * Unified Writable class - wraps Node.js Writable with browser-compatible API
10
- *
11
- * Supports the same `{ stream }` option as browser version for wrapping existing streams.
12
- */
13
- export class Writable extends NodeWritable {
14
- /**
15
- * Duck-typing check so that native Duplex/Transform (which extend native
16
- * stream.Writable, not our wrapper) pass `instanceof Writable`.
17
- */
18
- static [Symbol.hasInstance](instance) {
19
- return instance instanceof NodeWritable;
20
- }
21
- constructor(options) {
22
- // If wrapping an existing stream, proxy to it
23
- if (options?.stream) {
24
- const underlying = options.stream;
25
- // Create a pass-through wrapper that proxies to the underlying stream
26
- super({
27
- highWaterMark: options?.highWaterMark ?? getDefaultHighWaterMark(options?.objectMode ?? false),
28
- objectMode: options?.objectMode,
29
- autoDestroy: options?.autoDestroy,
30
- emitClose: options?.emitClose,
31
- decodeStrings: options?.decodeStrings,
32
- defaultEncoding: options?.defaultEncoding,
33
- signal: options?.signal,
34
- write(chunk, encoding, callback) {
35
- underlying.write(chunk, encoding, callback);
36
- },
37
- final(callback) {
38
- underlying.end(callback);
39
- }
40
- });
41
- // Proxy events from underlying stream, but ensure we clean up listeners so
42
- // the underlying stream cannot retain this wrapper longer than necessary.
43
- const onUnderlyingError = (err) => {
44
- this.emit("error", err);
45
- };
46
- const onUnderlyingClose = () => {
47
- this.emit("close");
48
- };
49
- const cleanup = () => {
50
- underlying.off("error", onUnderlyingError);
51
- underlying.off("close", onUnderlyingClose);
52
- };
53
- underlying.on("error", onUnderlyingError);
54
- underlying.on("close", onUnderlyingClose);
55
- this.once("close", cleanup);
56
- this.once("finish", cleanup);
57
- }
58
- else {
59
- super({
60
- highWaterMark: options?.highWaterMark ?? getDefaultHighWaterMark(options?.objectMode ?? false),
61
- objectMode: options?.objectMode,
62
- autoDestroy: options?.autoDestroy,
63
- emitClose: options?.emitClose,
64
- decodeStrings: options?.decodeStrings,
65
- defaultEncoding: options?.defaultEncoding,
66
- signal: options?.signal,
67
- write: options?.write,
68
- writev: options?.writev,
69
- final: options?.final,
70
- destroy: options?.destroy,
71
- construct: options?.construct
72
- });
73
- }
74
- }
75
- }
76
- // =============================================================================
77
- // Cross-environment stream normalization
78
- // =============================================================================
79
- /**
80
- * Normalize a user-provided writable into a Node.js-compatible Writable.
81
- *
82
- * This keeps Web/Node branching at the stream-module boundary.
83
- *
84
- * A Node `Writable` is accepted (and fast-pathed below) — it satisfies the
85
- * structural {@link WritableLike}, so the signature does not name Node's class.
86
- * Naming it made the browser variant's declaration require `@types/node`, and
87
- * the two platforms' signatures must stay identical (see
88
- * `excel/__tests__/type/stream-api-parity.typecheck.ts`).
89
- */
90
- export function toWritable(stream) {
91
- if (stream instanceof Writable) {
92
- return stream;
93
- }
94
- // Node.js Writable: already compatible, avoid extra wrapper allocation.
95
- if (stream instanceof NodeWritable) {
96
- return stream;
97
- }
98
- // Web WritableStream: detect by getWriter() (avoid relying on global WritableStream).
99
- // Avoid `Writable.fromWeb()` — it is buggy on some runtimes (e.g. Bun).
100
- // Instead, wrap manually by piping through the WritableStream's writer.
101
- if (stream.getWriter) {
102
- const ws = stream;
103
- let writer;
104
- const getWriter = () => (writer ?? (writer = ws.getWriter()));
105
- return new Writable({
106
- write(_chunk, _encoding, callback) {
107
- getWriter()
108
- .write(_chunk)
109
- .then(() => callback(null), callback);
110
- },
111
- final(callback) {
112
- const w = getWriter();
113
- w.close().then(() => {
114
- w.releaseLock();
115
- callback(null);
116
- }, (err) => {
117
- w.releaseLock();
118
- callback(err);
119
- });
120
- }
121
- });
122
- }
123
- // Assume it structurally matches Node's Writable.
124
- return stream;
125
- }
@@ -1,126 +0,0 @@
1
- /**
2
- * Stream Utilities (shared base)
3
- *
4
- * Platform-independent helpers re-exported by both `utils.ts` (Node) and
5
- * `utils.browser.ts`. The two platform files supply the concrete
6
- * `createReadableFromArray`, `createTransform` and `consumers` bindings.
7
- */
8
- import { isReadableStream } from "./core/type-guards.js";
9
- import { stringToUint8Array as _stringToUint8Array } from "../../utils/binary.js";
10
- // =============================================================================
11
- // High-Level Stream Consumers
12
- // =============================================================================
13
- export async function collect(stream) {
14
- const result = [];
15
- for await (const chunk of stream) {
16
- result.push(chunk);
17
- }
18
- return result;
19
- }
20
- export function createText(deps) {
21
- return async function text(stream) {
22
- return deps.consumers.text(stream);
23
- };
24
- }
25
- export function createJson(deps) {
26
- return async function json(stream) {
27
- return deps.consumers.json(stream);
28
- };
29
- }
30
- export function createBytes(deps) {
31
- return async function bytes(stream) {
32
- return deps.consumers.buffer(stream);
33
- };
34
- }
35
- // =============================================================================
36
- // Stream Factory Helpers
37
- // =============================================================================
38
- export function createFromString(deps) {
39
- return function fromString(str) {
40
- return deps.createReadableFromArray([_stringToUint8Array(str)], {
41
- objectMode: false
42
- });
43
- };
44
- }
45
- export function createFromJSON(deps) {
46
- const fromString = createFromString(deps);
47
- return function fromJSON(data) {
48
- return fromString(JSON.stringify(data));
49
- };
50
- }
51
- export function createFromBytes(deps) {
52
- return function fromBytes(data) {
53
- return deps.createReadableFromArray([data], { objectMode: false });
54
- };
55
- }
56
- export function createTransformHelper(deps) {
57
- return function transform(fn) {
58
- return deps.createTransform(fn);
59
- };
60
- }
61
- export function createFilter(deps) {
62
- return function filter(predicate) {
63
- return deps.createTransform(async (chunk) => {
64
- if (await predicate(chunk)) {
65
- return chunk;
66
- }
67
- return undefined;
68
- }, { objectMode: true });
69
- };
70
- }
71
- // =============================================================================
72
- // ReadableStream Conversion
73
- // =============================================================================
74
- /**
75
- * Type guard for browser ReadableStream-like objects.
76
- * Re-exported from internal/type-guards for public API compatibility.
77
- *
78
- * Boundary: the reader's chunk type is erased here — callers of
79
- * `readableStreamToAsyncIterable` re-assert the element type via its generic.
80
- */
81
- export const isReadableStreamLike = isReadableStream;
82
- /**
83
- * Convert a browser ReadableStream to an AsyncIterable.
84
- * This is useful for consuming fetch response bodies in a streaming fashion.
85
- *
86
- * @example
87
- * ```ts
88
- * const response = await fetch(url);
89
- * for await (const chunk of readableStreamToAsyncIterable(response.body)) {
90
- * // process chunk
91
- * }
92
- * ```
93
- */
94
- export async function* readableStreamToAsyncIterable(stream) {
95
- const reader = stream.getReader();
96
- try {
97
- while (true) {
98
- const result = await reader.read();
99
- if (result.done) {
100
- return;
101
- }
102
- // Only yield defined, non-null values — avoids silently dropping
103
- // falsy-but-valid values like 0 or "".
104
- if (result.value !== undefined && result.value !== null) {
105
- yield result.value;
106
- }
107
- }
108
- }
109
- finally {
110
- // Cancel the reader before releasing the lock so the underlying stream
111
- // can free resources (e.g. a fetch body). Without cancel(), the stream
112
- // stays in a "disturbed but not cancelled" state per the WHATWG spec.
113
- try {
114
- await reader.cancel?.();
115
- }
116
- catch {
117
- // ignore
118
- }
119
- try {
120
- reader.releaseLock?.();
121
- }
122
- catch {
123
- // ignore
124
- }
125
- }
126
- }
@@ -1,80 +0,0 @@
1
- /**
2
- * Stream Utilities (browser)
3
- *
4
- * Browser counterpart of `utils.ts`, selected automatically
5
- * by the `preferBrowserFilesPlugin()` mechanism.
6
- *
7
- * All factory-produced helpers are lazily initialized on first call to avoid
8
- * eagerly pulling in heavy stream class dependencies at import time.
9
- */
10
- import { createReadableFromArray, createTransform } from "./browser/factories.js";
11
- import { consumers } from "./browser/utils.js";
12
- import { collect, createText, createJson, createBytes, createFromString, createFromJSON, createFromBytes, createTransformHelper, createFilter, isReadableStreamLike, readableStreamToAsyncIterable } from "./utils.base.js";
13
- let _deps = null;
14
- function getDeps() {
15
- if (!_deps) {
16
- _deps = {
17
- createReadableFromArray,
18
- createTransform: createTransform,
19
- consumers
20
- };
21
- }
22
- return _deps;
23
- }
24
- export { collect, isReadableStreamLike, readableStreamToAsyncIterable };
25
- let _text;
26
- export function text(stream) {
27
- if (!_text) {
28
- _text = createText(getDeps());
29
- }
30
- return _text(stream);
31
- }
32
- let _json;
33
- export function json(stream) {
34
- if (!_json) {
35
- _json = createJson(getDeps());
36
- }
37
- return _json(stream);
38
- }
39
- let _bytes;
40
- export function bytes(stream) {
41
- if (!_bytes) {
42
- _bytes = createBytes(getDeps());
43
- }
44
- return _bytes(stream);
45
- }
46
- let _fromString;
47
- export function fromString(str) {
48
- if (!_fromString) {
49
- _fromString = createFromString(getDeps());
50
- }
51
- return _fromString(str);
52
- }
53
- let _fromJSON;
54
- export function fromJSON(data) {
55
- if (!_fromJSON) {
56
- _fromJSON = createFromJSON(getDeps());
57
- }
58
- return _fromJSON(data);
59
- }
60
- let _fromBytes;
61
- export function fromBytes(data) {
62
- if (!_fromBytes) {
63
- _fromBytes = createFromBytes(getDeps());
64
- }
65
- return _fromBytes(data);
66
- }
67
- let _transform;
68
- export function transform(fn) {
69
- if (!_transform) {
70
- _transform = createTransformHelper(getDeps());
71
- }
72
- return _transform(fn);
73
- }
74
- let _filter;
75
- export function filter(predicate) {
76
- if (!_filter) {
77
- _filter = createFilter(getDeps());
78
- }
79
- return _filter(predicate);
80
- }
@@ -1,81 +0,0 @@
1
- /**
2
- * Stream Utilities
3
- *
4
- * Small, cross-platform helpers built on top of the platform stream
5
- * implementation. This file is swapped for `utils.browser.ts` in browser
6
- * builds via the `preferBrowserFilesPlugin()` mechanism.
7
- *
8
- * All factory-produced helpers are lazily initialized on first call to avoid
9
- * eagerly pulling in heavy stream class dependencies at import time.
10
- */
11
- import { createReadableFromArray, createTransform } from "./node/factories.js";
12
- import { consumers } from "./node/utils.js";
13
- import { collect, createText, createJson, createBytes, createFromString, createFromJSON, createFromBytes, createTransformHelper, createFilter, isReadableStreamLike, readableStreamToAsyncIterable } from "./utils.base.js";
14
- let _deps = null;
15
- function getDeps() {
16
- if (!_deps) {
17
- _deps = {
18
- createReadableFromArray,
19
- createTransform: createTransform,
20
- consumers
21
- };
22
- }
23
- return _deps;
24
- }
25
- export { collect, isReadableStreamLike, readableStreamToAsyncIterable };
26
- let _text;
27
- export function text(stream) {
28
- if (!_text) {
29
- _text = createText(getDeps());
30
- }
31
- return _text(stream);
32
- }
33
- let _json;
34
- export function json(stream) {
35
- if (!_json) {
36
- _json = createJson(getDeps());
37
- }
38
- return _json(stream);
39
- }
40
- let _bytes;
41
- export function bytes(stream) {
42
- if (!_bytes) {
43
- _bytes = createBytes(getDeps());
44
- }
45
- return _bytes(stream);
46
- }
47
- let _fromString;
48
- export function fromString(str) {
49
- if (!_fromString) {
50
- _fromString = createFromString(getDeps());
51
- }
52
- return _fromString(str);
53
- }
54
- let _fromJSON;
55
- export function fromJSON(data) {
56
- if (!_fromJSON) {
57
- _fromJSON = createFromJSON(getDeps());
58
- }
59
- return _fromJSON(data);
60
- }
61
- let _fromBytes;
62
- export function fromBytes(data) {
63
- if (!_fromBytes) {
64
- _fromBytes = createFromBytes(getDeps());
65
- }
66
- return _fromBytes(data);
67
- }
68
- let _transform;
69
- export function transform(fn) {
70
- if (!_transform) {
71
- _transform = createTransformHelper(getDeps());
72
- }
73
- return _transform(fn);
74
- }
75
- let _filter;
76
- export function filter(predicate) {
77
- if (!_filter) {
78
- _filter = createFilter(getDeps());
79
- }
80
- return _filter(predicate);
81
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Lazy Duplex.from() registry
3
- *
4
- * Breaks the circular import between Readable and Duplex:
5
- * readable.ts → duplex.ts → readable.ts (cycle!)
6
- *
7
- * This file has ZERO imports from the browser stream class files, so it
8
- * can be safely imported by readable.ts without creating a cycle.
9
- * The actual Duplex.from binding is registered at module load time by
10
- * index.browser.ts.
11
- *
12
- * @internal
13
- */
14
- type DuplexFromFn = (source: unknown) => IDuplex<unknown, unknown>;
15
- /**
16
- * Get the registered Duplex.from() factory.
17
- * Returns null if not yet registered (callers should handle gracefully).
18
- */
19
- export declare function getDuplexFrom(): DuplexFromFn | null;
20
- export {};
@@ -1,61 +0,0 @@
1
- /**
2
- * Browser Stream - ChunkBuffer
3
- *
4
- * Encapsulates FIFO buffer management for Readable streams.
5
- * Tracks byte size internally so callers don't need manual bookkeeping.
6
- */
7
- /**
8
- * A FIFO buffer optimised for stream chunk management.
9
- *
10
- * - Uses an index-based ring on the main array to avoid O(n) `Array.shift()`.
11
- * - Maintains a small front-stack for `unshift()` to avoid O(n) `Array.unshift()`.
12
- * - Tracks cumulative byte size (binary mode) so backpressure checks are O(1).
13
- */
14
- export declare class ChunkBuffer<T> {
15
- private _items;
16
- private _index;
17
- private _front;
18
- private _byteSize;
19
- private readonly _objectMode;
20
- constructor(objectMode: boolean);
21
- private _chunkSize;
22
- /** Number of buffered items. */
23
- get length(): number;
24
- /**
25
- * Tracked byte size (binary mode) or item count (object mode).
26
- * Useful for O(1) backpressure checks without iterating.
27
- */
28
- get byteSize(): number;
29
- /** Append a chunk to the back of the buffer. */
30
- push(chunk: T): void;
31
- /** Remove and return the front chunk. Caller must check `length > 0` first. */
32
- shift(): T;
33
- /** Push a chunk back to the front of the buffer. */
34
- unshift(chunk: T): void;
35
- /** Peek at the front chunk without removing it. Returns `null` if empty. */
36
- peek(): T | null;
37
- /** Return a snapshot array of all buffered chunks (front-stack first, then main ring). */
38
- toArray(): T[];
39
- /** Remove all buffered data. */
40
- clear(): void;
41
- /**
42
- * Consume exactly `size` bytes from the buffer, splitting chunks as needed.
43
- * Returns a single Uint8Array of exactly `size` bytes.
44
- * Caller must ensure `byteSize >= size` before calling.
45
- * Only valid in binary (non-object) mode.
46
- */
47
- consumeBytes(size: number): T;
48
- /**
49
- * Consume all buffered data and return as a single concatenated Uint8Array.
50
- * Only valid in binary (non-object) mode.
51
- * Optimised: iterates directly over internal arrays instead of per-element
52
- * shift() to avoid redundant _byteSize arithmetic and compaction checks.
53
- */
54
- consumeAll(): T;
55
- /**
56
- * Remove and return the front chunk WITHOUT updating byteSize.
57
- * Used by consumeBytes when we need to split a chunk.
58
- * Actually, we just use shift() which handles byteSize — see consumeBytes.
59
- */
60
- private _shiftFrontChunk;
61
- }