forked from ZJONSSON/node-unzipper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractNormalize.js
More file actions
92 lines (71 loc) · 2.19 KB
/
Copy pathextractNormalize.js
File metadata and controls
92 lines (71 loc) · 2.19 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
var test = require('tap').test;
var fs = require('fs');
var os = require('os');
var path = require('path');
var temp = require('temp');
var unzip = require('../');
var Stream = require('stream');
test("Extract should normalize the path option", function (t) {
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');
temp.mkdir('node-unzip-normalize-', function (err, dirPath) {
if (err) {
throw err;
}
var filesDone = 0;
function getWriter() {
var delayStream = new Stream.Transform();
delayStream._transform = function(d, e, cb) {
setTimeout(cb, 500);
};
delayStream._flush = function(cb) {
filesDone += 1;
cb();
delayStream.emit('close');
};
return delayStream;
}
// don't use path.join, it will normalize the path which defeats
// the purpose of this test
var extractPath = os.tmpdir() + "/unzipper\\normalize/././extract\\test";
var unzipExtractor = unzip.Extract({ getWriter: getWriter, path: extractPath });
unzipExtractor.on('error', function(err) {
throw err;
});
unzipExtractor.on('close', function() {
t.same(filesDone,2);
t.end();
});
fs.createReadStream(archive).pipe(unzipExtractor);
});
});
test("Extract should resolve after normalize the path option", function (t) {
var archive = path.join(__dirname, '../testData/compressed-standard/archive.zip');
temp.mkdir('node-unzip-normalize-2-', function (err, dirPath) {
if (err) {
throw err;
}
var filesDone = 0;
function getWriter() {
var delayStream = new Stream.Transform();
delayStream._transform = function(d, e, cb) {
setTimeout(cb, 500);
};
delayStream._flush = function(cb) {
filesDone += 1;
cb();
delayStream.emit('close');
};
return delayStream;
}
var unzipExtractor = unzip.Extract({ getWriter: getWriter, path: '.' });
unzipExtractor.on('error', function(err) {
throw err;
});
unzipExtractor.on('close', function() {
t.same(filesDone,2);
t.end();
});
fs.createReadStream(archive).pipe(unzipExtractor);
});
});