Skip to content

Commit

Permalink
fixup: fix missing lastNeed
Browse files Browse the repository at this point in the history
  • Loading branch information
apapirovski committed Feb 12, 2018
1 parent b7d6315 commit 269a3dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/string_decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,19 @@ Object.defineProperties(StringDecoder.prototype, {
kIncompleteCharactersEnd);
}
},
lastNeed: {
configurable: true,
enumerable: true,
get() {
return this[kNativeDecoder][kMissingBytes];
}
},
lastTotal: {
configurable: true,
enumerable: true,
get() {
return this[kNativeDecoder][kBufferedBytes] + this.lastNeed;
return this[kNativeDecoder][kBufferedBytes] +
this[kNativeDecoder][kMissingBytes];
}
}
});
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-string-decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ test('utf16le', Buffer.from('3DD84DDC', 'hex'), '\ud83d\udc4d'); // thumbs up
// Additional UTF-8 tests
decoder = new StringDecoder('utf8');
assert.strictEqual(decoder.write(Buffer.from('E1', 'hex')), '');

// A quick test for lastNeed & lastTotal which are undocumented.
assert.strictEqual(decoder.lastNeed, 2);
assert.strictEqual(decoder.lastTotal, 3);

assert.strictEqual(decoder.end(), '\ufffd');

decoder = new StringDecoder('utf8');
Expand Down

0 comments on commit 269a3dc

Please sign in to comment.