1
1
import { $ , CryptoHasher , file , write } from "bun" ;
2
- import tar from "tar-fs " ;
2
+ import { extract } from "tar" ;
3
3
4
4
import stream from "node:stream" ;
5
+ import { mkdir } from "node:fs/promises" ;
5
6
6
7
const username = process . env [ "USERNAME_REGISTRY" ] ;
7
8
async function read ( stream : stream . Readable ) : Promise < string > {
@@ -54,6 +55,8 @@ if (imageID === "") {
54
55
process . exit ( 1 ) ;
55
56
}
56
57
58
+ console . log ( `Image ${ image } found locally, saving to disk...` ) ;
59
+
57
60
const tarFile = imageID . trim ( ) + ".tar" ;
58
61
const imagePath = ".output-image" ;
59
62
if ( ! ( await file ( tarFile ) . exists ( ) ) ) {
@@ -64,31 +67,17 @@ if (!(await file(tarFile).exists())) {
64
67
process . exit ( 1 ) ;
65
68
}
66
69
67
- const extract = tar . extract ( imagePath ) ;
68
-
69
- await Bun . file ( tarFile )
70
- . stream ( )
71
- . pipeTo (
72
- new WritableStream ( {
73
- write ( value ) {
74
- return new Promise ( ( res , rej ) => {
75
- extract . write ( value , ( err ) => {
76
- if ( err ) {
77
- rej ( err ) ;
78
- return ;
79
- }
80
- } ) ;
81
- extract . once ( "drain" , ( ) => {
82
- res ( ) ;
83
- } ) ;
84
- } ) ;
85
- } ,
86
- close ( ) {
87
- extract . end ( ) ;
88
- } ,
89
- } ) ,
90
- ) ;
91
- }
70
+ console . log ( `Image saved as ${ tarFile } , extracting...` ) ;
71
+
72
+ await mkdir ( imagePath ) ;
73
+
74
+ const result = await extract ( {
75
+ file : tarFile ,
76
+ cwd : imagePath ,
77
+ } ) ;
78
+
79
+ console . log ( `Extracted to ${ imagePath } ` ) ;
80
+ }
92
81
93
82
type DockerSaveConfigManifest = {
94
83
Config : string ;
@@ -110,7 +99,7 @@ if (manifests.length > 1) {
110
99
import plimit from "p-limit" ;
111
100
const pool = plimit ( 5 ) ;
112
101
import zlib from "node:zlib" ;
113
- import { mkdir , rename , rm } from "node:fs/promises" ;
102
+ import { rename , rm } from "node:fs/promises" ;
114
103
115
104
const cacheFolder = ".cache" ;
116
105
0 commit comments