From f6185516941c486c5abc8c856185495070a734d9 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 27 Apr 2010 17:24:32 -0700 Subject: [PATCH] Remove callback argument to FileWriteStream.prototype.write --- doc/api.markdown | 5 ++--- lib/fs.js | 11 ++++++----- test/simple/test-file-write-stream.js | 6 +----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/doc/api.markdown b/doc/api.markdown index 6021e23363b..3459e12c4a1 100644 --- a/doc/api.markdown +++ b/doc/api.markdown @@ -1509,14 +1509,13 @@ Returns a new FileWriteStream object. A boolean that is `true` by default, but turns `false` after an `'error'` 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 queued up for being written later. A `'drain'` will fire after all queued data has been written. -You can also specify `callback` to be notified when the data from this write -has been flushed. The first param is `err`, the second is `bytesWritten`. +The second optional parameter specifies the encoding of for the string. ### writeStream.end() diff --git a/lib/fs.js b/lib/fs.js index 48030de4797..963ac6a7cfb 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -655,9 +655,8 @@ FileWriteStream.prototype.flush = function () { this.busy = true; - var - method = args.shift(), - cb = args.pop(); + var method = args.shift(), + cb = args.pop(); 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) { 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(); return false; diff --git a/test/simple/test-file-write-stream.js b/test/simple/test-file-write-stream.js index 51beb8c8fe7..d1efb17e7c6 100644 --- a/test/simple/test-file-write-stream.js +++ b/test/simple/test-file-write-stream.js @@ -13,7 +13,6 @@ var drain: -2, close: -1, endCb: -1, - write: -11, }; file @@ -48,10 +47,7 @@ file for (var i = 0; i < 11; i++) { (function(i) { - assert.strictEqual(false, file.write(i, function(err, bytesWritten) { - callbacks.write++; - assert.equal(new String(i).length, bytesWritten); - })); + assert.strictEqual(false, file.write(i)); })(i); }