From 2b6c0c59042c22471499ed7b62cea65fd146ba8a Mon Sep 17 00:00:00 2001 From: Chris Talkington Date: Sat, 15 Feb 2014 22:46:00 -0600 Subject: [PATCH] pass file data as callback second argument. --- README.md | 4 ++-- lib/zip-stream.js | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7ab9bf17..b9aa1123 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ archive.on('error', function(err) { // pipe archive where you want it (ie fs, http, etc) // listen to the destination's end, close, or finish event -archive.entry('string contents', { name: 'string.txt' }, function(err) { +archive.entry('string contents', { name: 'string.txt' }, function(err, file) { if (err) throw err; archive.finalize(); @@ -36,7 +36,7 @@ archive.entry('string contents', { name: 'string.txt' }, function(err) { ### Instance API -#### entry(input, data, callback(err)) +#### entry(input, data, callback(err, file)) Appends an input source (text string, buffer, or stream) to the instance. When the instance has received, processed, and emitted the input, the callback is fired. diff --git a/lib/zip-stream.js b/lib/zip-stream.js index 244088fb..482f5614 100644 --- a/lib/zip-stream.js +++ b/lib/zip-stream.js @@ -74,7 +74,7 @@ ZipStream.prototype._appendBuffer = function(source, data, callback) { self._afterAppend(file); - callback(null); + callback(null, file); } if (file.store || source.length === 0) { @@ -87,7 +87,9 @@ ZipStream.prototype._appendBuffer = function(source, data, callback) { onend(); } else { var processStream = self._newProcessStream(file.store); - processStream.once('error', callback); + processStream.once('error', function(err) { + callback(err, file); + }); processStream.once('end', function() { file.crc32 = processStream.digest; @@ -116,11 +118,13 @@ ZipStream.prototype._appendStream = function(source, data, callback) { self._afterAppend(file); - callback(null); + callback(null, file); } var processStream = self._newProcessStream(file.store); - processStream.once('error', callback); + processStream.once('error', function(err) { + callback(err, file); + }); processStream.once('end', function() { file.crc32 = processStream.digest;