Skip to content

Commit

Permalink
pass file data as callback second argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Feb 16, 2014
1 parent de2ff81 commit 2b6c0c5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.

Expand Down
12 changes: 8 additions & 4 deletions lib/zip-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2b6c0c5

Please sign in to comment.