From 543f748b9a4437305a7f87c831505619a7e8a208 Mon Sep 17 00:00:00 2001 From: Gabriel Petrovay Date: Tue, 2 Dec 2014 18:07:22 +0100 Subject: [PATCH 1/2] Exposing file writable stream errors through the form --- lib/file.js | 4 ++++ lib/incoming_form.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/file.js b/lib/file.js index e34c10e4..483d1257 100644 --- a/lib/file.js +++ b/lib/file.js @@ -31,7 +31,11 @@ module.exports = File; util.inherits(File, EventEmitter); File.prototype.open = function() { + var self = this; this._writeStream = new WriteStream(this.path); + this._writeStream.on('error', function(err) { + self.emit('error', err); + }) }; File.prototype.toJSON = function() { diff --git a/lib/incoming_form.js b/lib/incoming_form.js index 27b9aedb..47d651db 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -207,6 +207,10 @@ IncomingForm.prototype.handlePart = function(part) { hash: self.hash }); + file.on('error', function(err) { + self.emit('error', err); + }); + this.emit('fileBegin', part.name, file); file.open(); From e11d092f185809d5c74dc5775e53f51e77e9596a Mon Sep 17 00:00:00 2001 From: Gabriel Petrovay Date: Tue, 2 Dec 2014 18:26:28 +0100 Subject: [PATCH 2/2] The File is an EventEmmiter, isn't it? --- lib/incoming_form.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/incoming_form.js b/lib/incoming_form.js index 47d651db..29de02d1 100644 --- a/lib/incoming_form.js +++ b/lib/incoming_form.js @@ -207,10 +207,6 @@ IncomingForm.prototype.handlePart = function(part) { hash: self.hash }); - file.on('error', function(err) { - self.emit('error', err); - }); - this.emit('fileBegin', part.name, file); file.open(); @@ -233,6 +229,10 @@ IncomingForm.prototype.handlePart = function(part) { self._maybeEnd(); }); }); + + file.on('error', function(err) { + self.emit('error', err); + }); }; function dummyParser(self) {