From f19f523e1a4022d70153346a594541f75885a738 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Fri, 12 Jul 2013 23:51:04 +0400 Subject: [PATCH] fixing bugs with streams --- lib/fs-storage.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/fs-storage.js b/lib/fs-storage.js index 455d745e8..170b8efc1 100644 --- a/lib/fs-storage.js +++ b/lib/fs-storage.js @@ -42,7 +42,7 @@ function write_stream(name) { this.queue(data); }, function() { this.queue(null); - }); + }, {autoDestroy: false}); stream.pause(); fs.exists(name, function(exists) { @@ -54,10 +54,13 @@ function write_stream(name) { file.write(data); }); stream.on('end', function() { - fs.rename(tmpname, name, function(err) { - if (err) stream.emit('error', err); - stream.emit('close'); + file.on('close', function() { + fs.rename(tmpname, name, function(err) { + if (err) stream.emit('error', err); + stream.emit('close'); + }); }); + file.destroySoon(); }); stream.resume(); });