Skip to content

Commit 3a452ed

Browse files
committed
Move to tar-fs.
1 parent 6f15a15 commit 3a452ed

File tree

3 files changed

+173
-16
lines changed

3 files changed

+173
-16
lines changed

package-lock.json

Lines changed: 166 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"socks-proxy-agent": "^8.0.4",
7373
"stream-buffers": "^3.0.2",
7474
"tar": "^7.0.0",
75+
"tar-fs": "^3.0.8",
7576
"tmp-promise": "^3.0.2",
7677
"ws": "^8.18.0"
7778
},

src/cp.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import fs from 'node:fs';
1+
import fs, { rmSync } from 'node:fs';
22
import { WritableStreamBuffer } from 'stream-buffers';
3-
import * as tar from 'tar';
3+
import tar from 'tar-fs';
44
import tmp from 'tmp-promise';
5+
import path from 'node:path';
56

67
import { KubeConfig } from './config.js';
78
import { Exec } from './exec.js';
9+
import { getServers } from 'node:dns';
810

911
export class Cp {
1012
public execInstance: Exec;
@@ -29,7 +31,7 @@ export class Cp {
2931
const tmpFile = tmp.fileSync();
3032
const tmpFileName = tmpFile.name;
3133
const command = ['tar', 'zcf', '-', srcPath];
32-
const writerStream = fs.createWriteStream(tmpFileName);
34+
const writerStream = tar.extract(tgtPath);
3335
const errStream = new WritableStreamBuffer();
3436
this.execInstance.exec(
3537
namespace,
@@ -44,10 +46,6 @@ export class Cp {
4446
if (errStream.size()) {
4547
throw new Error(`Error from cpFromPod - details: \n ${errStream.getContentsAsString()}`);
4648
}
47-
await tar.x({
48-
file: tmpFileName,
49-
cwd: tgtPath,
50-
});
5149
},
5250
);
5351
}
@@ -66,16 +64,8 @@ export class Cp {
6664
srcPath: string,
6765
tgtPath: string,
6866
): Promise<void> {
69-
const tmpFile = tmp.fileSync();
70-
const tmpFileName = tmpFile.name;
7167
const command = ['tar', 'xf', '-', '-C', tgtPath];
72-
await tar.c(
73-
{
74-
file: tmpFile.name,
75-
},
76-
[srcPath],
77-
);
78-
const readStream = fs.createReadStream(tmpFileName);
68+
const readStream = tar.pack(srcPath);
7969
const errStream = new WritableStreamBuffer();
8070
this.execInstance.exec(
8171
namespace,

0 commit comments

Comments
 (0)