|
| 1 | +;(function () { |
| 2 | + var assert = require('assert'); |
| 3 | + var path = require('path'); |
| 4 | + var Zip = require('../../adm-zip'); |
| 5 | + |
| 6 | + testGoodCrc(); |
| 7 | + testBadCrc(); |
| 8 | + |
| 9 | + // Good CRC |
| 10 | + function testGoodCrc() { |
| 11 | + var goodZip = new Zip(path.join(__dirname, 'good_crc.zip')); |
| 12 | + var entries = goodZip.getEntries(); |
| 13 | + assert(entries.length === 1, 'Good CRC: Test archive contains exactly 1 file'); |
| 14 | + |
| 15 | + var testFile = entries.filter(function (entry) { |
| 16 | + return entry.entryName === 'lorem_ipsum.txt'; |
| 17 | + }); |
| 18 | + assert(testFile.length === 1, 'Good CRC: lorem_ipsum.txt file exists as archive entry'); |
| 19 | + |
| 20 | + var testFileEntryName = testFile[0].entryName; |
| 21 | + goodZip.readAsTextAsync(testFileEntryName, function (data, err) { |
| 22 | + assert(!err, 'Good CRC: error object not present'); |
| 23 | + assert(data && data.length, 'Good CRC: buffer not empty'); |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + // Bad CRC |
| 28 | + function testBadCrc() { |
| 29 | + var badZip = new Zip(path.join(__dirname, 'bad_crc.zip')); |
| 30 | + var entries = badZip.getEntries(); |
| 31 | + assert(entries.length === 1, 'Bad CRC: Test archive contains exactly 1 file'); |
| 32 | + |
| 33 | + var testFile = entries.filter(function (entry) { |
| 34 | + return entry.entryName === 'lorem_ipsum.txt'; |
| 35 | + }); |
| 36 | + assert(testFile.length === 1, 'Bad CRC: lorem_ipsum.txt file exists as archive entry'); |
| 37 | + |
| 38 | + var testFileEntryName = testFile[0].entryName; |
| 39 | + badZip.readAsTextAsync(testFileEntryName, function (data, err) { |
| 40 | + assert(data && data.length, 'Bad CRC: buffer not empty'); |
| 41 | + assert(err, 'Bad CRC: error object present'); |
| 42 | + }); |
| 43 | + } |
| 44 | +})(); |
0 commit comments