Line data Source code
1 1 : function bridge(): DashQLElectronBridge['fs'] {
2 1 : if (globalThis.dashqlElectron === undefined) throw new Error('Electron filesystem bridge is unavailable');
3 1 : return globalThis.dashqlElectron.fs;
4 1 : }
5 :
6 : export type FileStamp = DashQLFileStamp;
7 1 : export const exists = (path: string) => bridge().exists(path);
8 1 : export const fileStamp = (path: string) => bridge().fileStamp(path);
9 1 : export const listFiles = (path: string) => bridge().listFiles(path);
10 1 : export const mkdir = (path: string, options?: {recursive?: boolean}) => bridge().mkdir(path, options);
11 1 : export const readDir = (path: string) => bridge().readDir(path);
12 1 : export const readFile = (path: string) => bridge().readFile(path);
13 1 : export const readTextFile = (path: string) => bridge().readTextFile(path);
14 1 : export const remove = (path: string, options?: {recursive?: boolean}) => bridge().remove(path, options);
15 1 : export const rename = (from: string, to: string) => bridge().rename(from, to);
16 1 : export const writeFile = (path: string, data: Uint8Array) => bridge().writeFile(path, data);
17 1 : export const writeTextFile = (path: string, data: string) => bridge().writeTextFile(path, data);
18 1 : export const join = async (...parts: string[]) => parts.reduce((result, part) => `${result.replace(/[\\/]$/, '')}/${part.replace(/^[\\/]/, '')}`);
19 1 : export async function stat(path: string) {
20 1 : const value = await bridge().stat(path);
21 1 : return {...value, mtime: value.mtime === null ? null : new Date(value.mtime)};
22 1 : }
|