From 4a7562d28fe8fb2de36c5d5ccf9e80cbf1a67d48 Mon Sep 17 00:00:00 2001 From: Marco Rogers Date: Mon, 27 Sep 2010 13:34:16 -0400 Subject: [PATCH] fix encoding option on ReadStream, updated test --- lib/fs.js | 2 ++ test/simple/test-fs-read-stream.js | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) 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;