@cj-tech-master/excelts 4.2.1-canary.20260111102127.f808a37 → 4.2.1-canary.20260112134913.a3cecdd

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 (101) hide show
  1. package/dist/browser/modules/archive/io/archive-sink.d.ts +0 -1
  2. package/dist/browser/modules/archive/io/archive-sink.js +6 -38
  3. package/dist/browser/modules/archive/io/archive-source.d.ts +0 -2
  4. package/dist/browser/modules/archive/io/archive-source.js +1 -8
  5. package/dist/browser/modules/excel/utils/ooxml-validator.d.ts +48 -0
  6. package/dist/browser/modules/excel/utils/ooxml-validator.js +469 -0
  7. package/dist/browser/modules/excel/worksheet.js +5 -2
  8. package/dist/browser/modules/excel/xlsx/xform/drawing/ctrl-prop-xform.d.ts +1 -0
  9. package/dist/browser/modules/excel/xlsx/xform/drawing/ctrl-prop-xform.js +13 -1
  10. package/dist/browser/modules/excel/xlsx/xform/drawing/sp-xform.d.ts +18 -0
  11. package/dist/browser/modules/excel/xlsx/xform/drawing/sp-xform.js +112 -0
  12. package/dist/browser/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.d.ts +6 -1
  13. package/dist/browser/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +30 -2
  14. package/dist/browser/modules/excel/xlsx/xform/drawing/vml-drawing-xform.js +11 -0
  15. package/dist/browser/modules/excel/xlsx/xform/sheet/page-setup-xform.d.ts +1 -0
  16. package/dist/browser/modules/excel/xlsx/xform/sheet/page-setup-xform.js +16 -2
  17. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +110 -12
  18. package/dist/browser/modules/stream/base-transform.d.ts +3 -0
  19. package/dist/browser/modules/stream/base-transform.js +34 -20
  20. package/dist/browser/modules/stream/buffered-stream.d.ts +2 -12
  21. package/dist/browser/modules/stream/chunked-builder.js +4 -4
  22. package/dist/browser/modules/stream/index.browser.d.ts +13 -19
  23. package/dist/browser/modules/stream/index.browser.js +10 -22
  24. package/dist/browser/modules/stream/index.d.ts +18 -41
  25. package/dist/browser/modules/stream/index.js +15 -44
  26. package/dist/browser/modules/stream/internal/event-utils.d.ts +17 -0
  27. package/dist/browser/modules/stream/internal/event-utils.js +40 -0
  28. package/dist/browser/modules/stream/internal/type-guards.d.ts +9 -0
  29. package/dist/browser/modules/stream/internal/type-guards.js +24 -0
  30. package/dist/browser/modules/stream/pull-stream.d.ts +5 -6
  31. package/dist/browser/modules/stream/pull-stream.js +107 -43
  32. package/dist/browser/modules/stream/shared.d.ts +1 -1
  33. package/dist/browser/modules/stream/shared.js +7 -4
  34. package/dist/browser/modules/stream/streams.browser.d.ts +4 -14
  35. package/dist/browser/modules/stream/streams.browser.js +129 -164
  36. package/dist/browser/modules/stream/streams.d.ts +4 -20
  37. package/dist/browser/modules/stream/streams.js +6 -37
  38. package/dist/browser/modules/stream/utils.js +5 -38
  39. package/dist/cjs/modules/archive/io/archive-sink.js +7 -40
  40. package/dist/cjs/modules/archive/io/archive-source.js +3 -12
  41. package/dist/cjs/modules/excel/utils/ooxml-validator.js +475 -0
  42. package/dist/cjs/modules/excel/worksheet.js +5 -2
  43. package/dist/cjs/modules/excel/xlsx/xform/drawing/ctrl-prop-xform.js +13 -1
  44. package/dist/cjs/modules/excel/xlsx/xform/drawing/sp-xform.js +115 -0
  45. package/dist/cjs/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +30 -2
  46. package/dist/cjs/modules/excel/xlsx/xform/drawing/vml-drawing-xform.js +11 -0
  47. package/dist/cjs/modules/excel/xlsx/xform/sheet/page-setup-xform.js +16 -2
  48. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +110 -12
  49. package/dist/cjs/modules/stream/base-transform.js +34 -20
  50. package/dist/cjs/modules/stream/chunked-builder.js +4 -4
  51. package/dist/cjs/modules/stream/index.browser.js +10 -17
  52. package/dist/cjs/modules/stream/index.js +15 -39
  53. package/dist/cjs/modules/stream/internal/event-utils.js +43 -0
  54. package/dist/cjs/modules/stream/internal/type-guards.js +30 -0
  55. package/dist/cjs/modules/stream/pull-stream.js +107 -43
  56. package/dist/cjs/modules/stream/shared.js +7 -4
  57. package/dist/cjs/modules/stream/streams.browser.js +135 -175
  58. package/dist/cjs/modules/stream/streams.js +16 -49
  59. package/dist/cjs/modules/stream/utils.js +3 -36
  60. package/dist/esm/modules/archive/io/archive-sink.js +6 -38
  61. package/dist/esm/modules/archive/io/archive-source.js +1 -8
  62. package/dist/esm/modules/excel/utils/ooxml-validator.js +469 -0
  63. package/dist/esm/modules/excel/worksheet.js +5 -2
  64. package/dist/esm/modules/excel/xlsx/xform/drawing/ctrl-prop-xform.js +13 -1
  65. package/dist/esm/modules/excel/xlsx/xform/drawing/sp-xform.js +112 -0
  66. package/dist/esm/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +30 -2
  67. package/dist/esm/modules/excel/xlsx/xform/drawing/vml-drawing-xform.js +11 -0
  68. package/dist/esm/modules/excel/xlsx/xform/sheet/page-setup-xform.js +16 -2
  69. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +110 -12
  70. package/dist/esm/modules/stream/base-transform.js +34 -20
  71. package/dist/esm/modules/stream/chunked-builder.js +4 -4
  72. package/dist/esm/modules/stream/index.browser.js +10 -22
  73. package/dist/esm/modules/stream/index.js +15 -44
  74. package/dist/esm/modules/stream/internal/event-utils.js +40 -0
  75. package/dist/esm/modules/stream/internal/type-guards.js +24 -0
  76. package/dist/esm/modules/stream/pull-stream.js +107 -43
  77. package/dist/esm/modules/stream/shared.js +7 -4
  78. package/dist/esm/modules/stream/streams.browser.js +129 -164
  79. package/dist/esm/modules/stream/streams.js +6 -37
  80. package/dist/esm/modules/stream/utils.js +5 -38
  81. package/dist/iife/excelts.iife.js +325 -60
  82. package/dist/iife/excelts.iife.js.map +1 -1
  83. package/dist/iife/excelts.iife.min.js +25 -25
  84. package/dist/types/modules/archive/io/archive-sink.d.ts +0 -1
  85. package/dist/types/modules/archive/io/archive-source.d.ts +0 -2
  86. package/dist/types/modules/excel/utils/ooxml-validator.d.ts +48 -0
  87. package/dist/types/modules/excel/xlsx/xform/drawing/ctrl-prop-xform.d.ts +1 -0
  88. package/dist/types/modules/excel/xlsx/xform/drawing/sp-xform.d.ts +18 -0
  89. package/dist/types/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.d.ts +6 -1
  90. package/dist/types/modules/excel/xlsx/xform/sheet/page-setup-xform.d.ts +1 -0
  91. package/dist/types/modules/stream/base-transform.d.ts +3 -0
  92. package/dist/types/modules/stream/buffered-stream.d.ts +2 -12
  93. package/dist/types/modules/stream/index.browser.d.ts +13 -19
  94. package/dist/types/modules/stream/index.d.ts +18 -41
  95. package/dist/types/modules/stream/internal/event-utils.d.ts +17 -0
  96. package/dist/types/modules/stream/internal/type-guards.d.ts +9 -0
  97. package/dist/types/modules/stream/pull-stream.d.ts +5 -6
  98. package/dist/types/modules/stream/shared.d.ts +1 -1
  99. package/dist/types/modules/stream/streams.browser.d.ts +4 -14
  100. package/dist/types/modules/stream/streams.d.ts +4 -20
  101. package/package.json +10 -10
