Skip to content

Commit

Permalink
added some test cases for parsing zip64 extra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Benndorf committed Jul 8, 2024
1 parent a8b057f commit 9965039
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion test/zip64.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const temp = require('temp');
const UNCOMPRESSED_SIZE = 5368709120;
const ZIP64_OFFSET = 72;
const ZIP64_SIZE = 36;
const ZIP64_EXTRA_FIELD_OFFSET = 0;

t.test('Correct uncompressed size for zip64', function (t) {
const archive = path.join(__dirname, '../testData/big.zip');
Expand Down Expand Up @@ -43,7 +44,77 @@ t.test('Correct uncompressed size for zip64', function (t) {
t.end();
});

t.test('Parse files from zip64 format correctly', function (t) {
t.test('Parse files with all zip64 extra fields correctly', function (t) {
const archive = path.join(__dirname, '../testData/zip64-allextrafields.zip');

t.test('in unzipper.Open', function(t) {
unzip.Open.file(archive)
.then(function(d) {
d.files[0].stream()
.on('vars', function(vars) {
t.same(vars.extra.uncompressedSize, ZIP64_SIZE, 'Open: Extra field');
t.same(vars.extra.compressedSize, ZIP64_SIZE, 'Open: Extra field');
t.same(vars.extra.offsetToLocalFileHeader, ZIP64_EXTRA_FIELD_OFFSET, 'Open: Extra field');
t.same(vars.uncompressedSize, ZIP64_SIZE, 'Open: File header');
t.same(vars.compressedSize, ZIP64_SIZE, 'Open: File header');
t.same(vars.offsetToLocalFileHeader, ZIP64_EXTRA_FIELD_OFFSET, 'Open: File header');
t.end();
})
.on('error', function(e) {
t.same(e.message, 'FILE_ENDED');
t.end();
});
});
});

t.test('in unzipper.extract', function (t) {
temp.mkdir('node-unzip-', function (err, dirPath) {
if (err) {
throw err;
}
fs.createReadStream(archive)
.pipe(unzip.Extract({ path: dirPath }))
.on('close', function() { t.end(); });
});
});

t.end();
});

t.test('Parse files with zip64 extra field with only offset length correctly', function (t) {
const archive = path.join(__dirname, '../testData/zip64-extrafieldoffsetlength.zip');

t.test('in unzipper.Open', function(t) {
unzip.Open.file(archive)
.then(function(d) {
d.files[0].stream()
.on('vars', function(vars) {
t.same(vars.extra.offsetToLocalFileHeader, ZIP64_EXTRA_FIELD_OFFSET, 'Open: Extra field');
t.same(vars.offsetToLocalFileHeader, ZIP64_EXTRA_FIELD_OFFSET, 'Open: File header');
t.end();
})
.on('error', function(e) {
t.same(e.message, 'FILE_ENDED');
t.end();
});
});
});

t.test('in unzipper.extract', function (t) {
temp.mkdir('node-unzip-', function (err, dirPath) {
if (err) {
throw err;
}
fs.createReadStream(archive)
.pipe(unzip.Extract({ path: dirPath }))
.on('close', function() { t.end(); });
});
});

t.end();
});

t.test('Parse files from regular zip64 format correctly', function (t) {
const archive = path.join(__dirname, '../testData/zip64.zip');

t.test('in unzipper.Open', function(t) {
Expand Down
Binary file added testData/zip64-allextrafields.zip
Binary file not shown.
Binary file added testData/zip64-extrafieldoffsetlength.zip
Binary file not shown.

0 comments on commit 9965039

Please sign in to comment.