import type { OneFSAdapter, OneFSConfig, OneFSFile, OneFSOpenOptions, OneFSSaveOptions, OneFSDirectory, OneFSDirectoryOptions, OneFSReadDirectoryOptions, OneFSScanOptions, OneFSEntry, StoredHandle, Platform, OneFSResult, OneFSErrorCode, OneFSError, OneFSCapabilities, PermissionMode, PermissionStatus } from './types'; import { ok, err, PLATFORM_CAPABILITIES } from './types'; import { FSAccessAdapter } from './adapters/fs-access'; import { PickerIDBAdapter } from './adapters/picker-idb'; import { TauriAdapter } from './adapters/tauri'; import { CapacitorAdapter } from './adapters/capacitor'; export type { OneFSAdapter, OneFSConfig, OneFSFile, OneFSOpenOptions, OneFSSaveOptions, OneFSDirectory, OneFSDirectoryOptions, OneFSReadDirectoryOptions, OneFSScanOptions, OneFSEntry, StoredHandle, Platform, OneFSResult, OneFSErrorCode, OneFSError, OneFSCapabilities, PermissionMode, PermissionStatus, }; export { ok, err, PLATFORM_CAPABILITIES }; export { FSAccessAdapter, PickerIDBAdapter, TauriAdapter, CapacitorAdapter }; /** * Cross-platform file system abstraction. * * Provides a unified API for file operations across: * - Modern browsers (File System Access API) * - Fallback browsers (file picker + IndexedDB) * - Tauri desktop apps * - Capacitor mobile apps * * @example * ```typescript * const fs = createOneFS({ appName: 'myapp' }) * * // Open a file * const result = await fs.openFile({ accept: ['.json'] }) * if (result.ok) { * const text = fs.readAsText(result.data) * } * * // Check platform capabilities * if (fs.capabilities.canSaveInPlace) { * await fs.saveFile(file, newContent) * } else { * // Will trigger download on web-fallback * await fs.saveFile(file, newContent) * } * ``` */ export declare class OneFS { private adapter; private config; constructor(config: OneFSConfig); private selectAdapter; /** Current platform identifier */ get platform(): Platform; /** Platform capabilities (what operations are available) */ get capabilities(): OneFSCapabilities; /** Whether directory operations are supported */ get supportsDirectories(): boolean; /** Whether file handles can be persisted and restored across sessions */ get supportsHandlePersistence(): boolean; /** * Open a file picker dialog. * @param options - Picker configuration (accept, startIn, persist) * @returns The selected file with content loaded as Uint8Array */ openFile(options?: OneFSOpenOptions): Promise>; openFile(options: OneFSOpenOptions & { multiple: true; }): Promise>; /** * Open a file picker for multiple files. * Convenience wrapper around openFile with multiple: true. */ openFiles(options?: Omit): Promise>; /** * Save content to an existing file. * * Behavior varies by platform: * - web-fs-access: Saves in-place to original location * - tauri: Saves in-place to original location * - web-fallback: Triggers a download (not in-place) * - capacitor: Saves to app's Data directory (not original location) * * Check `capabilities.canSaveInPlace` to detect behavior. * * @param file - The file to save to (must have handle/path from openFile) * @param content - New content as string or Uint8Array * @param options - Save options (persist) */ saveFile(file: OneFSFile, content: Uint8Array | string, options?: OneFSSaveOptions): Promise>; /** * Open a save dialog and write content to a new file. * @param content - Content to save as string or Uint8Array * @param options - Save options (suggestedName, accept, persist) * @returns The newly created file */ saveFileAs(content: Uint8Array | string, options?: OneFSSaveOptions): Promise>; /** * Open a directory picker dialog. * Not available on web-fallback platform. * @param options - Directory picker options (mode, persist) */ openDirectory(options?: OneFSDirectoryOptions): Promise>; /** * List directory contents as entries (metadata only, no content loaded). * Use readFileFromDirectory() to load a specific file's content. * * @param directory - Directory from openDirectory() * @returns Array of file and directory entries with metadata */ readDirectory(directory: OneFSDirectory, options?: OneFSReadDirectoryOptions): Promise>; /** * Load a specific file's content from a directory. * Use this instead of readDirectory to avoid loading all files at once. * * @param directory - Directory containing the file * @param entry - Entry from readDirectory() with kind === 'file' * @param options - Optional: maxBytes to read only first N bytes (for metadata extraction) * @returns The file with content loaded */ readFileFromDirectory(directory: OneFSDirectory, entry: OneFSEntry, options?: { maxBytes?: number; }): Promise>; /** * Recursively scan a directory for files. * Available on Tauri and Capacitor platforms. * * @param directory - Directory to scan * @param options - Scan options (extensions filter, progress callback, abort signal) */ scanDirectory(directory: OneFSDirectory, options?: OneFSScanOptions): Promise>; /** * Get an efficient streaming URL for a directory entry without loading content. * Available on Tauri and Capacitor platforms. Use for audio/video where you don't need file in memory. * * @param entry - Entry from readDirectory() or scanDirectory() * @returns Asset URL or null if not supported/available */ getEntryUrl(entry: OneFSEntry): Promise>; /** * Get an efficient URL for a file without re-reading content. * Available on Tauri and Capacitor. Falls back to blob URL. * * @param file - File to get URL for */ getFileUrl(file: OneFSFile): Promise>; /** * Get list of recently opened files. * On web-fs-access, these can be restored without picker. * On other platforms, content is restored from IndexedDB cache. */ getRecentFiles(): Promise; /** * Restore a previously opened file. * On web-fs-access: Re-reads from disk (may request permission) * On other platforms: Returns cached content from IndexedDB * * @param stored - Handle from getRecentFiles() */ restoreFile(stored: StoredHandle): Promise>; /** * Restore a previously opened directory. * Only available on web-fs-access platform. * * @param stored - Handle from getRecentFiles() with type === 'directory' * @param mode - Permission mode to request ('read' or 'readwrite') */ restoreDirectory(stored: StoredHandle, mode?: PermissionMode): Promise>; /** * Check current permission status on a file or directory. * Only available on web-fs-access platform - returns 'granted' on others. * * @param target - File or directory to check * @param mode - Permission mode to check ('read' or 'readwrite') */ queryPermission(target: OneFSFile | OneFSDirectory, mode: PermissionMode): Promise; /** * Request permission on a file or directory. * Only available on web-fs-access platform - returns ok(true) on others. * * @param target - File or directory to request permission for * @param mode - Permission mode to request ('read' or 'readwrite') */ requestPermission(target: OneFSFile | OneFSDirectory, mode: PermissionMode): Promise>; /** * Store a directory by a named key (separate from recent files). * Useful for app preferences like "output directory". * Only available on web-fs-access platform. * * @param key - Unique key to store the directory under * @param directory - Directory to persist */ setNamedDirectory(key: string, directory: OneFSDirectory): Promise>; /** * Retrieve a previously stored named directory. * Only available on web-fs-access platform. * * @param key - Key the directory was stored under * @param mode - Permission mode to request ('read' or 'readwrite') */ getNamedDirectory(key: string, mode?: PermissionMode): Promise>; /** * Remove a named directory from storage. * * @param key - Key the directory was stored under */ removeNamedDirectory(key: string): Promise; /** * Delete a file and remove it from storage. * Available on web-fs-access, Tauri, and Capacitor platforms. */ deleteFile(file: OneFSFile): Promise>; /** * Rename a file and update storage. * Available on web-fs-access, Tauri, and Capacitor platforms. */ renameFile(file: OneFSFile, newName: string): Promise>; /** * Remove a file from the recent files list. */ removeFromRecent(id: string): Promise; /** * Clear all recent files. */ clearRecent(): Promise; dispose(): void; /** * Read file content as UTF-8 string. */ readAsText(file: OneFSFile): string; /** * Read file content as parsed JSON. * Returns an error result if content is not valid JSON. */ readAsJSON(file: OneFSFile): OneFSResult; /** * Read file content as data URL (data:mime;base64,...). */ readAsDataURL(file: OneFSFile): string; /** * Read file content as Blob. */ readAsBlob(file: OneFSFile): Blob; /** * Read file content as object URL (blob:...). * Remember to call URL.revokeObjectURL() when done. */ readAsObjectURL(file: OneFSFile): string; } /** * Create a new OneFS instance. * * @param config - Configuration options * @returns OneFS instance configured for the current platform * * @example * ```typescript * const fs = createOneFS({ * appName: 'myapp', * maxRecentFiles: 20, * persistByDefault: true, * }) * ``` */ export declare function createOneFS(config: OneFSConfig): OneFS;