Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fs: handle fractional or NaN ReadStream buffer size
Browse files Browse the repository at this point in the history
Fixes #2320.
  • Loading branch information
bnoordhuis committed Dec 13, 2011
1 parent e90db17 commit b1b3dc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fs.js
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions test/simple/test-fs-read-stream.js
Expand Up @@ -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});
Expand Down

0 comments on commit b1b3dc6

Please sign in to comment.