aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-07-29 06:44:33 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-28 15:44:33 -0700
commit9b91e3c1a25548217d846932c14e3ccdd0942a99 (patch)
tree230806bbe73638a1edd3334af6a3acab119b3429 /src
parent7a1ebec26fc1a3f480fca5e5508d5ceda5a2ebcf (diff)
downloadbun-9b91e3c1a25548217d846932c14e3ccdd0942a99.tar.gz
bun-9b91e3c1a25548217d846932c14e3ccdd0942a99.tar.zst
bun-9b91e3c1a25548217d846932c14e3ccdd0942a99.zip
fix the chunk boundary (`node:stream:createReadStream`) (#3853)
* fix the slice boundary. Close: #3668 * Add more boundary test case. * fix end is 0.
Diffstat (limited to 'src')
-rw-r--r--src/js/node/fs.js8
-rw-r--r--src/js/out/modules/node/fs.js8
2 files changed, 8 insertions, 8 deletions
diff --git a/src/js/node/fs.js b/src/js/node/fs.js
index aa03ffc5c..d287809c6 100644
--- a/src/js/node/fs.js
+++ b/src/js/node/fs.js
@@ -540,15 +540,15 @@ ReadStream = (function (InternalReadStream) {
chunk = chunk.slice(-n);
var [_, ...rest] = arguments;
this.pos = this.bytesRead;
- if (this.end && this.bytesRead >= this.end) {
- chunk = chunk.slice(0, this.end - this.start);
+ if (this.end !== undefined && this.bytesRead > this.end) {
+ chunk = chunk.slice(0, this.end - this.start + 1);
}
return super.push(chunk, ...rest);
}
var end = this.end;
// This is multi-chunk read case where we go passed the end of the what we want to read in the last chunk
- if (end && this.bytesRead >= end) {
- chunk = chunk.slice(0, end - currPos);
+ if (end !== undefined && this.bytesRead > end) {
+ chunk = chunk.slice(0, end - currPos + 1);
var [_, ...rest] = arguments;
this.pos = this.bytesRead;
return super.push(chunk, ...rest);
diff --git a/src/js/out/modules/node/fs.js b/src/js/out/modules/node/fs.js
index 720d03134..7bb354dea 100644
--- a/src/js/out/modules/node/fs.js
+++ b/src/js/out/modules/node/fs.js
@@ -310,13 +310,13 @@ ReadStream = function(InternalReadStream) {
var n = this.bytesRead - currPos;
chunk = chunk.slice(-n);
var [_, ...rest] = arguments;
- if (this.pos = this.bytesRead, this.end && this.bytesRead >= this.end)
- chunk = chunk.slice(0, this.end - this.start);
+ if (this.pos = this.bytesRead, this.end !== void 0 && this.bytesRead > this.end)
+ chunk = chunk.slice(0, this.end - this.start + 1);
return super.push(chunk, ...rest);
}
var end = this.end;
- if (end && this.bytesRead >= end) {
- chunk = chunk.slice(0, end - currPos);
+ if (end !== void 0 && this.bytesRead > end) {
+ chunk = chunk.slice(0, end - currPos + 1);
var [_, ...rest] = arguments;
return this.pos = this.bytesRead, super.push(chunk, ...rest);
}