@@ -12,7 +12,7 @@
12
12
  * - Edge >= 89
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.promises = exports.consumers = exports.streamToBuffer = exports.BufferedStream = exports.BufferChunk = exports.StringChunk = exports.PullStream = exports.Collector = exports.PassThrough = exports.Duplex = exports.Transform = exports.Writable = exports.Readable = void 0;
15
+ exports.promises = exports.consumers = exports.streamToBuffer = exports.BufferChunk = exports.StringChunk = exports.BufferedStream = exports.PullStream = exports.Collector = exports.PassThrough = exports.Duplex = exports.Transform = exports.Writable = exports.Readable = void 0;
16
16
  exports.normalizeWritable = normalizeWritable;
17
17
  exports.createReadable = createReadable;
18
18
  exports.createReadableFromAsyncIterable = createReadableFromAsyncIterable;
@@ -53,8 +53,13 @@ exports.isWritable = isWritable;
53
53
  exports.duplexPair = duplexPair;
54
54
  const event_emitter_1 = require("./event-emitter.js");
55
55
  const pull_stream_1 = require("./pull-stream.js");
56
+ Object.defineProperty(exports, "PullStream", { enumerable: true, get: function () { return pull_stream_1.PullStream; } });
56
57
  const buffered_stream_1 = require("./buffered-stream.js");
