silverbullet/packages/common/asset_bundle.ts

22 lines
474 B
TypeScript
Raw Normal View History

2022-10-08 21:46:56 +08:00
import { base64Decode } from "./base64.ts";
2022-10-07 22:27:47 +08:00
type AssetBundle = Record<string, string>;
export function assetReadFileSync(
bundle: AssetBundle,
path: string,
): ArrayBuffer {
const content = bundle[path];
if (!content) {
throw new Error(`No such file ${path}`);
}
2022-10-08 21:46:56 +08:00
return base64Decode(content);
2022-10-07 22:27:47 +08:00
}
export function assetReadTextFileSync(
bundle: AssetBundle,
path: string,
): string {
return new TextDecoder().decode(assetReadFileSync(bundle, path));
}