Skip to content

Commit be3c555

Browse files
authoredJun 22, 2020
fix: extract from url not working (#195)
* fix: extract from url not working * test: extract from url
1 parent 36add2f commit be3c555

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
 

‎lib/Open/directory.js

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ module.exports = function centralDirectory(source, options) {
151151

152152
vars.extract = function(opts) {
153153
if (!opts || !opts.path) throw new Error('PATH_MISSING');
154+
// make sure path is normalized before using it
155+
opts.path = path.resolve(path.normalize(opts.path));
154156
return vars.files.then(function(files) {
155157
return Promise.map(files, function(entry) {
156158
if (entry.type == 'Directory') return;

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"devDependencies": {
3838
"aws-sdk": "^2.77.0",
3939
"dirdiff": ">= 0.0.1 < 1",
40+
"fs-extra": "^9.0.0",
4041
"iconv-lite": "^0.4.24",
4142
"request": "^2.88.0",
4243
"stream-buffers": ">= 0.2.5 < 1",

‎test/extractFromUrl.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
3+
const test = require("tap").test;
4+
const fs = require("fs-extra");
5+
const unzip = require("../");
6+
const os = require("os");
7+
const request = require("request");
8+
9+
test("extract zip from url", function (t) {
10+
const extractPath = os.tmpdir() + "/node-unzip-extract-fromURL"; // Not using path resolve, cause it should be resolved in extract() function
11+
unzip.Open.url(
12+
request,
13+
"https://github.com/h5bp/html5-boilerplate/releases/download/v7.3.0/html5-boilerplate_v7.3.0.zip"
14+
)
15+
.then((d) => d.extract({ path: extractPath }))
16+
.then((d) => {
17+
const dirFiles = fs.readdirSync(extractPath);
18+
const isPassing =
19+
dirFiles.length > 10 &&
20+
dirFiles.indexOf("css") > -1 &&
21+
dirFiles.indexOf("index.html") > -1 &&
22+
dirFiles.indexOf("favicon.ico") > -1;
23+
24+
t.equal(isPassing, true);
25+
fs.remove(extractPath);
26+
t.end();
27+
});
28+
});

0 commit comments

Comments
 (0)
Please sign in to comment.