File tree 3 files changed +31
-0
lines changed
3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,8 @@ module.exports = function centralDirectory(source, options) {
151
151
152
152
vars . extract = function ( opts ) {
153
153
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 ) ) ;
154
156
return vars . files . then ( function ( files ) {
155
157
return Promise . map ( files , function ( entry ) {
156
158
if ( entry . type == 'Directory' ) return ;
Original file line number Diff line number Diff line change 37
37
"devDependencies" : {
38
38
"aws-sdk" : " ^2.77.0" ,
39
39
"dirdiff" : " >= 0.0.1 < 1" ,
40
+ "fs-extra" : " ^9.0.0" ,
40
41
"iconv-lite" : " ^0.4.24" ,
41
42
"request" : " ^2.88.0" ,
42
43
"stream-buffers" : " >= 0.2.5 < 1" ,
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments