Created
March 1, 2011 15:39
-
-
Save koichik/849307 to your computer and use it in GitHub Desktop.
Fix fs.WriteStream.end(data, [encoding]) throws TypeError
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From edaad49acce5ae54ab859ec4fbf8002f76d80585 Mon Sep 17 00:00:00 2001 | |
From: koichik <koichik@improvement.jp> | |
Date: Wed, 2 Mar 2011 00:35:32 +0900 | |
Subject: [PATCH] Fix fs.WriteStream.end(data, [encoding]) throws TypeError | |
--- | |
lib/fs.js | 10 +++++++++- | |
test/simple/test-fs-write-stream-end.js | 25 +++++++++++++++++++++++++ | |
2 files changed, 34 insertions(+), 1 deletions(-) | |
create mode 100644 test/simple/test-fs-write-stream-end.js | |
diff --git a/lib/fs.js b/lib/fs.js | |
index 8350c61..0ae4550 100644 | |
--- a/lib/fs.js | |
+++ b/lib/fs.js | |
@@ -1052,7 +1052,15 @@ WriteStream.prototype.write = function(data) { | |
return false; | |
}; | |
-WriteStream.prototype.end = function(cb) { | |
+WriteStream.prototype.end = function(data, encoding, cb) { | |
+ if (typeof(data) === 'function') { | |
+ cb = data; | |
+ } else if (typeof(encoding) === 'function') { | |
+ cb = encoding; | |
+ this.write(data); | |
+ } else if (arguments.length > 0) { | |
+ this.write(data, encoding); | |
+ } | |
this.writable = false; | |
this._queue.push([fs.close, cb]); | |
this.flush(); | |
diff --git a/test/simple/test-fs-write-stream-end.js b/test/simple/test-fs-write-stream-end.js | |
new file mode 100644 | |
index 0000000..4c25620 | |
--- /dev/null | |
+++ b/test/simple/test-fs-write-stream-end.js | |
@@ -0,0 +1,25 @@ | |
+var common = require('../common'); | |
+var assert = require('assert'); | |
+ | |
+var path = require('path'), | |
+ fs = require('fs'); | |
+ | |
+var writeEndOk = false; | |
+(function() { | |
+ debugger; | |
+ var file = path.join(common.tmpDir, 'write-end-test.txt'); | |
+ var stream = fs.createWriteStream(file); | |
+ | |
+ stream.end('a\n', 'utf8', function() { | |
+ var content = fs.readFileSync(file, 'utf8'); | |
+ assert.equal(content, 'a\n'); | |
+ writeEndOk = true; | |
+ }); | |
+ | |
+})(); | |
+ | |
+ | |
+process.on('exit', function() { | |
+ assert.ok(writeEndOk); | |
+}); | |
+ | |
-- | |
1.7.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment