Skip to content
Closed
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
1 change: 1 addition & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) {
}
} else if (!addToFront) {
state.reading = false;
maybeReadMore(stream, state);
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-stream-readable-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,33 @@ const Readable = require('stream').Readable;
r.on('readable', common.mustCall());
}, 1);
}

{
// pushing a empty string in non-objectMode should
// trigger next `read()`.
const underlyingData = ['', 'x', 'y', '', 'z'];
const expected = underlyingData.filter((data) => data);
const result = [];

const r = new Readable({
encoding: 'utf8',
});
r._read = function() {
process.nextTick(() => {
if (!underlyingData.length) {
this.push(null);
} else {
this.push(underlyingData.shift());
}
});
};

r.on('readable', () => {
const data = r.read();
if (data !== null) result.push(data);
});

r.on('end', common.mustCall(() => {
assert.deepStrictEqual(result, expected);
}));
}