Skip to content

Commit

Permalink
run zip64 test as part of normal test suite. tests now fail due to ab…
Browse files Browse the repository at this point in the history
…andoned large.bin pipe.
  • Loading branch information
thejoshwolfe committed Dec 31, 2015
1 parent 2f8dfac commit 1ebd839
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "yet another unzip library for node",
"main": "index.js",
"scripts": {
"test": "node test/zip64.js && node test/test.js",
"test": "node test/test.js",
"test-cov": "istanbul cover test/test.js",
"test-travis": "istanbul cover --report lcovonly test/test.js"
},
Expand Down
5 changes: 5 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var yauzl = require("../");
var zip64 = require("./zip64");
var fs = require("fs");
var path = require("path");
var Pend = require("pend");
Expand Down Expand Up @@ -235,11 +236,15 @@ pend.go(function(cb) {
});
});

// zip64
pend.go(zip64.runTest);

pend.wait(function() {
// if you don't see this, something never happened.
console.log("done");
});


function listZipFiles(dir) {
var zipfilePaths = fs.readdirSync(dir).filter(function(filepath) {
return /\.zip$/.exec(filepath);
Expand Down
33 changes: 23 additions & 10 deletions test/zip64.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var Readable = require("stream").Readable;
var Writable = require("stream").Writable;
var BufferList = require("bl");

exports.runTest = runTest;

function usage() {
process.stdout.write("" +
"zip64.js usage:\n" +
Expand Down Expand Up @@ -156,47 +158,58 @@ function compressFile(inputPath, outputPath) {
}
}

function runTest() {
var logPrefix = "test/zip64: ";
function runTest(cb) {
if (cb == null) cb = function() {};
makeRandomAccessReader(function(reader, size) {
yauzl.fromRandomAccessReader(reader, size, function(err, zipfile) {
if (err) throw err;
var entryIndex = 0;
zipfile.on("entry", function(entry) {
var expectedContents;
if (entryIndex === 0) {
if (entry.fileName !== "a.txt") throw new Error("expected 'a.txt'. got '" + entry.fileName + "'.");
if (entry.fileName !== "a.txt") throw new Error(logPrefix + "expected 'a.txt'. got '" + entry.fileName + "'.");
expectedContents = "hello a\n";
} else if (entryIndex === 1) {
if (entry.fileName !== "large.bin") throw new Error("expected 'large.bin'. got '" + entry.fileName + "'.");
if (entry.fileName !== "large.bin") throw new Error(logPrefix + "expected 'large.bin'. got '" + entry.fileName + "'.");
expectedContents = null; // special case
} else if (entryIndex === 2) {
if (entry.fileName !== "b.txt") throw new Error("expected 'b.txt'. got '" + entry.fileName + "'.");
if (entry.fileName !== "b.txt") throw new Error(logPrefix + "expected 'b.txt'. got '" + entry.fileName + "'.");
expectedContents = "hello b\n";
} else {
throw new Error("too many entries");
throw new Error(logPrefix + "too many entries");
}
entryIndex += 1;
zipfile.openReadStream(entry, function(err, readStream) {
if (err) throw err;
if (expectedContents != null) {
readStream.pipe(BufferList(function(err, data) {
if (data.toString() !== expectedContents) throw new Error("expected contents:\n" + expectedContents + "\ngot:\n" + data.toString() + "\n");
console.log("test/zip64: " + entry.fileName + ": PASS");
if (data.toString() !== expectedContents) throw new Error(logPrefix + "expected contents:\n" + expectedContents + "\ngot:\n" + data.toString() + "\n");
console.log(logPrefix + entry.fileName + ": PASS");
}));
} else {
// make sure this is the big thing
getPrefixOfLargeBinContents(function(expectedPrefixBuffer) {
getPrefixOfStream(readStream, function(actualPrefixBuffer) {
if (buffersEqual(expectedPrefixBuffer, actualPrefixBuffer)) {
console.log("test/zip64: " + entry.fileName + ": PASS");
console.log(logPrefix + entry.fileName + ": PASS");
} else {
throw new Error("large.bin contents read did not return expected stream")
throw new Error(logPrefix + "large.bin contents read did not return expected stream")
}
});
});
}
});
});
zipfile.on("close", function() {
console.log(logPrefix + "closed");
if (entryIndex === 3) {
console.log(logPrefix + "pass");
cb();
} else {
throw new Error(logPrefix + "closed prematurely");
}
});
});
});
}
Expand Down Expand Up @@ -251,4 +264,4 @@ function buffersEqual(buf1, buf2) {
return true;
}

cli();
if (require.main === module) cli();

0 comments on commit 1ebd839

Please sign in to comment.