Skip to content

Commit

Permalink
Iterate
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Nov 13, 2024
1 parent 4095e8e commit 5bd9368
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import unpack, { IWasmModule } from './unpack';
import unpackWasm from './unpack.wasm';

const initializeWasm = async (wasmPath: string | undefined): Promise<IWasmModule> => {
try {
const wasmModule: IWasmModule = await unpack({
locateFile(path: string) {
if (path.endsWith('.wasm')) {
return wasmPath ? wasmPath : unpackWasm;
return wasmPath ? wasmPath : 'unpack.wasm';
}
return path;
}
Expand All @@ -17,4 +16,5 @@ const initializeWasm = async (wasmPath: string | undefined): Promise<IWasmModule
throw new Error(`Error initializing the WASM module: ${err}`);
}
};

export default initializeWasm;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface IUnpackJSAPI {
extract: (url: string) => Promise<IFileData[]>;
}

export const initUntarJS = async (wasmPath: string | undefined): Promise<IUnpackJSAPI> => {
export const initUntarJS = async (wasmPath?: string): Promise<IUnpackJSAPI> => {
let wasmModule: IWasmModule | undefined = undefined;
try {
wasmModule = await initializeWasm(wasmPath);
Expand Down
4 changes: 3 additions & 1 deletion tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import untarjs from '../src/index';
import { initUntarJS } from '../src/index';

jest.mock('../src/helper', () => ({
__esModule: true,
Expand All @@ -14,6 +14,8 @@ jest.mock('../src/index', () => {

describe('extract', () => {
it('should download and extract data successfully', async () => {
const untarjs = await initUntarJS();

const mockData = new Uint8Array([1, 2, 3, 4]);
const extractedData = {
data: new Uint8Array([5, 6, 7, 8]),
Expand Down

0 comments on commit 5bd9368

Please sign in to comment.