Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 1 addition & 1 deletion lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,7 @@ function fromList(n, state) {
n -= str.length;
buf[idx++] = null;
} else {
if (n === buf.length) {
if (n === str.length) {
ret += str;
buf[idx++] = null;
} else {
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-stream2-read-correct-num-bytes-in-utf8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

Check failure on line 1 in test/parallel/test-stream2-read-correct-num-bytes-in-utf8.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Mandatory module "common" must be loaded before any other modules

Check failure on line 1 in test/parallel/test-stream2-read-correct-num-bytes-in-utf8.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Mandatory module "common" must be loaded

const assert = require('assert');
const { Readable } = require('stream');

const readable = new Readable({ read() {} });
readable.setEncoding('utf8');

readable.push('abc');
readable.push('defgh');
readable.push(null);

assert.strictEqual(readable.read(5), 'abcde');
assert.strictEqual(readable.read(3), 'fgh');
assert.strictEqual(readable.read(1), null);
Loading