Skip to content

Commit

Permalink
stream: use arrow fns for 'this' in readable
Browse files Browse the repository at this point in the history
PR-URL: #16927
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
vipinmenon authored and gibfahn committed Dec 19, 2017
1 parent 4d85687 commit 3531043
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,19 +853,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 @@ -876,7 +875,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 @@ -897,20 +896,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]));
}

// when we try to consume some more bytes, simply unpause the
// underlying stream.
self._read = function(n) {
this._read = (n) => {
debug('wrapped _read', n);
if (paused) {
paused = false;
stream.resume();
}
};

return self;
return this;
};


Expand Down

0 comments on commit 3531043

Please sign in to comment.