Skip to content
Closed
Changes from all commits
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
17 changes: 8 additions & 9 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,19 +856,18 @@ Readable.prototype.wrap = function(stream) {
var state = this._readableState;
var paused = false;

var self = this;
stream.on('end', function() {
stream.on('end', () => {
debug('wrapped end');
if (state.decoder && !state.ended) {
var chunk = state.decoder.end();
if (chunk && chunk.length)
self.push(chunk);
this.push(chunk);
}

self.push(null);
this.push(null);
});

stream.on('data', function(chunk) {
stream.on('data', (chunk) => {
debug('wrapped data');
if (state.decoder)
chunk = state.decoder.write(chunk);
Expand All @@ -879,7 +878,7 @@ Readable.prototype.wrap = function(stream) {
else if (!state.objectMode && (!chunk || !chunk.length))
return;

var ret = self.push(chunk);
var ret = this.push(chunk);
if (!ret) {
paused = true;
stream.pause();
Expand All @@ -900,20 +899,20 @@ Readable.prototype.wrap = function(stream) {

// proxy certain important events.
for (var n = 0; n < kProxyEvents.length; n++) {
stream.on(kProxyEvents[n], self.emit.bind(self, kProxyEvents[n]));
stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the face of it, looks like self was not required here in the first place, the block being directly under the lexical scope of constructor function.

}

// when we try to consume some more bytes, simply unpause the
// underlying stream.
self._read = function(n) {
this._read = (n) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, self was not required here in the first place I guess.

debug('wrapped _read', n);
if (paused) {
paused = false;
stream.resume();
}
};

return self;
return this;
};


Expand Down