fs-write-stream-atomic
Advanced tools
Comparing version 1.0.1 to 1.0.2
23
index.js
@@ -58,11 +58,11 @@ var fs = require('graceful-fs') | ||
if (ev === 'finish') { | ||
atomicDoStuff.call(this, function (er) { | ||
if (er) | ||
cleanup.call(this, er) | ||
else | ||
fs.WriteStream.prototype.emit.call(this, 'finish') | ||
}.bind(this)) | ||
// We handle emitting finish and close after the rename. | ||
if (ev === 'close' || ev === 'finish') { | ||
if (!this.__atomicDidStuff) { | ||
atomicDoStuff.call(this, function (er) { | ||
if (er) | ||
cleanup.call(this, er) | ||
}.bind(this)) | ||
} | ||
} | ||
// close will be emitted later, once we do the rename | ||
} | ||
@@ -90,4 +90,9 @@ | ||
cb(er) | ||
fs.WriteStream.prototype.emit.call(this, 'close') | ||
// emit finish, and then close on the next tick | ||
// This makes finish/close consistent across Node versions also. | ||
fs.WriteStream.prototype.emit.call(this, 'finish') | ||
process.nextTick(function() { | ||
fs.WriteStream.prototype.emit.call(this, 'close') | ||
}.bind(this)) | ||
}.bind(this)) | ||
} |
{ | ||
"name": "fs-write-stream-atomic", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Like `fs.createWriteStream(...)`, but atomic.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7383
157