1
- import fs from 'node:fs' ;
1
+ import fs , { rmSync } from 'node:fs' ;
2
2
import { WritableStreamBuffer } from 'stream-buffers' ;
3
- import * as tar from 'tar' ;
3
+ import tar from 'tar-fs ' ;
4
4
import tmp from 'tmp-promise' ;
5
+ import path from 'node:path' ;
5
6
6
7
import { KubeConfig } from './config.js' ;
7
8
import { Exec } from './exec.js' ;
9
+ import { getServers } from 'node:dns' ;
8
10
9
11
export class Cp {
10
12
public execInstance : Exec ;
@@ -29,7 +31,7 @@ export class Cp {
29
31
const tmpFile = tmp . fileSync ( ) ;
30
32
const tmpFileName = tmpFile . name ;
31
33
const command = [ 'tar' , 'zcf' , '-' , srcPath ] ;
32
- const writerStream = fs . createWriteStream ( tmpFileName ) ;
34
+ const writerStream = tar . extract ( tgtPath ) ;
33
35
const errStream = new WritableStreamBuffer ( ) ;
34
36
this . execInstance . exec (
35
37
namespace ,
@@ -44,10 +46,6 @@ export class Cp {
44
46
if ( errStream . size ( ) ) {
45
47
throw new Error ( `Error from cpFromPod - details: \n ${ errStream . getContentsAsString ( ) } ` ) ;
46
48
}
47
- await tar . x ( {
48
- file : tmpFileName ,
49
- cwd : tgtPath ,
50
- } ) ;
51
49
} ,
52
50
) ;
53
51
}
@@ -66,16 +64,8 @@ export class Cp {
66
64
srcPath : string ,
67
65
tgtPath : string ,
68
66
) : Promise < void > {
69
- const tmpFile = tmp . fileSync ( ) ;
70
- const tmpFileName = tmpFile . name ;
71
67
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 ) ;
79
69
const errStream = new WritableStreamBuffer ( ) ;
80
70
this . execInstance . exec (
81
71
namespace ,
0 commit comments