summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2011-12-13 16:30:53 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2011-12-13 16:31:12 +0100
commitb1b3dc62ff13f5bd5be1ec75630b0308c48d6399 (patch)
tree6d8c0e394a90f4ff56100b2458dd73db80514d11
parente90db17392c7749bc44235dd9b7f69b298e481a9 (diff)
downloadnode-b1b3dc62ff13f5bd5be1ec75630b0308c48d6399.tar.gz
fs: handle fractional or NaN ReadStream buffer size
Fixes #2320.
-rw-r--r--lib/fs.js2
-rw-r--r--test/simple/test-fs-read-stream.js9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/fs.js b/lib/fs.js
index e9efece32..61adbdf9b 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -1092,7 +1092,7 @@ ReadStream.prototype._read = function() {
// thread pool another read() finishes up the pool, and allocates a new
// one.
var thisPool = pool;
- var toRead = Math.min(pool.length - pool.used, this.bufferSize);
+ var toRead = Math.min(pool.length - pool.used, ~~this.bufferSize);
var start = pool.used;
if (this.pos !== undefined) {
diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js
index 63e9b1ae4..dbb5fbf84 100644
--- a/test/simple/test-fs-read-stream.js
+++ b/test/simple/test-fs-read-stream.js
@@ -133,6 +133,15 @@ file5.on('end', function() {
assert.equal(file5.data, 'yz\n');
});
+// https://github.com/joyent/node/issues/2320
+var file6 = fs.createReadStream(rangeFile, {bufferSize: 1.23, start: 1});
+file6.data = '';
+file6.on('data', function(data) {
+ file6.data += data.toString('utf-8');
+});
+file6.on('end', function() {
+ assert.equal(file6.data, 'yz\n');
+});
assert.throws(function() {
fs.createReadStream(rangeFile, {start: 10, end: 2});