Skip to content

Commit

Permalink
implementation of Buffer.byteLength at fromListPartial
Browse files Browse the repository at this point in the history
A continued effort to ensure the highWaterMark is measured against
byteLength in all instances. The buffer head data has been measured
with string.proto.length. This commit changes the method to byteLength.
  • Loading branch information
jalafel committed Oct 27, 2016
1 parent b587c1f commit cedc393
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ function fromList(n, state) {
state.buffer.clear();
} else {
// read part of list
ret = fromListPartial(n, state.buffer, state.decoder);
ret = fromListPartial(n, state.buffer, state.encoding, state.decoder);
}

return ret;
Expand All @@ -865,13 +865,13 @@ function fromList(n, state) {
// Extracts only enough buffered data to satisfy the amount requested.
// This function is designed to be inlinable, so please take care when making
// changes to the function body.
function fromListPartial(n, list, hasStrings) {
function fromListPartial(n, list, encoding, hasStrings) {
var ret;
if (n < list.head.data.length) {
if (n < Buffer.byteLength(list.head.data, encoding)) {
// slice is the same for buffers and strings
ret = list.head.data.slice(0, n);
list.head.data = list.head.data.slice(n);
} else if (n === list.head.data.length) {
} else if (n === Buffer.byteLength(list.head.data, encoding)) {
// first chunk is a perfect match
ret = list.shift();
} else {
Expand Down

0 comments on commit cedc393

Please sign in to comment.