From 5c7fd50a2d51de1bd76e9233d35effcf69c40b7a Mon Sep 17 00:00:00 2001 From: helloyou2012 Date: Mon, 19 Apr 2021 18:01:49 +0800 Subject: [PATCH] stream: the position of _read() is wrong Fixes: https://github.com/nodejs/node/issues/33940 --- lib/internal/fs/streams.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 57c2304fca82cc..b388bad80c74a5 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -255,6 +255,10 @@ ReadStream.prototype._read = function(n) { if (er) { errorOrDestroy(this, er); } else if (bytesRead > 0) { + if (this.pos !== undefined) { + this.pos += bytesRead; + } + this.bytesRead += bytesRead; if (bytesRead !== buf.length) { @@ -271,10 +275,6 @@ ReadStream.prototype._read = function(n) { this.push(null); } }); - - if (this.pos !== undefined) { - this.pos += n; - } }; ReadStream.prototype._destroy = function(err, cb) {