Skip to content

Commit 48711f1

Browse files
committed
add pipe to copyFrom
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent 5c7fb6b commit 48711f1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/core/k8.mjs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { v4 as uuid4 } from 'uuid'
2828
import { V1ObjectMeta, V1Secret } from '@kubernetes/client-node'
2929
import { sleep } from './helpers.mjs'
3030
import { constants } from './index.mjs'
31+
import * as stream from 'node:stream'
3132

3233
/**
3334
* A kubernetes API wrapper class providing custom functionalities required by solo
@@ -571,11 +572,15 @@ export class K8 {
571572
const self = this
572573
return new Promise((resolve, reject) => {
573574
const execInstance = new k8s.Exec(this.kubeConfig)
574-
const command = ['cat', `${srcDir}/${srcFile}`]
575+
const command = ['tar', 'cf', '-', '-C', srcDir, srcFile]
575576
const writerStream = fs.createWriteStream(tmpFile)
577+
const writerPassthroughStream = new stream.PassThrough()
576578
const errStream = new sb.WritableStreamBuffer()
577579
let additionalErrorMessageDetail = ''
578580

581+
// Use pipe() to automatically handle backpressure between streams
582+
writerPassthroughStream.pipe(writerStream);
583+
579584
execInstance.exec(
580585
namespace,
581586
podName,
@@ -599,9 +604,11 @@ export class K8 {
599604
}
600605

601606
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+
})
605612
self._deleteTempFile(tmpFile)
606613

607614
const stat = fs.statSync(destPath)
@@ -615,7 +622,7 @@ export class K8 {
615622
}
616623
}
617624
} catch (e) {
618-
return reject(new FullstackTestingError(`failed to copy file: ${destPath}`, e))
625+
return reject(new FullstackTestingError(`failed to extract file: ${destPath}`, e))
619626
}
620627

621628
return reject(new FullstackTestingError(`failed to download file completely: ${destPath}${additionalErrorMessageDetail}`))

0 commit comments

Comments
 (0)