Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/internal/streams/iter/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ function* withFlushSync(source) {
function* applyStatefulSyncTransform(source, transform) {
const output = transform(withFlushSync(source));
for (const item of output) {
if (item === null) continue;
const batch = [];
for (const chunk of flattenTransformYieldSync(item)) {
ArrayPrototypePush(batch, chunk);
Expand Down Expand Up @@ -642,6 +643,7 @@ async function* withFlushAsync(source) {
async function* applyStatefulAsyncTransform(source, transform, options) {
const output = transform(withFlushAsync(source), options);
for await (const item of output) {
if (item === null) continue;
// Fast path: item is already a Uint8Array[] batch (e.g. compression transforms)
if (isUint8ArrayBatch(item)) {
if (item.length > 0) {
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-stream-iter-transform-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ async function testStatefulSyncTransformYieldsString() {
assert.deepStrictEqual(data, new TextEncoder().encode('world'));
}

// Stateful async transform yields null (no output)
async function testStatefulTransformYieldsNull() {
const tx = {
async *transform() {
yield null;
},
};
const data = await bytes(pull(from('x'), tx));
assert.deepStrictEqual(data, new Uint8Array());
}

// Stateful sync transform yields null (no output)
async function testStatefulSyncTransformYieldsNull() {
const tx = {
*transform() {
yield null;
},
};
const data = bytesSync(pullSync(fromSync('x'), tx));
assert.deepStrictEqual(data, new Uint8Array());
}

// Flush returns single Uint8Array (not batch)
async function testFlushReturnsSingleUint8Array() {
const tx = (chunks) => {
Expand Down Expand Up @@ -217,6 +239,8 @@ Promise.all([
testStatefulTransformYieldsString(),
testStatefulTransformYieldsArrayBuffer(),
testStatefulSyncTransformYieldsString(),
testStatefulTransformYieldsNull(),
testStatefulSyncTransformYieldsNull(),
testFlushReturnsSingleUint8Array(),
testFlushReturnsString(),
testSyncFlushReturnsSingleUint8Array(),
Expand Down
Loading