@@ -284,52 +284,56 @@ export const listArchive =
284
284
name : string ;
285
285
} ;
286
286
287
- // let beginningDone = false;
288
-
289
287
let entries : Entry [ ] = [ ] ;
290
288
291
289
if ( buffer . length > 0 ) {
292
290
data = buffer + data ;
293
291
buffer = '' ;
294
292
}
295
293
296
- const params = {
297
- path : 'Path = ' ,
298
- type : 'Type = ' ,
299
- method : 'Method = ' ,
300
- physicalSize : 'Physical Size = ' ,
301
- headersSize : 'Headers Size = ' ,
302
- } ;
303
-
304
- data . split ( '\n' ) . forEach ( function ( line ) {
305
- // Populate the tech specs of the archive that are passed to the
306
- // resolve handler.
307
- if ( line . startsWith ( params . path ) ) {
308
- spec . path = line . slice ( params . path . length ) ;
309
- } else if ( line . startsWith ( params . type ) ) {
310
- spec . type = line . slice ( params . type . length ) ;
311
- } else if ( line . startsWith ( params . method ) ) {
312
- spec . method = line . slice ( params . method . length ) ;
313
- } else if ( line . startsWith ( params . physicalSize ) ) {
314
- spec . physicalSize = parseInt ( line . slice ( params . physicalSize . length ) , 10 ) ;
315
- } else if ( line . startsWith ( params . headersSize ) ) {
316
- spec . headersSize = parseInt ( line . slice ( params . headersSize . length ) , 10 ) ;
317
- } else {
318
- // Parse the stdout to find entries
319
- let res = regex . exec ( line ) ;
320
-
321
- if ( res ) {
322
- let e = {
323
- date : new Date ( res [ 1 ] ) ,
324
- attr : res [ 2 ] ,
325
- size : parseInt ( res [ 3 ] , 10 ) ,
326
- name : ReplaceNativeSeparator ( res [ 5 ] ) ,
327
- } ;
328
- entries . push ( e ) ;
329
- } // Line may be incomplete, Save it to the buffer.
330
- else buffer = line ;
294
+ // Populate the tech specs of the archive that are passed to the
295
+ // resolve handler.
296
+ type Param = [ string , string , Function | null ] ;
297
+
298
+ const params : Param [ ] = [
299
+ [ 'Path = ' , 'path' , null ] ,
300
+ [ 'Type = ' , 'type' , null ] ,
301
+ [ 'Method = ' , 'method' , null ] ,
302
+ [ 'Physical Size = ' , 'physicalSize' , parseInt ] ,
303
+ [ 'Headers Size = ' , 'headersSize' , parseInt ] ,
304
+ ] ;
305
+
306
+ const lines = data . split ( '\n' ) ;
307
+
308
+ for ( const line of lines ) {
309
+ let lineDone = false ;
310
+
311
+ for ( const [ beginning , paramType , fn ] of params ) {
312
+ if ( line . startsWith ( beginning ) ) {
313
+ const paramValue = line . slice ( beginning . length ) ;
314
+ spec [ paramType ] = fn ? fn ( paramValue ) : paramValue ;
315
+ lineDone = true ;
316
+ break ;
317
+ }
331
318
}
332
- } ) ;
319
+
320
+ if ( lineDone ) continue ;
321
+
322
+ // Parse the stdout to find entries
323
+ let res = regex . exec ( line ) ;
324
+
325
+ if ( res ) {
326
+ let e = {
327
+ date : new Date ( res [ 1 ] ) ,
328
+ attr : res [ 2 ] ,
329
+ size : parseInt ( res [ 3 ] , 10 ) ,
330
+ name : ReplaceNativeSeparator ( res [ 5 ] ) ,
331
+ } ;
332
+ entries . push ( e ) ;
333
+ } // Line may be incomplete, Save it to the buffer.
334
+ else buffer = line ;
335
+ }
336
+
333
337
return entries ;
334
338
}
335
339
0 commit comments