Skip to content

Commit f624ccb

Browse files
committed
streams2: Use StringDecoder.end
1 parent cf0b4ba commit f624ccb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

Diff for: lib/_stream_readable.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ Readable.prototype.read = function(n) {
153153
if (!chunk || !chunk.length) {
154154
// eof
155155
state.ended = true;
156+
if (state.decoder) {
157+
chunk = state.decoder.end();
158+
if (chunk && chunk.length) {
159+
state.buffer.push(chunk);
160+
state.length += chunk.length;
161+
}
162+
}
156163
// if we've ended and we have some data left, then emit
157164
// 'readable' now to make sure it gets picked up.
158165
if (!sync) {
@@ -395,11 +402,26 @@ Readable.prototype.wrap = function(stream) {
395402

396403
stream.on('end', function() {
397404
state.ended = true;
398-
if (state.length === 0)
405+
if (state.decoder) {
406+
var chunk = state.decoder.end();
407+
if (chunk && chunk.length) {
408+
state.buffer.push(chunk);
409+
state.length += chunk.length;
410+
}
411+
}
412+
413+
if (state.length > 0)
414+
this.emit('readable');
415+
else
399416
endReadable(this);
400417
}.bind(this));
401418

402419
stream.on('data', function(chunk) {
420+
if (state.decoder)
421+
chunk = state.decoder.write(chunk);
422+
if (!chunk || !chunk.length)
423+
return;
424+
403425
state.buffer.push(chunk);
404426
state.length += chunk.length;
405427
this.emit('readable');

0 commit comments

Comments
 (0)