Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function File (options) {
// Destination is not an HTTP request

if (self.src && !self.dest) {
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path).on('close',function(){self.close()}))
} else if (self.dest && !self.src) {
fs.createReadStream(self.path).pipe(self.dest)
}
Expand All @@ -161,7 +161,7 @@ function File (options) {

if (!self.src && !self.dest) {
if (self.buffers.length > 0) {
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path))
stream.Stream.prototype.pipe.call(self, fs.createWriteStream(self.path).on('close',function(){self.close()}))
} else if (self.listeners('data').length > 0) {
fs.createReadStream(self.path).pipe(self.dest)
} else {
Expand Down Expand Up @@ -196,6 +196,9 @@ File.prototype.end = function (chunk) {
this.emit('end')
}
}
File.prototype.close = function (chunk) {
this.emit('close')
}

module.exports = function (options) {
return new File(options)
Expand Down