UNPKG

1.81 kBJavaScriptView Raw
1'use strict';
2
3var test = require('tap').test;
4var fs = require('fs');
5var path = require('path');
6var fstream = require('fstream');
7var temp = require('temp');
8var dirdiff = require('dirdiff');
9var unzip = require('../');
10
11test("uncompressed archive", function (t) {
12 var archive = path.join(__dirname, '../testData/uncompressed/archive.zip');
13
14 temp.mkdir('node-unzip-', function (err, dirPath) {
15 if (err) {
16 throw err;
17 }
18 var unzipExtractor = unzip.Extract({ path: dirPath });
19 unzipExtractor.on('error', function(err) {
20 throw err;
21 });
22 unzipExtractor.on('end', testExtractionResults);
23
24 fs.createReadStream(archive).pipe(unzipExtractor);
25
26 function testExtractionResults() {
27 dirdiff(path.join(__dirname, '../testData/uncompressed/inflated'), dirPath, {
28 fileContents: true
29 }, function (err, diffs) {
30 if (err) {
31 throw err;
32 }
33 t.equal(0, diffs.length, 'extracted directory contents');
34 t.end();
35 });
36 }
37 });
38});
39
40test("compressed archive", function (t) {
41 var archive = path.join(__dirname, '../testData/compressed/archive.zip');
42
43 temp.mkdir('node-unzip-', function (err, dirPath) {
44 if (err) {
45 throw err;
46 }
47 var unzipExtractor = unzip.Extract({ path: dirPath });
48 unzipExtractor.on('error', function(err) {
49 throw err;
50 });
51 unzipExtractor.on('end', testExtractionResults);
52
53 fs.createReadStream(archive).pipe(unzipExtractor);
54
55 function testExtractionResults() {
56 dirdiff(path.join(__dirname, '../testData/compressed/inflated'), dirPath, {
57 fileContents: true
58 }, function (err, diffs) {
59 if (err) {
60 throw err;
61 }
62 t.equal(0, diffs.length, 'extracted directory contents');
63 t.end();
64 });
65 }
66 });
67});