mirror of
https://github.com/zhigang1992/adm-zip.git
synced 2026-04-29 20:35:51 +08:00
add tests for CRC fixes
This commit is contained in:
BIN
test/crc/bad_crc.zip
Normal file
BIN
test/crc/bad_crc.zip
Normal file
Binary file not shown.
BIN
test/crc/good_crc.zip
Normal file
BIN
test/crc/good_crc.zip
Normal file
Binary file not shown.
44
test/crc/index.js
Normal file
44
test/crc/index.js
Normal file
@@ -0,0 +1,44 @@
|
||||
;(function () {
|
||||
var assert = require('assert');
|
||||
var path = require('path');
|
||||
var Zip = require('../../adm-zip');
|
||||
|
||||
testGoodCrc();
|
||||
testBadCrc();
|
||||
|
||||
// Good CRC
|
||||
function testGoodCrc() {
|
||||
var goodZip = new Zip(path.join(__dirname, 'good_crc.zip'));
|
||||
var entries = goodZip.getEntries();
|
||||
assert(entries.length === 1, 'Good CRC: Test archive contains exactly 1 file');
|
||||
|
||||
var testFile = entries.filter(function (entry) {
|
||||
return entry.entryName === 'lorem_ipsum.txt';
|
||||
});
|
||||
assert(testFile.length === 1, 'Good CRC: lorem_ipsum.txt file exists as archive entry');
|
||||
|
||||
var testFileEntryName = testFile[0].entryName;
|
||||
goodZip.readAsTextAsync(testFileEntryName, function (data, err) {
|
||||
assert(!err, 'Good CRC: error object not present');
|
||||
assert(data && data.length, 'Good CRC: buffer not empty');
|
||||
});
|
||||
}
|
||||
|
||||
// Bad CRC
|
||||
function testBadCrc() {
|
||||
var badZip = new Zip(path.join(__dirname, 'bad_crc.zip'));
|
||||
var entries = badZip.getEntries();
|
||||
assert(entries.length === 1, 'Bad CRC: Test archive contains exactly 1 file');
|
||||
|
||||
var testFile = entries.filter(function (entry) {
|
||||
return entry.entryName === 'lorem_ipsum.txt';
|
||||
});
|
||||
assert(testFile.length === 1, 'Bad CRC: lorem_ipsum.txt file exists as archive entry');
|
||||
|
||||
var testFileEntryName = testFile[0].entryName;
|
||||
badZip.readAsTextAsync(testFileEntryName, function (data, err) {
|
||||
assert(data && data.length, 'Bad CRC: buffer not empty');
|
||||
assert(err, 'Bad CRC: error object present');
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user