Fix fs.WriteStream.end(data, [encoding]) throws TypeError
This commit is contained in:
parent
4ab5476e89
commit
4e7c37b87c
10
lib/fs.js
10
lib/fs.js
@ -1052,7 +1052,15 @@ WriteStream.prototype.write = function(data) {
|
|||||||
return false;
|
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.writable = false;
|
||||||
this._queue.push([fs.close, cb]);
|
this._queue.push([fs.close, cb]);
|
||||||
this.flush();
|
this.flush();
|
||||||
|
25
test/simple/test-fs-write-stream-end.js
Normal file
25
test/simple/test-fs-write-stream-end.js
Normal file
@ -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);
|
||||||
|
});
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user