@@ -28,6 +28,7 @@ import { v4 as uuid4 } from 'uuid'
28
28
import { V1ObjectMeta , V1Secret } from '@kubernetes/client-node'
29
29
import { sleep } from './helpers.mjs'
30
30
import { constants } from './index.mjs'
31
+ import * as stream from 'node:stream'
31
32
32
33
/**
33
34
* A kubernetes API wrapper class providing custom functionalities required by solo
@@ -571,11 +572,15 @@ export class K8 {
571
572
const self = this
572
573
return new Promise ( ( resolve , reject ) => {
573
574
const execInstance = new k8s . Exec ( this . kubeConfig )
574
- const command = [ 'cat ' , ` ${ srcDir } / ${ srcFile } ` ]
575
+ const command = [ 'tar ' , 'cf' , '-' , '-C' , srcDir , srcFile ]
575
576
const writerStream = fs . createWriteStream ( tmpFile )
577
+ const writerPassthroughStream = new stream . PassThrough ( )
576
578
const errStream = new sb . WritableStreamBuffer ( )
577
579
let additionalErrorMessageDetail = ''
578
580
581
+ // Use pipe() to automatically handle backpressure between streams
582
+ writerPassthroughStream . pipe ( writerStream ) ;
583
+
579
584
execInstance . exec (
580
585
namespace ,
581
586
podName ,
@@ -599,9 +604,11 @@ export class K8 {
599
604
}
600
605
601
606
try {
602
- // copy the downloaded file
603
- fs . copyFileSync ( tmpFile , destPath )
604
-
607
+ // extract the downloaded file
608
+ await tar . x ( {
609
+ file : tmpFile ,
610
+ cwd : destDir
611
+ } )
605
612
self . _deleteTempFile ( tmpFile )
606
613
607
614
const stat = fs . statSync ( destPath )
@@ -615,7 +622,7 @@ export class K8 {
615
622
}
616
623
}
617
624
} catch ( e ) {
618
- return reject ( new FullstackTestingError ( `failed to copy file: ${ destPath } ` , e ) )
625
+ return reject ( new FullstackTestingError ( `failed to extract file: ${ destPath } ` , e ) )
619
626
}
620
627
621
628
return reject ( new FullstackTestingError ( `failed to download file completely: ${ destPath } ${ additionalErrorMessageDetail } ` ) )
0 commit comments