parent
ba0892ba91
commit
493a6bb19a
@ -1125,8 +1125,13 @@ var ReadStream = fs.ReadStream = function(path, options) {
|
|||||||
if (this.encoding) this.setEncoding(this.encoding);
|
if (this.encoding) this.setEncoding(this.encoding);
|
||||||
|
|
||||||
if (this.start !== undefined) {
|
if (this.start !== undefined) {
|
||||||
|
if ('number' !== typeof this.start) {
|
||||||
|
throw TypeError('start must be a Number');
|
||||||
|
}
|
||||||
if (this.end === undefined) {
|
if (this.end === undefined) {
|
||||||
this.end = Infinity;
|
this.end = Infinity;
|
||||||
|
} else if ('number' !== typeof this.end) {
|
||||||
|
throw TypeError('end must be a Number');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.start > this.end) {
|
if (this.start > this.end) {
|
||||||
@ -1313,6 +1318,9 @@ var WriteStream = fs.WriteStream = function(path, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.start !== undefined) {
|
if (this.start !== undefined) {
|
||||||
|
if ('number' !== typeof this.start) {
|
||||||
|
throw TypeError('start must be a Number');
|
||||||
|
}
|
||||||
if (this.start < 0) {
|
if (this.start < 0) {
|
||||||
throw new Error('start must be >= zero');
|
throw new Error('start must be >= zero');
|
||||||
}
|
}
|
||||||
|
24
test/simple/test-fs-non-number-arguments-throw.js
Normal file
24
test/simple/test-fs-non-number-arguments-throw.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
var assert = require('assert'),
|
||||||
|
fs = require('fs'),
|
||||||
|
saneEmitter,
|
||||||
|
sanity = 'ire(\'assert\')';
|
||||||
|
|
||||||
|
saneEmitter = fs.createReadStream(__filename, { start: 17, end: 29 });
|
||||||
|
|
||||||
|
assert.throws(function () {
|
||||||
|
fs.createReadStream(__filename, { start: "17", end: 29 });
|
||||||
|
}, "start as string didn't throw an error for createReadStream");
|
||||||
|
|
||||||
|
assert.throws(function () {
|
||||||
|
fs.createReadStream(__filename, { start: 17, end: "29" });
|
||||||
|
}, "end as string didn't throw an error");
|
||||||
|
|
||||||
|
assert.throws(function () {
|
||||||
|
fs.createWriteStream(__filename, { start: "17" });
|
||||||
|
}, "start as string didn't throw an error for createWriteStream");
|
||||||
|
|
||||||
|
saneEmitter.on('data', function (data) {
|
||||||
|
// a sanity check when using numbers instead of strings
|
||||||
|
assert.strictEqual(sanity, data.toString('utf8'), 'read ' +
|
||||||
|
data.toString('utf8') + ' instead of ' + sanity);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user