@@ -13,7 +13,10 @@ const fetchByteArray = async (url: string): Promise<Uint8Array> => {
1313export const initUntarJS = async ( ) : Promise < IUnpackJSAPI > => {
1414 const wasmModule = await initializeWasm ( ) ;
1515
16- const extractData = async ( data : Uint8Array ) : Promise < FilesData > => {
16+ const extractData = async (
17+ data : Uint8Array ,
18+ decompressionOnly : boolean = false
19+ ) : Promise < FilesData > => {
1720 /**Since WebAssembly, memory is accessed using pointers
1821 and the first parameter of extract_archive method from unpack.c, which is Uint8Array of file data, should be a pointer
1922 so we have to allocate memory for file data
@@ -27,9 +30,10 @@ export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
2730 let resultPtr : number | null = wasmModule . _extract_archive (
2831 inputPtr ,
2932 data . length ,
30- fileCountPtr
33+ fileCountPtr ,
34+ decompressionOnly
3135 ) ;
32-
36+ const files : FilesData = { } ;
3337 /**
3438 * Since extract_archive returns a pointer that refers to an instance of the ExtractedArchive in unpack.c
3539 typedef struct {
@@ -71,8 +75,6 @@ export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
7175 const filesPtr = wasmModule . getValue ( resultPtr , 'i32' ) ;
7276 const fileCount = wasmModule . getValue ( resultPtr + 4 , 'i32' ) ;
7377
74- const files : FilesData = { } ;
75-
7678 /**
7779 * FilesPtr is a pointer that refers to an instance of the FileData in unpack.c
7880 typedef struct {
@@ -102,26 +104,38 @@ export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
102104 dataPtr ,
103105 dataSize
104106 ) ;
105-
106- const fileDataCopy = fileData . slice ( 0 ) ;
107107
108+ const fileDataCopy = fileData . slice ( 0 ) ;
108109 files [ filename ] = fileDataCopy ;
109110 }
110-
111+
111112 wasmModule . _free ( inputPtr ) ;
112113 wasmModule . _free ( fileCountPtr ) ;
113114 wasmModule . _free_extracted_archive ( resultPtr ) ;
114115 inputPtr = null ;
115116 fileCountPtr = null ;
116117 resultPtr = null ;
117118 errorMessagePtr = null ;
119+
118120 return files ;
119121 } ;
120122
121123 const extract = async ( url : string ) : Promise < FilesData > => {
124+ let isArchive : boolean = checkIsArchive ( url ) ;
122125 const data = await fetchByteArray ( url ) ;
123- return extractData ( data ) ;
124- }
126+ return extractData ( data , ! isArchive ) ;
127+ } ;
128+
129+ const checkIsArchive = ( url : string ) : boolean => {
130+ let isArchive : boolean = false ;
131+ let archiveExtArr = [ '.conda' , 'tar.bz2' , 'tar.gz' ] ;
132+ archiveExtArr . forEach ( type => {
133+ if ( url . toLowerCase ( ) . endsWith ( type ) ) {
134+ isArchive = true ;
135+ }
136+ } ) ;
137+ return isArchive ;
138+ } ;
125139
126140 return {
127141 extract,
0 commit comments