Skip to content

Commit 6cd194e

Browse files
committed
Add resolveFile helper function
1 parent c98d54f commit 6cd194e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
import initializeWasm from './helper';
22
import { FilesData, IUnpackJSAPI } from './types';
33

4+
/**
5+
* Resolve file content given its name (resolving symlinks if any)
6+
* @param files the current FilesData
7+
* @param filename the filename to resolve
8+
* @returns the resolved file content
9+
*/
10+
export function resolveFile(files: FilesData, filename: string): Uint8Array {
11+
if (!files[filename]) {
12+
throw new Error(`File ${filename} does not exist.`);
13+
}
14+
15+
if (typeof files[filename] === 'string') {
16+
// It's a symlink
17+
return resolveFile(files, files[filename]);
18+
}
19+
20+
return files[filename];
21+
}
22+
423
export const fetchByteArray = async (url: string): Promise<Uint8Array> => {
524
const response = await fetch(url);
625
if (!response.ok) {

0 commit comments

Comments
 (0)