8000 [v8.x fix] - stream: fix end not being called when reading some base64 files by marcosc90 · Pull Request #21089 · nodejs/node · GitHub
[go: up one dir, main page]

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

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function maybeReadMore(stream, state) {

function maybeReadMore_(stream, state) {
var len = state.length;
while (!state.reading && !state.flowing && !state.ended &&
while (!state.reading && !state.ended &&
state.length < state.highWaterMark) {
debug('maybeReadMore read 0');
stream.read(0);
Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-fs-read-stream-events.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');

const tmpdir = require('../common/tmpdir');

const encodings = ['utf8', 'base64', 'ascii', 'binary', 'hex', 'utf16le'];

function test(encoding) {

const file = path.join(tmpdir.path, `read-stream-events-${encoding}.txt`);

const data = '1234';
fs.writeFileSync(file, data);

const rs = fs.createReadStream(file, {
encoding,
highWaterMark: data.length - 1
});

let chunks = '';

rs.on('data', common.mustCall(function(data) {
chunks += Buffer.from(data, encoding);
}, 2));

rs.on('end', common.mustCall(function() {
assert.strictEqual(chunks, data);
}));
}

for (const encoding of encodings)
test(encoding);
0