Remove callback argument to FileWriteStream.prototype.write

This commit is contained in:
Ryan Dahl 2010-04-27 17:24:32 -07:00
parent d1b352e4b3
commit f618551694
3 changed files with 9 additions and 13 deletions

View File

@ -1509,14 +1509,13 @@ Returns a new FileWriteStream object.
A boolean that is `true` by default, but turns `false` after an `'error'` A boolean that is `true` by default, but turns `false` after an `'error'`
occurred or `end()` / `destroy()` was called. occurred or `end()` / `destroy()` was called.
### writeStream.write(data) ### writeStream.write(data, encoding='utf8')
Returns `true` if the data was flushed to the kernel, and `false` if it was Returns `true` if the data was flushed to the kernel, and `false` if it was
queued up for being written later. A `'drain'` will fire after all queued data queued up for being written later. A `'drain'` will fire after all queued data
has been written. has been written.
You can also specify `callback` to be notified when the data from this write The second optional parameter specifies the encoding of for the string.
has been flushed. The first param is `err`, the second is `bytesWritten`.
### writeStream.end() ### writeStream.end()

View File

@ -655,9 +655,8 @@ FileWriteStream.prototype.flush = function () {
this.busy = true; this.busy = true;
var var method = args.shift(),
method = args.shift(), cb = args.pop();
cb = args.pop();
var self = this; var self = this;
@ -703,12 +702,14 @@ FileWriteStream.prototype.flush = function () {
}; };
FileWriteStream.prototype.write = function(data, cb) { FileWriteStream.prototype.write = function(data, encoding) {
if (!this.writeable) { if (!this.writeable) {
throw new Error('stream not writeable'); throw new Error('stream not writeable');
} }
this._queue.push([fs.write, data, undefined, this.encoding, cb]); // TODO handle Buffer
this._queue.push([fs.write, data, undefined, encoding || 'utf8', null]);
this.flush(); this.flush();
return false; return false;

View File

@ -13,7 +13,6 @@ var
drain: -2, drain: -2,
close: -1, close: -1,
endCb: -1, endCb: -1,
write: -11,
}; };
file file
@ -48,10 +47,7 @@ file
for (var i = 0; i < 11; i++) { for (var i = 0; i < 11; i++) {
(function(i) { (function(i) {
assert.strictEqual(false, file.write(i, function(err, bytesWritten) { assert.strictEqual(false, file.write(i));
callbacks.write++;
assert.equal(new String(i).length, bytesWritten);
}));
})(i); })(i);
} }