11import initializeWasm from './helper' ;
2- import { IFileData , IUnpackJSAPI } from './types' ;
2+ import { FilesData , IUnpackJSAPI } from './types' ;
33
44const fetchByteArray = async ( url : string ) : Promise < Uint8Array > => {
55 const response = await fetch ( url ) ;
@@ -13,7 +13,7 @@ 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 < IFileData [ ] > => {
16+ const extractData = async ( data : Uint8Array ) : Promise < FilesData > => {
1717 /**Since WebAssembly, memory is accessed using pointers
1818 and the first parameter of extract_archive method from unpack.c, which is Uint8Array of file data, should be a pointer
1919 so we have to allocate memory for file data
@@ -60,12 +60,12 @@ export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
6060 'Error:' ,
6161 errorMessage
6262 ) ;
63- return [ ] ;
63+ return { } ;
6464 }
6565 const filesPtr = wasmModule . getValue ( resultPtr , 'i32' ) ;
6666 const fileCount = wasmModule . getValue ( resultPtr + 4 , 'i32' ) ;
6767
68- const files : IFileData [ ] = [ ] ;
68+ const files : FilesData = { } ;
6969
7070 /**
7171 * FilesPtr is a pointer that refers to an instance of the FileData in unpack.c
@@ -97,10 +97,7 @@ export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
9797 dataSize
9898 ) ;
9999
100- files . push ( {
101- filename : filename ,
102- data : fileData
103- } ) ;
100+ files [ filename ] = fileData ;
104101 }
105102
106103 wasmModule . _free ( inputPtr ) ;
@@ -111,17 +108,17 @@ export const initUntarJS = async (): Promise<IUnpackJSAPI> => {
111108 return files ;
112109 } catch ( error ) {
113110 console . error ( 'Error during extraction:' , error ) ;
114- return [ ] ;
111+ return { } ;
115112 }
116113 } ;
117114
118- const extract = async ( url : string ) : Promise < IFileData [ ] > => {
115+ const extract = async ( url : string ) : Promise < FilesData > => {
119116 try {
120117 const data = await fetchByteArray ( url ) ;
121118 return await extractData ( data ) ;
122119 } catch ( error ) {
123120 console . error ( 'Error during extracting:' , error ) ;
124- return [ ] ;
121+ return { } ;
125122 }
126123 }
127124
0 commit comments