forked from EvanOxfeld/node-unzip
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathnotArchive.js
51 lines (43 loc) · 1.33 KB
/
notArchive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const test = require('tap').test;
const fs = require('fs');
const path = require('path');
const temp = require('temp');
const unzip = require('../');
const archive = path.join(__dirname, '../package.json');
test('parse a file that is not an archive', function (t) {
const unzipParser = unzip.Parse();
fs.createReadStream(archive).pipe(unzipParser);
unzipParser.on('error', function(err) {
t.ok(err.message.indexOf('invalid signature: 0x') !== -1);
t.end();
});
unzipParser.on('close', function(d) {
t.fail('Archive was parsed', d);
});
});
test('extract a file that is not an archive', function (t) {
temp.mkdir('node-unzip-', function(err, dirPath) {
if (err) {
throw err;
}
const unzipExtractor = unzip.Extract({ path: dirPath });
unzipExtractor.on('error', function(err) {
t.ok(err.message.indexOf('invalid signature: 0x') !== -1);
t.end();
});
unzipExtractor.on('close', function() {
t.fail('Archive was extracted');
});
fs.createReadStream(archive).pipe(unzipExtractor);
});
});
test('get content of a single file entry out of a file that is not an archive', function (t) {
unzip.Open.file(archive)
.then(function(d) {
t.fail('Archive was opened', d);
})
.catch(function(err) {
t.equal(err.message, 'FILE_ENDED');
t.end();
});
});