@@ -5,6 +5,18 @@ import { Files, ReplaceNativeSeparator, Run } from './utility.js';
5
5
import { createSfx } from './createSfx.js' ;
6
6
import { isWindows } from 'node-sys' ;
7
7
8
+ /**
9
+ * When a stdout is emitted, parse each line and search for a pattern. When
10
+ * the pattern is found, extract the file (or directory) name from it and
11
+ * pass it to an array. Finally returns this array.
12
+ */
13
+ const onProgress = ( firstChar : string ) =>
14
+ function ( data : string ) : string [ ] {
15
+ return data . split ( '\n' )
16
+ . filter ( ( line ) => line . startsWith ( firstChar ) )
17
+ . map ( ( line ) => ReplaceNativeSeparator ( line . slice ( 2 ) ) ) ;
18
+ }
19
+
8
20
function retry (
9
21
command : string | undefined ,
10
22
options : { } ,
@@ -66,16 +78,7 @@ export const createArchive =
66
78
reject : ( reason : any ) => void ,
67
79
progress : ( arg0 : any ) => any
68
80
) {
69
- /**
70
- * When a stdout is emitted, parse each line and search for a pattern.When
71
- * the pattern is found, extract the file (or directory) name from it and
72
- * pass it to an array. Finally returns this array.
73
- */
74
- function onprogress ( data : string ) {
75
- return data . split ( '\n' )
76
- . filter ( ( line ) => line . startsWith ( '+' ) )
77
- . map ( ( line ) => ReplaceNativeSeparator ( line . slice ( 2 ) ) ) ;
78
- }
81
+ const onprogress = onProgress ( '+' ) ;
79
82
80
83
// Convert array of files into a string if needed.
81
84
files = Files ( files ) ;
@@ -170,24 +173,7 @@ export const extractArchive =
170
173
reject : ( reason : any ) => void ,
171
174
progress : ( arg0 : any ) => any
172
175
) {
173
- /**
174
- * When a stdout is emitted, parse each line and search for a pattern.When
175
- * the pattern is found, extract the file (or directory) name from it and
176
- * pass it to an array. Finally returns this array.
177
- */
178
- function onprogress ( data : string ) {
179
- let entries : string [ ] = [ ] ;
180
- data . split ( '\n' ) . forEach ( function ( line ) {
181
- if ( line . substr ( 0 , 1 ) === '-' ) {
182
- entries . push (
183
- ReplaceNativeSeparator (
184
- line . substr ( 2 , line . length )
185
- )
186
- ) ;
187
- }
188
- } ) ;
189
- return entries ;
190
- }
176
+ const onprogress = onProgress ( '-' ) ;
191
177
192
178
// Create a string that can be parsed by `run`.
193
179
let command = 'e "' + filepath + '" -o"' + dest + '" ' ;
@@ -233,25 +219,8 @@ export const fullArchive =
233
219
reject : ( reason : any ) => void ,
234
220
progress : ( arg0 : any ) => any
235
221
) {
236
- /**
237
- * When a stdout is emitted, parse each line and search for a pattern.When
238
- * the pattern is found, extract the file (or directory) name from it and
239
- * pass it to an array. Finally returns this array.
240
- */
241
- function onprogress ( data : string ) {
242
- let entries : string [ ] = [ ] ;
243
- data . split ( '\n' ) . forEach ( function ( line ) {
244
- if ( line . substr ( 0 , 1 ) === '-' ) {
245
- entries . push (
246
- ReplaceNativeSeparator (
247
- line . substr ( 2 , line . length )
248
- )
249
- ) ;
250
- }
251
- } ) ;
252
- return entries ;
253
- }
254
-
222
+ const onprogress = onProgress ( '-' ) ;
223
+
255
224
// Create a string that can be parsed by `run`.
256
225
let command = 'x "' + filepath + '" -o"' + dest + '" ' ;
257
226
return retry (
@@ -425,25 +394,8 @@ export const onlyArchive =
425
394
files : files ,
426
395
} ) ;
427
396
428
- /**
429
- * When a stdout is emitted, parse each line and search for a pattern.When
430
- * the pattern is found, extract the file (or directory) name from it and
431
- * pass it to an array. Finally returns this array.
432
- */
433
- function onprogress ( data : string ) {
434
- let entries : string [ ] = [ ] ;
435
- data . split ( '\n' ) . forEach ( function ( line ) {
436
- if ( line . substr ( 0 , 1 ) === '-' ) {
437
- entries . push (
438
- ReplaceNativeSeparator (
439
- line . substr ( 2 , line . length )
440
- )
441
- ) ;
442
- }
443
- } ) ;
444
- return entries ;
445
- }
446
-
397
+ const onprogress = onProgress ( '-' ) ;
398
+
447
399
// Create a string that can be parsed by `run`.
448
400
let command = 'e "' + filepath + '" -o"' + dest + '"' ;
449
401
// Start the command
@@ -488,24 +440,7 @@ export const renameArchive =
488
440
reject : ( reason : any ) => void ,
489
441
progress : ( arg0 : any ) => any
490
442
) {
491
- /**
492
- * When a stdout is emitted, parse each line and search for a pattern.When
493
- * the pattern is found, extract the file (or directory) name from it and
494
- * pass it to an array. Finally returns this array.
495
- */
496
- function onprogress ( data : string ) {
497
- let entries : string [ ] = [ ] ;
498
- data . split ( '\n' ) . forEach ( function ( line ) {
499
- if ( line . substr ( 0 , 1 ) === 'U' ) {
500
- entries . push (
501
- ReplaceNativeSeparator (
502
- line . substr ( 2 , line . length )
503
- )
504
- ) ;
505
- }
506
- } ) ;
507
- return entries ;
508
- }
443
+ const onprogress = onProgress ( 'U' ) ;
509
444
510
445
// Convert array of files into a string if needed.
511
446
files = Files ( files ) ;
@@ -547,24 +482,7 @@ export const testArchive =
547
482
reject : ( reason : any ) => void ,
548
483
progress : ( arg0 : any ) => any
549
484
) {
550
- /**
551
- * When a stdout is emitted, parse each line and search for a pattern.When
552
- * the pattern is found, extract the file (or directory) name from it and
553
- * pass it to an array. Finally returns this array.
554
- */
555
- function onprogress ( data : string ) {
556
- let entries : string [ ] = [ ] ;
557
- data . split ( '\n' ) . forEach ( function ( line ) {
558
- if ( line . substr ( 0 , 1 ) === 'T' ) {
559
- entries . push (
560
- ReplaceNativeSeparator (
561
- line . substr ( 2 , line . length )
562
- )
563
- ) ;
564
- }
565
- } ) ;
566
- return entries ;
567
- }
485
+ const onprogress = onProgress ( 'T' ) ;
568
486
569
487
// Create a string that can be parsed by `run`.
570
488
let command = 't "' + filepath + '"' ;
@@ -610,24 +528,7 @@ export const updateArchive =
610
528
reject : ( reason : any ) => void ,
611
529
progress : ( arg0 : any ) => any
612
530
) {
613
- /**
614
- * When a stdout is emitted, parse each line and search for a pattern.When
615
- * the pattern is found, extract the file (or directory) name from it and
616
- * pass it to an array. Finally returns this array.
617
- */
618
- function onprogress ( data : string ) {
619
- let entries : string [ ] = [ ] ;
620
- data . split ( '\n' ) . forEach ( function ( line ) {
621
- if ( line . substr ( 0 , 1 ) === 'U' ) {
622
- entries . push (
623
- ReplaceNativeSeparator (
624
- line . substr ( 2 , line . length )
625
- )
626
- ) ;
627
- }
628
- } ) ;
629
- return entries ;
630
- }
531
+ const onprogress = onProgress ( 'U' ) ;
631
532
632
533
// Convert array of files into a string if needed.
633
534
files = Files ( files ) ;
0 commit comments