Skip to content

Commit

Permalink
var adjustments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ctalkington committed Apr 1, 2014
1 parent c7eeb2c commit c5257fb
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions lib/zip-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,34 @@ ZipStream.prototype._afterAppend = function(file) {
ZipStream.prototype._appendBuffer = function(source, data, callback) {
var self = this;

var file = data;
file.offset = self.offset;
data.offset = self.offset;

self.write(headers.encode('file', file));
self.write(headers.encode('file', data));

function onend() {
self.write(headers.encode('fileDescriptor', file));
self.write(headers.encode('fileDescriptor', data));

self._afterAppend(file);
self._afterAppend(data);

callback(null, file);
callback(null, data);
}

if (file.store || source.length === 0) {
file.uncompressedSize = source.length;
file.compressedSize = file.uncompressedSize;
file.crc32 = crc32.unsigned(source);
if (data.store || source.length === 0) {
data.uncompressedSize = source.length;
data.compressedSize = data.uncompressedSize;
data.crc32 = crc32.unsigned(source);

self.write(source);

onend();
} else {
var processStream = self._newProcessStream(file.store);
var processStream = self._newProcessStream(data.store);
processStream.once('error', callback);

processStream.once('end', function() {
file.crc32 = processStream.digest;
file.uncompressedSize = processStream.rawSize;
file.compressedSize = processStream.compressedSize || processStream.rawSize;
data.crc32 = processStream.digest;
data.uncompressedSize = processStream.rawSize;
data.compressedSize = processStream.compressedSize || processStream.rawSize;

onend();
});
Expand All @@ -119,26 +118,25 @@ ZipStream.prototype._appendBuffer = function(source, data, callback) {
ZipStream.prototype._appendStream = function(source, data, callback) {
var self = this;

var file = data;
file.offset = self.offset;
data.offset = self.offset;

self.write(headers.encode('file', file));
self.write(headers.encode('file', data));

function onend() {
self.write(headers.encode('fileDescriptor', file));
self.write(headers.encode('fileDescriptor', data));

self._afterAppend(file);
self._afterAppend(data);

callback(null, file);
callback(null, data);
}

var processStream = self._newProcessStream(file.store);
var processStream = self._newProcessStream(data.store);
processStream.once('error', callback);

processStream.once('end', function() {
file.crc32 = processStream.digest;
file.uncompressedSize = processStream.rawSize;
file.compressedSize = processStream.compressedSize || processStream.rawSize;
data.crc32 = processStream.digest;
data.uncompressedSize = processStream.rawSize;
data.compressedSize = processStream.compressedSize || processStream.rawSize;

onend();
});
Expand Down

0 comments on commit c5257fb

Please sign in to comment.