stream: use arrow fns for 'this' in readable
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
42bdb66bf2
commit
fe932a1204
@ -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);
|
||||
@ -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();
|
||||
@ -900,12 +899,12 @@ 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;
|
||||
@ -913,7 +912,7 @@ Readable.prototype.wrap = function(stream) {
|
||||
}
|
||||
};
|
||||
|
||||
return self;
|
||||
return this;
|
||||
};
|
||||
|
||||
Object.defineProperty(Readable.prototype, 'readableHighWaterMark', {
|
||||
|
Loading…
x
Reference in New Issue
Block a user