mirror of https://github.com/lukechilds/node.git
Browse Source
Add string encoding option for fs.createReadStream and fs.createWriteStream. and check argument type more strictly PR-URL: https://github.com/nodejs/io.js/pull/1845 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>v2.3.1-release
Yosuke Furukawa
10 years ago
5 changed files with 103 additions and 4 deletions
@ -0,0 +1,17 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
const stream = require('stream'); |
|||
const encoding = 'base64'; |
|||
|
|||
const example = path.join(common.fixturesDir, 'x.txt'); |
|||
const assertStream = new stream.Writable({ |
|||
write: function(chunk, enc, next) { |
|||
const expected = new Buffer('xyz'); |
|||
assert(chunk.equals(expected)); |
|||
} |
|||
}); |
|||
assertStream.setDefaultEncoding(encoding); |
|||
fs.createReadStream(example, encoding).pipe(assertStream); |
@ -0,0 +1,33 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
|
|||
const example = path.join(common.fixturesDir, 'x.txt'); |
|||
|
|||
assert.doesNotThrow(function() { |
|||
fs.createReadStream(example, undefined); |
|||
}); |
|||
assert.doesNotThrow(function() { |
|||
fs.createReadStream(example, 'utf8'); |
|||
}); |
|||
assert.doesNotThrow(function() { |
|||
fs.createReadStream(example, {encoding: 'utf8'}); |
|||
}); |
|||
|
|||
assert.throws(function() { |
|||
fs.createReadStream(example, null); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createReadStream(example, 123); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createReadStream(example, 0); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createReadStream(example, true); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createReadStream(example, false); |
|||
}, /options must be a string or an object/); |
@ -0,0 +1,33 @@ |
|||
'use strict'; |
|||
const common = require('../common'); |
|||
const assert = require('assert'); |
|||
const fs = require('fs'); |
|||
const path = require('path'); |
|||
|
|||
const example = path.join(common.tmpDir, 'dummy'); |
|||
|
|||
assert.doesNotThrow(function() { |
|||
fs.createWriteStream(example, undefined); |
|||
}); |
|||
assert.doesNotThrow(function() { |
|||
fs.createWriteStream(example, 'utf8'); |
|||
}); |
|||
assert.doesNotThrow(function() { |
|||
fs.createWriteStream(example, {encoding: 'utf8'}); |
|||
}); |
|||
|
|||
assert.throws(function() { |
|||
fs.createWriteStream(example, null); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createWriteStream(example, 123); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createWriteStream(example, 0); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createWriteStream(example, true); |
|||
}, /options must be a string or an object/); |
|||
assert.throws(function() { |
|||
fs.createWriteStream(example, false); |
|||
}, /options must be a string or an object/); |
Loading…
Reference in new issue