joyent/node — Issue #2554: confusing error for `fs.createReadStream(path, { start: "90", end: "99"})`
Author: coolaj86
Created: 2012-01-17 07:21:57+00:00
State: open

There are several places in `fs.js` where `this.pos += {{whatever}}` will result in string concatenation and throw a confusing error:

binding.read(fd, buffer, offset, length, position, wrapper);
^
Error: Length extends beyond buffer

I propose that `this.pos = parseInt(this.start, 10)` be used (in the if block around line 1040 in fs.js) instead of `this.pos = this.start`.

I'll be happy to submit the pull request if you like.

In context:

if (this.start !== undefined) {
if (this.end === undefined) {
this.end = Infinity;
}

if (this.start > this.end) {
throw new Error('start must be <= end');
}

this.pos = parseInt(this.start, 10);
}

...