@@ -19,11 +19,16 @@ program
19
19
. option ( '-O, --to-stdout' , 'extract raw contents to stdout' )
20
20
. option ( '-z, --dump' , 'dump internal representation but do not extract' )
21
21
. option ( '-q, --quiet' , 'process but do not report' )
22
+ . option ( '--here' , 'skip the CFB root name when extracting' )
23
+ . option ( '--osx' , 'use OSX-style unzip listing' )
24
+ . option ( '--zlib' , 'use native zlib' )
25
+ . option ( '--local' , 'print times in local timezone' )
22
26
. option ( '--dev' , 'development mode' )
23
27
. option ( '--read' , 'read but do not print out contents' ) ;
24
-
25
28
program . parse ( process . argv ) ;
26
29
30
+ if ( program . zlib ) X . utils . use_zlib ( require ( 'zlib' ) ) ;
31
+
27
32
var exit = process . exit ;
28
33
var die = function ( errno /*:number*/ , msg /*:string*/ ) { console . error ( n + ": " + msg ) ; exit ( errno ) ; } ;
29
34
var logit = function ( cmd /*:string*/ , f /*:string*/ ) { console . error ( sprintf ( "%-6s %s" , cmd , f ) ) ; } ;
@@ -53,30 +58,55 @@ if(program.dump) {
53
58
}
54
59
if ( program . repair ) { X . writeFile ( cfb , program . args [ 0 ] ) ; exit ( 0 ) ; }
55
60
61
+ var rlen = cfb . FullPaths [ 0 ] . length ;
62
+
56
63
function fix_string ( x /*:string*/ ) /*:string*/ { return x . replace ( / [ \u0000 - \u001f ] / g, function ( $$ ) { return sprintf ( "\\u%04X" , $$ . charCodeAt ( 0 ) ) ; } ) ; }
57
- var format_date = function ( date /*:Date*/ ) /*:string*/ {
58
- return sprintf ( "%02u-%02u-%02u %02u:%02u" , date . getUTCMonth ( ) + 1 , date . getUTCDate ( ) , date . getUTCFullYear ( ) % 100 , date . getUTCHours ( ) , date . getUTCMinutes ( ) ) ;
64
+ var format_date = function ( date /*:Date*/ , osx /*:?any*/ ) /*:string*/ {
65
+ var datefmt = osx ? "%02u-%02u-%04u %02u:%02u" : "%02u-%02u-%02u %02u:%02u" ;
66
+ var MM = program . local ? date . getMonth ( ) + 1 : date . getUTCMonth ( ) + 1 ;
67
+ var DD = program . local ? date . getDate ( ) : date . getUTCDate ( ) ;
68
+ var YY = ( program . local ? date . getFullYear ( ) : date . getUTCFullYear ( ) ) % ( osx ? 10000 : 100 ) ;
69
+ var hh = program . local ? date . getHours ( ) : date . getUTCHours ( ) ;
70
+ var mm = program . local ? date . getMinutes ( ) : date . getUTCMinutes ( ) ;
71
+ return sprintf ( datefmt , MM , DD , YY , hh , mm ) ;
59
72
} ;
60
73
61
74
if ( program . listFiles ) {
62
- var basetime = new Date ( 1980 , 0 , 1 ) ;
75
+ var basetime = new Date ( Date . UTC ( 1980 , 0 , 1 ) ) ;
63
76
var cnt = 0 , rootsize = 0 , filesize = 0 ;
64
- console . log ( " Length Date Time Name" ) ;
65
- console . log ( " -------- ---- ---- ----" ) ;
77
+ var fmtstr = "%9lu %s %s" ;
78
+ if ( program . osx ) {
79
+ console . log ( "Archive: " + program . args [ 0 ] ) ;
80
+ console . log ( " Length Date Time Name" ) ;
81
+ console . log ( "--------- ---------- ----- ----" ) ;
82
+ fmtstr = "%9lu %s %s" ;
83
+ } else {
84
+ console . log ( " Length Date Time Name" ) ;
85
+ console . log ( " -------- ---- ---- ----" ) ;
86
+ }
66
87
cfb . FileIndex . forEach ( function ( file /*:CFBEntry*/ , i /*:number*/ ) {
67
88
switch ( file . type ) {
68
89
case 5 :
69
90
basetime = file . ct || file . mt || basetime ;
70
91
rootsize = file . size ;
71
92
break ;
72
93
case 2 :
73
- console . log ( sprintf ( "%9lu %s %s" , file . size , format_date ( basetime ) , fix_string ( cfb . FullPaths [ i ] ) ) ) ;
94
+ var fixname = fix_string ( cfb . FullPaths [ i ] ) ;
95
+ if ( program . osx && fixname . match ( / \\ u 0 0 0 1 S h 3 3 t J 5 / ) ) return ;
96
+ if ( program . here ) fixname = fixname . slice ( rlen ) ;
97
+ console . log ( sprintf ( fmtstr , file . size , format_date ( file . mt || basetime , program . osx ) , fixname ) ) ;
74
98
filesize += file . size ;
75
99
++ cnt ;
76
100
}
77
101
} ) ;
78
- console . log ( " -------- -------" ) ;
79
- console . log ( sprintf ( "%9lu %lu file%s" , rootsize || filesize , cnt , ( cnt !== 1 ? "s" : "" ) ) ) ;
102
+ var outfmt = "%9lu %lu file%s" ;
103
+ if ( program . osx ) {
104
+ console . log ( "--------- -------" ) ;
105
+ outfmt = "%9lu %lu file%s" ;
106
+ } else {
107
+ console . log ( " -------- -------" ) ;
108
+ }
109
+ console . log ( sprintf ( outfmt , rootsize || filesize , cnt , ( cnt !== 1 ? "s" : "" ) ) ) ;
80
110
81
111
exit ( 0 ) ;
82
112
}
@@ -124,8 +154,13 @@ if(program.args.length > 1) {
124
154
}
125
155
126
156
if ( program . toStdout ) exit ( 0 ) ;
127
- for ( var i = 0 ; i !== cfb . FullPaths . length ; ++ i ) {
157
+ for ( var i = program . here ? 1 : 0 ; i !== cfb . FullPaths . length ; ++ i ) {
128
158
if ( ! cfb . FileIndex [ i ] . name ) continue ;
129
- if ( cfb . FullPaths [ i ] . slice ( - 1 ) === "/" ) mkdirp ( cfb . FullPaths [ i ] ) ;
130
- else write ( cfb . FullPaths [ i ] , cfb . FileIndex [ i ] ) ;
159
+ var fp = cfb . FullPaths [ i ] ;
160
+ if ( program . here ) fp = fp . slice ( rlen ) ;
161
+ if ( fp . slice ( - 1 ) === "/" ) mkdirp ( fp ) ;
162
+ else {
163
+ if ( fp . indexOf ( "/" ) > - 1 ) mkdirp ( fp . slice ( 0 , fp . lastIndexOf ( "/" ) ) ) ;
164
+ write ( fp , cfb . FileIndex [ i ] ) ;
165
+ }
131
166
}
0 commit comments