Files
esengine/packages/editor-runtime/src/FileSystem.ts

122 lines
3.0 KiB
TypeScript
Raw Normal View History

/**
* API
* File System API
*
* Tauri
* 使 API @tauri-apps/plugin-fs
*/
import { invoke } from '@tauri-apps/api/core';
/**
*
* 使
*/
export const FileSystem = {
/**
*
* @param path
* @returns
*/
async readTextFile(path: string): Promise<string> {
return await invoke<string>('read_file_content', { path });
},
/**
*
* @param path
* @param content
*/
async writeTextFile(path: string, content: string): Promise<void> {
await invoke('write_file_content', { path, content });
},
/**
*
* @param path
*/
async exists(path: string): Promise<boolean> {
return await invoke<boolean>('path_exists', { path });
},
/**
*
* @param path
*/
async createDirectory(path: string): Promise<void> {
await invoke('create_directory', { path });
},
/**
*
* @param path
*/
async createFile(path: string): Promise<void> {
await invoke('create_file', { path });
},
/**
*
* @param path
*/
async deleteFile(path: string): Promise<void> {
await invoke('delete_file', { path });
},
/**
*
* @param path
*/
async deleteDirectory(path: string): Promise<void> {
await invoke('delete_folder', { path });
},
/**
*
* @param oldPath
* @param newPath
*/
async rename(oldPath: string, newPath: string): Promise<void> {
await invoke('rename_file_or_folder', { oldPath, newPath });
},
/**
*
* @param path
* @returns
*/
async readDirectory(path: string): Promise<DirectoryEntry[]> {
return await invoke<DirectoryEntry[]>('read_directory', { path });
},
/**
* Base64
* @param path
* @returns Base64
*/
async readFileAsBase64(path: string): Promise<string> {
return await invoke<string>('read_file_as_base64', { filePath: path });
},
/**
*
* @param path
* @param data
*/
async writeBinaryFile(path: string, data: Uint8Array): Promise<void> {
await invoke('write_binary_file', { filePath: path, content: Array.from(data) });
}
};
/**
*
*/
export interface DirectoryEntry {
name: string;
path: string;
isDirectory: boolean;
isFile: boolean;
size?: number;
modified?: number;
}