Browse Source

Do not emit WriteStream's drain event before ws.write has been called.

v0.7.4-release
Tobie Langel 15 years ago
committed by Ryan Dahl
parent
commit
ccf4afa256
  1. 7
      lib/fs.js
  2. 9
      test/simple/test-fs-write-stream.js

7
lib/fs.js

@ -840,7 +840,10 @@ WriteStream.prototype.flush = function () {
var self = this;
var args = this._queue.shift();
if (!args) return self.emit('drain');
if (!args) {
if (this.drainable) { self.emit('drain'); }
return;
}
this.busy = true;
@ -896,6 +899,8 @@ WriteStream.prototype.write = function (data) {
throw new Error('stream not writeable');
}
this.drainable = true;
var cb;
if (typeof(arguments[arguments.length-1]) == 'function') {
cb = arguments[arguments.length-1];

9
test/simple/test-fs-write-stream.js

@ -17,3 +17,12 @@ var file = path.join(common.fixturesDir, "write.txt");
stream.destroy();
})();
(function() {
var stream = fs.createWriteStream(file);
stream.addListener('drain', function () {
assert.fail('"drain" event must not be emitted before stream.write() has been called at least once.')
});
stream.destroy();
})();

Loading…
Cancel
Save