Skip to content

Commit 1ebd839

Browse files
committed
run zip64 test as part of normal test suite. tests now fail due to abandoned large.bin pipe.
1 parent 2f8dfac commit 1ebd839

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "yet another unzip library for node",
55
"main": "index.js",
66
"scripts": {
7-
"test": "node test/zip64.js && node test/test.js",
7+
"test": "node test/test.js",
88
"test-cov": "istanbul cover test/test.js",
99
"test-travis": "istanbul cover --report lcovonly test/test.js"
1010
},

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var yauzl = require("../");
2+
var zip64 = require("./zip64");
23
var fs = require("fs");
34
var path = require("path");
45
var Pend = require("pend");
@@ -235,11 +236,15 @@ pend.go(function(cb) {
235236
});
236237
});
237238

239+
// zip64
240+
pend.go(zip64.runTest);
241+
238242
pend.wait(function() {
239243
// if you don't see this, something never happened.
240244
console.log("done");
241245
});
242246

247+
243248
function listZipFiles(dir) {
244249
var zipfilePaths = fs.readdirSync(dir).filter(function(filepath) {
245250
return /\.zip$/.exec(filepath);

test/zip64.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ var Readable = require("stream").Readable;
66
var Writable = require("stream").Writable;
77
var BufferList = require("bl");
88

9+
exports.runTest = runTest;
10+
911
function usage() {
1012
process.stdout.write("" +
1113
"zip64.js usage:\n" +
@@ -156,47 +158,58 @@ function compressFile(inputPath, outputPath) {
156158
}
157159
}
158160

159-
function runTest() {
161+
var logPrefix = "test/zip64: ";
162+
function runTest(cb) {
163+
if (cb == null) cb = function() {};
160164
makeRandomAccessReader(function(reader, size) {
161165
yauzl.fromRandomAccessReader(reader, size, function(err, zipfile) {
162166
if (err) throw err;
163167
var entryIndex = 0;
164168
zipfile.on("entry", function(entry) {
165169
var expectedContents;
166170
if (entryIndex === 0) {
167-
if (entry.fileName !== "a.txt") throw new Error("expected 'a.txt'. got '" + entry.fileName + "'.");
171+
if (entry.fileName !== "a.txt") throw new Error(logPrefix + "expected 'a.txt'. got '" + entry.fileName + "'.");
168172
expectedContents = "hello a\n";
169173
} else if (entryIndex === 1) {
170-
if (entry.fileName !== "large.bin") throw new Error("expected 'large.bin'. got '" + entry.fileName + "'.");
174+
if (entry.fileName !== "large.bin") throw new Error(logPrefix + "expected 'large.bin'. got '" + entry.fileName + "'.");
171175
expectedContents = null; // special case
172176
} else if (entryIndex === 2) {
173-
if (entry.fileName !== "b.txt") throw new Error("expected 'b.txt'. got '" + entry.fileName + "'.");
177+
if (entry.fileName !== "b.txt") throw new Error(logPrefix + "expected 'b.txt'. got '" + entry.fileName + "'.");
174178
expectedContents = "hello b\n";
175179
} else {
176-
throw new Error("too many entries");
180+
throw new Error(logPrefix + "too many entries");
177181
}
178182
entryIndex += 1;
179183
zipfile.openReadStream(entry, function(err, readStream) {
180184
if (err) throw err;
181185
if (expectedContents != null) {
182186
readStream.pipe(BufferList(function(err, data) {
183-
if (data.toString() !== expectedContents) throw new Error("expected contents:\n" + expectedContents + "\ngot:\n" + data.toString() + "\n");
184-
console.log("test/zip64: " + entry.fileName + ": PASS");
187+
if (data.toString() !== expectedContents) throw new Error(logPrefix + "expected contents:\n" + expectedContents + "\ngot:\n" + data.toString() + "\n");
188+
console.log(logPrefix + entry.fileName + ": PASS");
185189
}));
186190
} else {
187191
// make sure this is the big thing
188192
getPrefixOfLargeBinContents(function(expectedPrefixBuffer) {
189193
getPrefixOfStream(readStream, function(actualPrefixBuffer) {
190194
if (buffersEqual(expectedPrefixBuffer, actualPrefixBuffer)) {
191-
console.log("test/zip64: " + entry.fileName + ": PASS");
195+
console.log(logPrefix + entry.fileName + ": PASS");
192196
} else {
193-
throw new Error("large.bin contents read did not return expected stream")
197+
throw new Error(logPrefix + "large.bin contents read did not return expected stream")
194198
}
195199
});
196200
});
197201
}
198202
});
199203
});
204+
zipfile.on("close", function() {
205+
console.log(logPrefix + "closed");
206+
if (entryIndex === 3) {
207+
console.log(logPrefix + "pass");
208+
cb();
209+
} else {
210+
throw new Error(logPrefix + "closed prematurely");
211+
}
212+
});
200213
});
201214
});
202215
}
@@ -251,4 +264,4 @@ function buffersEqual(buf1, buf2) {
251264
return true;
252265
}
253266

254-
cli();
267+
if (require.main === module) cli();

0 commit comments

Comments
 (0)