MCPcopy Index your code
hub / github.com/nodejs/node / applyStatefulAsyncTransform

Function applyStatefulAsyncTransform

lib/internal/streams/iter/pull.js:648–672  ·  view source on GitHub ↗
(source, transform, options)

Source from the content-addressed store, hash-verified

646}
647
648async function* applyStatefulAsyncTransform(source, transform, options) {
649 const output = transform(withFlushAsync(source), options);
650 for await (const item of output) {
651 // Fast path: item is already a Uint8Array[] batch (e.g. compression transforms)
652 if (isUint8ArrayBatch(item)) {
653 if (item.length > 0) {
654 yield item;
655 }
656 continue;
657 }
658 // Fast path: single Uint8Array
659 if (isUint8Array(item)) {
660 yield [item];
661 continue;
662 }
663 // Slow path: flatten arbitrary transform yield
664 const batch = [];
665 for await (const chunk of flattenTransformYieldAsync(item)) {
666 ArrayPrototypePush(batch, chunk);
667 }
668 if (batch.length > 0) {
669 yield batch;
670 }
671 }
672}
673
674/**
675 * Fast path for validated stateful transforms (e.g. compression).

Callers 1

createAsyncPipelineFunction · 0.85

Calls 5

withFlushAsyncFunction · 0.85
isUint8ArrayBatchFunction · 0.85
isUint8ArrayFunction · 0.85
transformFunction · 0.50

Tested by

no test coverage detected