11import { $ , CryptoHasher , file , write } from "bun" ;
2- import tar from "tar-fs " ;
2+ import { extract } from "tar" ;
33
44import stream from "node:stream" ;
5+ import { mkdir } from "node:fs/promises" ;
56
67const username = process . env [ "USERNAME_REGISTRY" ] ;
78async function read ( stream : stream . Readable ) : Promise < string > {
@@ -54,6 +55,8 @@ if (imageID === "") {
5455 process . exit ( 1 ) ;
5556}
5657
58+ console . log ( `Image ${ image } found locally, saving to disk...` ) ;
59+
5760const tarFile = imageID . trim ( ) + ".tar" ;
5861const imagePath = ".output-image" ;
5962if ( ! ( await file ( tarFile ) . exists ( ) ) ) {
@@ -64,31 +67,17 @@ if (!(await file(tarFile).exists())) {
6467 process . exit ( 1 ) ;
6568 }
6669
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+ }
9281
9382type DockerSaveConfigManifest = {
9483 Config : string ;
@@ -110,7 +99,7 @@ if (manifests.length > 1) {
11099import plimit from "p-limit" ;
111100const pool = plimit ( 5 ) ;
112101import zlib from "node:zlib" ;
113- import { mkdir , rename , rm } from "node:fs/promises" ;
102+ import { rename , rm } from "node:fs/promises" ;
114103
115104const cacheFolder = ".cache" ;
116105
0 commit comments