diff --git a/lib/fs.js b/lib/fs.js index 286dea2654..0bbb14b6d4 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -635,6 +635,8 @@ var ReadStream = fs.ReadStream = function(path, options) { this[key] = options[key]; } + if(this.encoding) this.setEncoding(this.encoding); + if (this.start !== undefined || this.end !== undefined) { if (this.start === undefined || this.end === undefined) { this.emit('error', diff --git a/test/simple/test-fs-read-stream.js b/test/simple/test-fs-read-stream.js index ab8cbc5a4e..cc1b6cd66a 100644 --- a/test/simple/test-fs-read-stream.js +++ b/test/simple/test-fs-read-stream.js @@ -60,9 +60,8 @@ file2.destroy(function(err) { callbacks.destroy++; }); -var file3 = fs.createReadStream(fn); +var file3 = fs.createReadStream(fn, {encoding: 'utf8'}); file3.length = 0; -file3.setEncoding('utf8'); file3.addListener('data', function(data) { assert.equal("string", typeof(data)); file3.length += data.length;