opfs-tools
Version:
EN: A simple, high-performance, and comprehensive file system API running in the browser, built on [OPFS](https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system).
64 lines (60 loc) • 2.01 kB
TypeScript
import { OTFile } from './file';
declare global {
interface FileSystemDirectoryHandle {
keys: () => AsyncIterable<string>;
values: () => AsyncIterable<FileSystemDirectoryHandle | FileSystemFileHandle>;
}
}
/**
* Represents a directory with utility functions.
* @param {string} dirPath - The path of the directory.
* @returns An object with directory utility functions.
*
* @example
// Create a directory
await dir('/path/to/directory').create();
// Check if the directory exists
const exists = await dir('/path/to/directory').exists();
// Remove the directory
// Retrieve children of the directory
const children = await dir('/path/to/parent_directory').children();
*/
export declare function dir(dirPath: string): OTDir;
export declare class OTDir {
#private;
get kind(): 'dir';
get name(): string;
get path(): string;
get parent(): OTDir | null;
constructor(dirPath: string);
/**
* Creates the directory.
* return A promise that resolves when the directory is created.
*/
create(): Promise<OTDir>;
/**
* Checks if the directory exists.
* return A promise that resolves to true if the directory exists, otherwise false.
*/
exists(): Promise<boolean>;
/**
* Removes the directory.
* return A promise that resolves when the directory is removed.
*/
remove(): Promise<void>;
/**
* Retrieves the children of the directory.
* return A promise that resolves to an array of objects representing the children.
*/
children(): Promise<Array<OTDir | OTFile>>;
/**
* If the dest folder exists, copy the current directory into the dest folder;
* if the dest folder does not exist, rename the current directory to dest name.
*/
copyTo(dest: OTDir): Promise<OTDir>;
copyTo(dest: FileSystemDirectoryHandle): Promise<null>;
/**
* move directory, copy then remove current
*/
moveTo(dest: OTDir): Promise<OTDir>;
}