Skip to content

Commit 38a025f

Browse files
committed
fix double-write error when using only addBuffer(). closes #12
1 parent 681dadc commit 38a025f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function ZipFile() {
1414
this.outputStream = new PassThrough();
1515
this.entries = [];
1616
this.outputStreamCursor = 0;
17-
this.ended = false;
17+
this.ended = false; // .end() sets this
18+
this.allDone = false; // set when we've written the last bytes
1819
}
1920

2021
ZipFile.prototype.addFile = function(realPath, metadataPath, options) {
@@ -142,6 +143,7 @@ function pumpFileDataReadStream(self, entry, readStream) {
142143
}
143144

144145
function pumpEntries(self) {
146+
if (self.allDone) return;
145147
// first check if finalSize is finally known
146148
if (self.ended && self.finalSizeCallback != null) {
147149
var finalSize = calculateFinalSize(self);
@@ -181,6 +183,7 @@ function pumpEntries(self) {
181183
});
182184
writeToOutputStream(self, getEndOfCentralDirectoryRecord(self));
183185
self.outputStream.end();
186+
self.allDone = true;
184187
}
185188
}
186189
}

0 commit comments

Comments
 (0)