58
+ Object.defineProperty(exports, "BufferedStream", { enumerable: true, get: function () { return buffered_stream_1.BufferedStream; } });
59
+ Object.defineProperty(exports, "BufferChunk", { enumerable: true, get: function () { return buffered_stream_1.BufferChunk; } });
60
+ Object.defineProperty(exports, "StringChunk", { enumerable: true, get: function () { return buffered_stream_1.StringChunk; } });
57
61
  const shared_1 = require("./shared.js");
62
+ const type_guards_1 = require("./internal/type-guards.js");
58
63
  const removeEmitterListener = (emitter, event, listener) => {
59
64
  if (typeof emitter.off === "function") {
60
65
  emitter.off(event, listener);
@@ -2450,28 +2455,6 @@ class Collector extends Writable {
2450
2455
  }
2451
2456
  exports.Collector = Collector;
2452
2457
  // =============================================================================
2453
- // PullStream / BufferedStream / DataChunk helpers
2454
- // =============================================================================
2455
- class PullStream extends pull_stream_1.PullStream {
2456
- // Keep constructor signature aligned with streams.browser.ts public API
2457
- constructor(options) {
2458
- super(options);
2459
- }
2460
- }
2461
- exports.PullStream = PullStream;
2462
- class StringChunk extends buffered_stream_1.StringChunk {
2463
- }
2464
- exports.StringChunk = StringChunk;
2465
- class BufferChunk extends buffered_stream_1.BufferChunk {
2466
- }
2467
- exports.BufferChunk = BufferChunk;
2468
- class BufferedStream extends buffered_stream_1.BufferedStream {
2469
- constructor(options) {
2470
- super(options);
2471
- }
2472
- }
2473
- exports.BufferedStream = BufferedStream;
2474
- // =============================================================================
2475
2458
  // Stream Creation Functions
2476
2459
  // =============================================================================
2477
2460
  /**
@@ -2545,28 +2528,14 @@ function createPassThrough(options) {
2545
2528
  * Create a pull stream
2546
2529
  */
2547
2530
  function createPullStream(options) {
2548
- return new PullStream(options);
2531
+ return new pull_stream_1.PullStream(options);
2549
2532
  }
2550
2533
  /**
2551
2534
  * Create a buffered stream
2552
2535
  */
2553
2536
  function createBufferedStream(options) {
2554
- return new BufferedStream(options);
2537
+ return new buffered_stream_1.BufferedStream(options);
2555
2538
  }
2556
- const isReadableStream = (value) => !!value && typeof value === "object" && typeof value.getReader === "function";
2557
- const isAsyncIterable = (value) => {
2558
- if (!value || (typeof value !== "object" && typeof value !== "function")) {
2559
- return false;
2560
- }
2561
- return typeof value[Symbol.asyncIterator] === "function";
2562
- };
2563
- const isWritableStream = (value) => !!value && typeof value === "object" && typeof value.getWriter === "function";
2564
- const isTransformStream = (value) => !!value &&
2565
- typeof value === "object" &&
2566
- !!value.readable &&
2567
- !!value.writable &&
2568
- isReadableStream(value.readable) &&
2569
- isWritableStream(value.writable);
2570
2539
  const isPipelineOptions = (value) => {
2571
2540
  if (!value || typeof value !== "object") {
2572
2541
  return false;
@@ -2591,13 +2560,13 @@ const toBrowserPipelineStream = (stream) => {
2591
2560
  stream instanceof Duplex) {
2592
2561
  return stream;
2593
2562
  }
2594
- if (isTransformStream(stream)) {
2563
+ if ((0, type_guards_1.isTransformStream)(stream)) {
2595
2564
  return Transform.fromWeb(stream);
2596
2565
  }
2597
- if (isReadableStream(stream)) {
2566
+ if ((0, type_guards_1.isReadableStream)(stream)) {
2598
2567
  return Readable.fromWeb(stream);
2599
2568
  }
2600
- if (isWritableStream(stream)) {
2569
+ if ((0, type_guards_1.isWritableStream)(stream)) {
2601
2570
  return Writable.fromWeb(stream);
2602
2571
  }
2603
2572
  return stream;
@@ -2836,8 +2805,8 @@ async function streamToPromise(stream) {
2836
2805
  * (Browser equivalent of Node.js streamToBuffer)
2837
2806
  */
2838
2807
  async function streamToUint8Array(stream) {
2839
- const { chunks, totalLength } = await collectStreamChunks(stream);
2840
- return concatWithLength(chunks, totalLength);
2808
+ const [chunks, totalLength] = await collectStreamChunks(stream);
2809
+ return (0, shared_1.concatUint8Arrays)(chunks, totalLength);
2841
2810
  }
2842
2811
  /**
2843
2812
  * Alias for streamToUint8Array (Node.js compatibility)
@@ -2847,8 +2816,8 @@ exports.streamToBuffer = streamToUint8Array;
2847
2816
  * Collect all data from a readable stream into a string
2848
2817
  */
2849
2818
  async function streamToString(stream, encoding) {
2850
- const { chunks, totalLength } = await collectStreamChunks(stream);
2851
- const combined = concatWithLength(chunks, totalLength);
2819
+ const [chunks, totalLength] = await collectStreamChunks(stream);
2820
+ const combined = (0, shared_1.concatUint8Arrays)(chunks, totalLength);
2852
2821
  const decoder = encoding ? (0, shared_1.getTextDecoder)(encoding) : shared_1.textDecoder;
2853
2822
  return decoder.decode(combined);
2854
2823
  }
@@ -2856,16 +2825,7 @@ async function streamToString(stream, encoding) {
2856
2825
  * Drain a stream (consume all data without processing)
2857
2826
  */
2858
2827
  async function drainStream(stream) {
2859
- let iterable;
2860
- if (isReadableStream(stream)) {
2861
- iterable = Readable.fromWeb(stream);
2862
- }
2863
- else if (isAsyncIterable(stream)) {
2864
- iterable = stream;
2865
- }
2866
- else {
2867
- throw new Error("drainStream: unsupported stream type");
2868
- }
2828
+ const iterable = toReadableAsyncIterable(stream, "drainStream");
2869
2829
  for await (const _chunk of iterable) {
2870
2830
  // Consume data
2871
2831
  }
@@ -3085,94 +3045,117 @@ function compose(...transforms) {
3085
3045
  for (let i = 0; i < len - 1; i++) {
3086
3046
  transforms[i].pipe(transforms[i + 1]);
3087
3047
  }
3088
- class ComposedTransform extends Transform {
3089
- constructor(options) {
3090
- super(options);
3091
- this._dataForwarding = false;
3092
- this._endForwarding = false;
3093
- this._dataForwardCleanup = null;
3094
- this._endForwardCleanup = null;
3095
- this._errorForwardCleanup = [];
3096
- for (const t of transforms) {
3097
- const onError = (err) => {
3098
- this.emit("error", err);
3099
- };
3100
- this._errorForwardCleanup.push(addEmitterListener(t, "error", onError));
3101
- }
3102
- }
3103
- on(event, listener) {
3104
- if (event === "data" && !this._dataForwarding) {
3105
- this._dataForwarding = true;
3106
- const onData = (chunk) => {
3107
- this.emit("data", chunk);
3108
- };
3109
- this._dataForwardCleanup = addEmitterListener(last, "data", onData);
3110
- }
3111
- if (event === "end" && !this._endForwarding) {
3112
- this._endForwarding = true;
3113
- const onEnd = () => {
3114
- this.emit("end");
3115
- };
3116
- this._endForwardCleanup = addEmitterListener(last, "end", onEnd, { once: true });
3117
- }
3118
- return super.on(event, listener);
3119
- }
3120
- write(chunk, encodingOrCallback, callback) {
3121
- if (typeof encodingOrCallback === "function") {
3122
- return first.write(chunk, encodingOrCallback);
3123
- }
3124
- return first.write(chunk, encodingOrCallback, callback);
3125
- }
3126
- end(chunkOrCallback, encodingOrCallback, callback) {
3127
- if (typeof chunkOrCallback === "function") {
3128
- first.end(chunkOrCallback);
3129
- return this;
3130
- }
3131
- if (typeof encodingOrCallback === "function") {
3132
- first.end(chunkOrCallback, encodingOrCallback);
3133
- return this;
3134
- }
3135
- first.end(chunkOrCallback, encodingOrCallback, callback);
3136
- return this;
3048
+ // A lightweight Transform wrapper that delegates:
3049
+ // - writable side to `first`
3050
+ // - readable side to `last`
3051
+ // It forwards relevant events lazily to avoid per-chunk overhead when unused.
3052
+ const composed = new Transform({
3053
+ objectMode: first?.objectMode ?? true,
3054
+ transform: chunk => chunk
3055
+ });
3056
+ const registry = createListenerRegistry();
3057
+ // Always forward errors; they are critical for pipeline semantics.
3058
+ for (const t of transforms) {
3059
+ registry.add(t, "error", (err) => composed.emit("error", err));
3060
+ }
3061
+ // Forward writable-side backpressure/completion events from `first`.
3062
+ registry.add(first, "drain", () => composed.emit("drain"));
3063
+ registry.once(first, "finish", () => composed.emit("finish"));
3064
+ // Forward readable-side events from `last` lazily.
3065
+ let forwardData = false;
3066
+ let forwardEnd = false;
3067
+ let forwardReadable = false;
3068
+ const ensureDataForwarding = () => {
3069
+ if (forwardData) {
3070
+ return;
3137
3071
  }
3138
- pipe(destination) {
3139
- return last.pipe(destination);
3072
+ forwardData = true;
3073
+ registry.add(last, "data", (chunk) => composed.emit("data", chunk));
3074
+ };
3075
+ const ensureEndForwarding = () => {
3076
+ if (forwardEnd) {
3077
+ return;
3140
3078
  }
3141
- destroy(error) {
3142
- if (this._dataForwardCleanup) {
3143
- this._dataForwardCleanup();
3144
- this._dataForwardCleanup = null;
3145
- }
3146
- if (this._endForwardCleanup) {
3147
- this._endForwardCleanup();
3148
- this._endForwardCleanup = null;
3149
- }
3150
- for (let i = this._errorForwardCleanup.length - 1; i >= 0; i--) {
3151
- this._errorForwardCleanup[i]();
3152
- }
3153
- this._errorForwardCleanup.length = 0;
3154
- for (const t of transforms) {
3155
- t.destroy(error);
3156
- }
3157
- super.destroy(error);
3079
+ forwardEnd = true;
3080
+ registry.once(last, "end", () => composed.emit("end"));
3081
+ };
3082
+ const ensureReadableForwarding = () => {
3083
+ if (forwardReadable) {
3084
+ return;
3085
+ }
3086
+ forwardReadable = true;
3087
+ registry.add(last, "readable", () => composed.emit("readable"));
3088
+ };
3089
+ const originalOn = composed.on.bind(composed);
3090
+ const originalOnce = composed.once.bind(composed);
3091
+ composed.on = (event, listener) => {
3092
+ if (event === "data") {
3093
+ ensureDataForwarding();
3158
3094
  }
3159
- read(size) {
3160
- return typeof last.read === "function" ? last.read(size) : null;
3095
+ else if (event === "end") {
3096
+ ensureEndForwarding();
3161
3097
  }
3162
- async *[Symbol.asyncIterator]() {
3163
- const it = last?.[Symbol.asyncIterator]?.();
3164
- if (it) {
3165
- for await (const chunk of it) {
3166
- yield chunk;
3167
- }
3168
- return;
3098
+ else if (event === "readable") {
3099
+ ensureReadableForwarding();
3100
+ }
3101
+ return originalOn(event, listener);
3102
+ };
3103
+ composed.once = (event, listener) => {
3104
+ if (event === "data") {
3105
+ ensureDataForwarding();
3106
+ }
3107
+ else if (event === "end") {
3108
+ ensureEndForwarding();
3109
+ }
3110
+ else if (event === "readable") {
3111
+ ensureReadableForwarding();
3112
+ }
3113
+ return originalOnce(event, listener);
3114
+ };
3115
+ // Delegate core stream methods
3116
+ const firstAny = first;
3117
+ const lastAny = last;
3118
+ composed.write = (chunk, encodingOrCallback, callback) => {
3119
+ if (typeof encodingOrCallback === "function") {
3120
+ return firstAny.write(chunk, encodingOrCallback);
3121
+ }
3122
+ return firstAny.write(chunk, encodingOrCallback, callback);
3123
+ };
3124
+ composed.end = (chunkOrCallback, encodingOrCallback, callback) => {
3125
+ if (typeof chunkOrCallback === "function") {
3126
+ firstAny.end(chunkOrCallback);
3127
+ return composed;
3128
+ }
3129
+ if (typeof encodingOrCallback === "function") {
3130
+ firstAny.end(chunkOrCallback, encodingOrCallback);
3131
+ return composed;
3132
+ }
3133
+ firstAny.end(chunkOrCallback, encodingOrCallback, callback);
3134
+ return composed;
3135
+ };
3136
+ composed.pipe = (destination) => {
3137
+ return lastAny.pipe(destination);
3138
+ };
3139
+ composed.read = (size) => {
3140
+ return typeof lastAny.read === "function" ? lastAny.read(size) : null;
3141
+ };
3142
+ composed[Symbol.asyncIterator] = async function* () {
3143
+ const it = lastAny?.[Symbol.asyncIterator]?.();
3144
+ if (it) {
3145
+ for await (const chunk of it) {
3146
+ yield chunk;
3169
3147
  }
3170
- yield* super[Symbol.asyncIterator]();
3148
+ return;
3171
3149
  }
3172
- }
3173
- const composed = new ComposedTransform({
3174
- objectMode: first?.objectMode ?? true,
3175
- transform: chunk => chunk
3150
+ yield* Transform.prototype[Symbol.asyncIterator].call(composed);
3151
+ };
3152
+ const originalDestroy = composed.destroy.bind(composed);
3153
+ composed.destroy = ((error) => {
3154
+ registry.cleanup();
3155
+ for (const t of transforms) {
3156
+ t.destroy(error);
3157
+ }
3158
+ originalDestroy(error);
3176
3159
  });
3177
3160
  // Reflect underlying readability/writability like the previous duck-typed wrapper
3178
3161
  Object.defineProperty(composed, "readable", {
@@ -3419,77 +3402,54 @@ function duplexPair(options) {
3419
3402
  async function collectStreamChunks(stream) {
3420
3403
  const chunks = [];
3421
3404
  let totalLength = 0;
3422
- let iterable;
3423
- if (isReadableStream(stream)) {
3424
- iterable = Readable.fromWeb(stream);
3425
- }
3426
- else if (isAsyncIterable(stream)) {
3427
- iterable = stream;
3428
- }
3429
- else {
3430
- throw new Error("collectStreamChunks: unsupported stream type");
3431
- }
3405
+ const iterable = toReadableAsyncIterable(stream, "collectStreamChunks");
3432
3406
  for await (const chunk of iterable) {
3433
3407
  chunks.push(chunk);
3434
3408
  totalLength += chunk.length;
3435
3409
  }
3436
- return { chunks, totalLength };
3410
+ return [chunks, totalLength];
3437
3411
  }
3438
- // Helper to concatenate with known length (faster)
3439
- function concatWithLength(chunks, totalLength) {
3440
- const len = chunks.length;
3441
- if (len === 0) {
3442
- return new Uint8Array(0);
3443
- }
3444
- if (len === 1) {
3445
- return chunks[0];
3412
+ function toReadableAsyncIterable(stream, name) {
3413
+ if ((0, type_guards_1.isReadableStream)(stream)) {
3414
+ return Readable.fromWeb(stream);
3446
3415
  }
3447
- const result = new Uint8Array(totalLength);
3448
- let offset = 0;
3449
- for (let i = 0; i < len; i++) {
3450
- result.set(chunks[i], offset);
3451
- offset += chunks[i].length;
3416
+ if ((0, type_guards_1.isAsyncIterable)(stream)) {
3417
+ return stream;
3452
3418
  }
3453
- return result;
3419
+ throw new Error(`${name}: unsupported stream type`);
3454
3420
  }
3455
3421
  exports.consumers = {
3456
3422
  /**
3457
3423
  * Consume entire stream as ArrayBuffer
3458
3424
  */
3459
3425
  async arrayBuffer(stream) {
3460
- const { chunks, totalLength } = await collectStreamChunks(stream);
3461
- const combined = concatWithLength(chunks, totalLength);
3462
- return combined.buffer.slice(combined.byteOffset, combined.byteOffset + combined.byteLength);
3426
+ const bytes = await streamToUint8Array(stream);
3427
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
3463
3428
  },
3464
3429
  /**
3465
3430
  * Consume entire stream as Blob
3466
3431
  */
3467
3432
  async blob(stream, options) {
3468
- const { chunks } = await collectStreamChunks(stream);
3433
+ const [chunks] = await collectStreamChunks(stream);
3469
3434
  return new Blob(chunks, options);
3470
3435
  },
3471
3436
  /**
3472
3437
  * Consume entire stream as Buffer (Uint8Array in browser)
3473
3438
  */
3474
3439
  async buffer(stream) {
3475
- const { chunks, totalLength } = await collectStreamChunks(stream);
3476
- return concatWithLength(chunks, totalLength);
3440
+ return streamToUint8Array(stream);
3477
3441
  },
3478
3442
  /**
3479
3443
  * Consume entire stream as JSON
3480
3444
  */
3481
3445
  async json(stream) {
3482
- const text = await exports.consumers.text(stream);
3483
- return JSON.parse(text);
3446
+ return JSON.parse(await streamToString(stream));
3484
3447
  },
3485
3448
  /**
3486
3449
  * Consume entire stream as text
3487
3450
  */
3488
3451
  async text(stream, encoding) {
3489
- const { chunks, totalLength } = await collectStreamChunks(stream);
3490
- const combined = concatWithLength(chunks, totalLength);
3491
- const decoder = encoding ? (0, shared_1.getTextDecoder)(encoding) : shared_1.textDecoder;
3492
- return decoder.decode(combined);
3452
+ return streamToString(stream, encoding);
3493
3453
  }
3494
3454
  };
3495
3455
  // =============================================================================
@@ -6,7 +6,7 @@
6
6
  * Provides Readable, Writable, Transform, Duplex, and PassThrough streams.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.promises = exports.consumers = exports.BufferedStream = exports.BufferChunk = exports.StringChunk = exports.PullStream = exports.Collector = exports.PassThrough = exports.Duplex = exports.Transform = exports.Readable = exports.Writable = void 0;
9
+ exports.promises = exports.consumers = exports.Collector = exports.BufferChunk = exports.StringChunk = exports.BufferedStream = exports.PullStream = exports.PassThrough = exports.Duplex = exports.Transform = exports.Readable = exports.Writable = void 0;
10
10
  exports.normalizeWritable = normalizeWritable;
11
11
  exports.pipeline = pipeline;
12
12
  exports.finished = finished;
@@ -52,7 +52,12 @@ Object.defineProperty(exports, "Transform", { enumerable: true, get: function ()
52
52
  Object.defineProperty(exports, "Duplex", { enumerable: true, get: function () { return stream_1.Duplex; } });
53
53
  Object.defineProperty(exports, "PassThrough", { enumerable: true, get: function () { return stream_1.PassThrough; } });
54
54
  const buffered_stream_1 = require("./buffered-stream.js");
55
+ Object.defineProperty(exports, "BufferedStream", { enumerable: true, get: function () { return buffered_stream_1.BufferedStream; } });
56
+ Object.defineProperty(exports, "BufferChunk", { enumerable: true, get: function () { return buffered_stream_1.BufferChunk; } });
57
+ Object.defineProperty(exports, "StringChunk", { enumerable: true, get: function () { return buffered_stream_1.StringChunk; } });
55
58
  const pull_stream_1 = require("./pull-stream.js");
59
+ Object.defineProperty(exports, "PullStream", { enumerable: true, get: function () { return pull_stream_1.PullStream; } });
60
+ const type_guards_1 = require("./internal/type-guards.js");
56
61
  /**
57
62
  * Unified Writable class - wraps Node.js Writable with browser-compatible API
58
63
  *
@@ -127,29 +132,12 @@ function normalizeWritable(stream) {
127
132
  }
128
133
  // Import for internal use
129
134
  const shared_1 = require("./shared.js");
130
- const isReadableStream = (value) => !!value && typeof value === "object" && typeof value.getReader === "function";
131
- const isAsyncIterable = (value) => {
132
- if (!value || (typeof value !== "object" && typeof value !== "function")) {
133
- return false;
134
- }
135
- return typeof value[Symbol.asyncIterator] === "function";
136
- };
137
- const isWritableStream = (value) => !!value && typeof value === "object" && typeof value.getWriter === "function";
138
- const isTransformStream = (value) => !!value &&
139
- typeof value === "object" &&
140
- !!value.readable &&
141
- !!value.writable &&
142
- isReadableStream(value.readable) &&
143
- isWritableStream(value.writable);
144
135
  const isPipelineOptions = (value) => {
145
136
  if (!value || typeof value !== "object") {
146
137
  return false;
147
138
  }
148
- // IMPORTANT:
149
- // Do NOT use `"end" in obj` here because streams have `.end()` and would be
150
- // misclassified as options, breaking argument parsing and potentially hanging.
139
+ // Avoid treating streams as options objects.
151
140
  if (typeof value.pipe === "function" ||
152
- typeof value.write === "function" ||
153
141
  typeof value.end === "function" ||
154
142
  typeof value.getReader === "function" ||
155
143
  typeof value.getWriter === "function") {
@@ -166,13 +154,13 @@ const toNodePipelineStream = (stream) => {
166
154
  stream instanceof stream_1.Writable) {
167
155
  return stream;
168
156
  }
169
- if (isTransformStream(stream)) {
157
+ if ((0, type_guards_1.isTransformStream)(stream)) {
170
158
  return stream_1.Transform.fromWeb(stream);
171
159
  }
172
- if (isReadableStream(stream)) {
160
+ if ((0, type_guards_1.isReadableStream)(stream)) {
173
161
  return stream_1.Readable.fromWeb(stream);
174
162
  }
175
- if (isWritableStream(stream)) {
163
+ if ((0, type_guards_1.isWritableStream)(stream)) {
176
164
  return stream_1.Writable.fromWeb(stream);
177
165
  }
178
166
  return stream;
@@ -469,41 +457,20 @@ function createCollector(options) {
469
457
  // =============================================================================
470
458
  // Pull Stream - Read data on demand with pattern matching
471
459
  // =============================================================================
472
- class PullStream extends pull_stream_1.PullStream {
473
- }
474
- exports.PullStream = PullStream;
475
460
  /**
476
461
  * Create a pull stream
477
462
  */
478
463
  function createPullStream(options) {
479
- return new PullStream(options);
464
+ return new pull_stream_1.PullStream(options);
480
465
  }
481
466
  // =============================================================================
482
467
  // Buffered Stream - Efficient chunk management
483
468
  // =============================================================================
484
- /**
485
- * String chunk implementation
486
- */
487
- class StringChunk extends buffered_stream_1.StringChunk {
488
- }
489
- exports.StringChunk = StringChunk;
490
- /**
491
- * Buffer chunk implementation
492
- */
493
- class BufferChunk extends buffered_stream_1.BufferChunk {
494
- }
495
- exports.BufferChunk = BufferChunk;
496
- /**
497
- * Buffered stream with efficient chunk management
498
- */
499
- class BufferedStream extends buffered_stream_1.BufferedStream {
500
- }
501
- exports.BufferedStream = BufferedStream;
502
469
  /**
503
470
  * Create a buffered stream
504
471
  */
505
472
  function createBufferedStream(options) {
506
- return new BufferedStream(options);
473
+ return new buffered_stream_1.BufferedStream(options);
507
474
  }
508
475
  // =============================================================================
509
476
  // Utility Functions
@@ -520,10 +487,10 @@ async function streamToPromise(stream) {
520
487
  */
521
488
  async function streamToBuffer(stream) {
522
489
  let iterable;
523
- if (isReadableStream(stream)) {
490
+ if ((0, type_guards_1.isReadableStream)(stream)) {
524
491
  iterable = stream_1.Readable.fromWeb(stream);
525
492
  }
526
- else if (isAsyncIterable(stream)) {
493
+ else if ((0, type_guards_1.isAsyncIterable)(stream)) {
527
494
  iterable = stream;
528
495
  }
529
496
  else {
@@ -565,10 +532,10 @@ async function streamToString(stream, encoding) {
565
532
  */
566
533
  async function drainStream(stream) {
567
534
  let iterable;
568
- if (isReadableStream(stream)) {
535
+ if ((0, type_guards_1.isReadableStream)(stream)) {
569
536
  iterable = stream_1.Readable.fromWeb(stream);
570
537
  }
571
- else if (isAsyncIterable(stream)) {
538
+ else if ((0, type_guards_1.isAsyncIterable)(stream)) {
572
539
  iterable = stream;
573
540
  }
574
541
  else {
@@ -28,46 +28,13 @@ async function collect(stream) {
28
28
  return result;
29
29
  }
30
30
  async function text(stream) {
31
- const chunks = [];
32
- let totalLength = 0;
33
- for await (const chunk of stream) {
34
- chunks.push(chunk);
35
- totalLength += chunk.length;
36
- }
37
- if (chunks.length === 1) {
38
- return (0, shared_1.uint8ArrayToString)(chunks[0]);
39
- }
40
- const result = new Uint8Array(totalLength);
41
- let offset = 0;
42
- for (let i = 0, len = chunks.length; i < len; i++) {
43
- const c = chunks[i];
44
- result.set(c, offset);
45
- offset += c.length;
46
- }
47
- return (0, shared_1.uint8ArrayToString)(result);
31
+ return streams_1.consumers.text(stream);
48
32
  }
49
33
  async function json(stream) {
50
- const str = await text(stream);
51
- return JSON.parse(str);
34
+ return streams_1.consumers.json(stream);
52
35
  }
53
36
  async function bytes(stream) {
54
- const chunks = [];
55
- let totalLength = 0;
56
- for await (const chunk of stream) {
57
- chunks.push(chunk);
58
- totalLength += chunk.length;
59
- }
60
- if (chunks.length === 1) {
61
- return chunks[0];
62
- }
63
- const result = new Uint8Array(totalLength);
64
- let offset = 0;
65
- for (let i = 0, len = chunks.length; i < len; i++) {
66
- const c = chunks[i];
67
- result.set(c, offset);
68
- offset += c.length;
69
- }
70
- return result;
37
+ return streams_1.consumers.buffer(stream);
71
38
  }
72
39
  // =============================================================================
73
40
  // Stream Factory Helpers