- 探索FileSystem Api
- MDN FileSystem
- How to use navigator instead of window.webkitStorageInfo HTML5 File-system API?
npm i file-system-web
# or
yarn add file-system-web
import { readFile } from 'file-system-web';
async function main() {
const fileContent = await readFile('1.txt');
console.log(fileContent);
}
- RequestFileSystemConfig
interface RequestFileSystemConfig {
size?: number;
type?: 0 | 1;
}
- DirectoryEntry
interface DirectoryEntry {
filesystem: DOMFileSystem;
fullPath: string;
isDirectory: boolean;
isFile: boolean;
name: string;
createReader: () => DirectoryReader;
getDirectory: (
path: string,
options: GetDirectoryOptions,
successCallback?: (dirEntry: DirectoryEntry) => void,
errorCallback?: (e: Error) => void
) => void;
getFile: (
path: string,
options: GetDirectoryOptions,
successCallback?: (fileEntry: FileEntry) => void,
errorCallback?: (e: Error) => void
) => void;
remove: (
successCallback: () => void,
errorCallback?: (e: Error) => void
) => void;
removeRecursively: (
successCallback: () => void,
errorCallback?: (e: Error) => void
) => void;
// removeRecursively will Deprecated
}
- FileEntry
interface FileEntry extends Omit<DirectoryEntry, 'removeRecursively'> {
file: (
successCallback: (file: unknown) => void,
errorCallback?: (e: Error) => void
) => void;
createWriter: (
successCallback: (fileWriter: FileWriter) => void,
errorCallback?: (e: Error) => void
) => void;
}
- WriteFileConfig
interface WriteFileConfig {
append?: boolean; // 是否追加内容
}
- RemoveDirConfig
interface RemoveDirConfig {
recursive?: boolean; // 是否递归删除
}
- FSInfoResult
interface FSInfoResult {
currentUsageInBytes: number; // 当前已使用字节数
currentQuotaInBytes: number; // 当前配额字节数
}
- RequestFileSystemConfig
const defaultConfig = {
size: 0,
type: 0
}
- WriteFileConfig
const defaultWriteFileConfig = {
append: false
}
- RemoveDirConfig
const defaultRemoveDirConfig = {
recursive: false
}