opfs-worker 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/raw.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"raw.js","sources":["../src/worker.ts"],"sourcesContent":["import { expose } from 'comlink';\n\n\nimport { decodeBuffer } from './utils/encoder';\nimport {\n FileNotFoundError,\n OPFSError,\n PathError\n} from './utils/errors';\n\nimport {\n basename,\n calculateFileHash,\n checkOPFSSupport,\n convertBlobToUint8Array,\n dirname,\n isBinaryFileExtension,\n joinPath,\n matchMinimatch,\n normalizeMinimatch,\n normalizePath,\n readFileData,\n removeEntry,\n resolvePath,\n splitPath,\n writeFileData\n} from './utils/helpers';\n\nimport type { DirentData, Encoding, FileStat, OPFSOptions, RenameOptions, WatchEvent, WatchOptions, WatchSnapshot } from './types';\nimport type { BufferEncoding } from 'typescript';\n\n/**\n * OPFS (Origin Private File System) File System implementation\n * \n * This class provides a high-level interface for working with the browser's\n * Origin Private File System API, offering file and directory operations\n * similar to Node.js fs module.\n * \n * @example\n * ```typescript\n * const fs = new OPFSFileSystem();\n * await fs.init('/my-app');\n * await fs.writeFile('/data/config.json', JSON.stringify({ theme: 'dark' }));\n * const config = await fs.readFile('/data/config.json');\n * ```\n */\nexport class OPFSWorker {\n /** Root directory handle for the file system */\n private root!: FileSystemDirectoryHandle;\n\n /** Map of watched paths and options */\n private watchers = new Map<string, WatchSnapshot>();\n\n /** Promise to prevent concurrent mount operations */\n private mountingPromise: Promise<boolean> | null = null;\n\n /** BroadcastChannel instance for sending events */\n private broadcastChannel: BroadcastChannel | null = null;\n\n /** Configuration options */\n private options: Required<OPFSOptions> = {\n root: '/',\n namespace: '',\n maxFileSize: 50 * 1024 * 1024,\n hashAlgorithm: null,\n broadcastChannel: 'opfs-worker',\n };\n\n\n /**\n * Notify about internal changes to the file system\n * \n * This method is called by internal operations to notify clients about\n * changes, even when no specific paths are being watched.\n * \n * @param path - The path that was changed\n * @param type - The type of change (create, change, delete)\n */\n private async notifyChange(event: Omit<WatchEvent, 'timestamp' | 'hash' | 'namespace'>): Promise<void> {\n // This instance not configured to send events\n if (!this.options.broadcastChannel) {\n return;\n }\n\n const path = event.path;\n\n const match = [...this.watchers.values()].some((snapshot) => {\n return (\n matchMinimatch(path, snapshot.pattern)\n && snapshot.include.some(include => include && matchMinimatch(path, include))\n && !snapshot.exclude.some(exclude => exclude && matchMinimatch(path, exclude))\n );\n });\n\n if (!match) {\n return;\n }\n\n let hash: string | undefined;\n\n if (this.options.hashAlgorithm) {\n try {\n const stat = await this.stat(path);\n\n hash = stat.hash;\n }\n catch {}\n }\n\n // Send event via BroadcastChannel\n try {\n if (!this.broadcastChannel) {\n this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel as string);\n }\n\n const watchEvent: WatchEvent = {\n namespace: this.options.namespace,\n timestamp: new Date().toISOString(),\n ...event,\n ...(hash && { hash }),\n };\n\n this.broadcastChannel.postMessage(watchEvent);\n }\n catch (error) {\n console.warn('Failed to send event via BroadcastChannel:', error);\n }\n }\n\n /**\n * Creates a new OPFSFileSystem instance\n * \n * @param options - Optional configuration options\n * @param options.root - Root path for the file system (default: '/')\n * @param options.watchInterval - Polling interval in milliseconds for file watching\n * @param options.hashAlgorithm - Hash algorithm for file hashing\n * @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)\n * @throws {OPFSError} If OPFS is not supported in the current browser\n */\n constructor(options?: OPFSOptions) {\n checkOPFSSupport();\n\n if (options) {\n void this.setOptions(options);\n }\n }\n\n /**\n * Initialize the file system within a given directory\n * \n * This method sets up the root directory for all subsequent operations.\n * If no root is specified, it will use the OPFS root directory.\n * \n * @param root - The root path for the file system (default: '/')\n * @returns Promise that resolves to true if initialization was successful\n * @throws {OPFSError} If initialization fails\n * \n * @example\n * ```typescript\n * const fs = new OPFSFileSystem();\n * \n * // Use OPFS root (default)\n * await fs.mount();\n * \n * // Use custom directory\n * await fs.mount('/my-app');\n * ```\n */\n private async mount(): Promise<boolean> {\n const root = this.options.root;\n\n // If already mounting, wait for previous operation to complete first\n if (this.mountingPromise) {\n await this.mountingPromise;\n }\n\n // eslint-disable-next-line no-async-promise-executor\n this.mountingPromise = new Promise<boolean>(async(resolve, reject) => {\n try {\n const rootDir = await navigator.storage.getDirectory();\n\n this.root = (root === '/') ? rootDir : await this.getDirectoryHandle(root, true, rootDir);\n\n resolve(true);\n }\n catch (error) {\n reject(new OPFSError('Failed to initialize OPFS', 'INIT_FAILED', root, error));\n }\n finally {\n this.mountingPromise = null;\n }\n });\n\n return this.mountingPromise;\n }\n\n\n /**\n * Update configuration options\n * \n * @param options - Configuration options to update\n * @param options.root - Root path for the file system\n * @param options.watchInterval - Polling interval in milliseconds for file watching\n * @param options.hashAlgorithm - Hash algorithm for file hashing\n * @param options.maxFileSize - Maximum file size for hashing in bytes\n * @param options.broadcastChannel - Custom name for the broadcast channel\n */\n async setOptions(options: OPFSOptions): Promise<void> {\n if (options.hashAlgorithm !== undefined) {\n this.options.hashAlgorithm = options.hashAlgorithm;\n }\n\n if (options.maxFileSize !== undefined) {\n this.options.maxFileSize = options.maxFileSize;\n }\n\n if (options.broadcastChannel !== undefined) {\n // Close existing channel if name changed\n if (this.broadcastChannel && this.options.broadcastChannel !== options.broadcastChannel) {\n this.broadcastChannel.close();\n this.broadcastChannel = null;\n }\n\n this.options.broadcastChannel = options.broadcastChannel;\n }\n\n if (options.namespace) {\n this.options.namespace = options.namespace;\n }\n\n if (options.root !== undefined) {\n this.options.root = normalizePath(options.root);\n\n if (!this.options.namespace) {\n this.options.namespace = `opfs-worker:${ this.options.root }`;\n }\n\n await this.mount();\n }\n }\n\n /**\n * Get a directory handle from a path\n * \n * Navigates through the directory structure to find or create a directory\n * at the specified path.\n * \n * @param path - The path to the directory (string or array of segments)\n * @param create - Whether to create the directory if it doesn't exist (default: false)\n * @param from - The directory to start from (default: root directory)\n * @returns Promise that resolves to the directory handle\n * @throws {OPFSError} If the directory cannot be accessed or created\n * \n * @example\n * ```typescript\n * const docsDir = await fs.getDirectoryHandle('/users/john/documents', true);\n * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);\n * ```\n */\n private async getDirectoryHandle(path: string | string[], create: boolean = false, from: FileSystemDirectoryHandle | null = this.root): Promise<FileSystemDirectoryHandle> {\n const segments = Array.isArray(path) ? path : splitPath(path);\n let current = from;\n\n for (const segment of segments) {\n current = await current!.getDirectoryHandle(segment, { create });\n }\n\n return current!;\n }\n\n /**\n * Get a file handle from a path\n * \n * Navigates to the parent directory and retrieves or creates a file handle\n * for the specified file path.\n * \n * @param path - The path to the file (string or array of segments)\n * @param create - Whether to create the file if it doesn't exist (default: false)\n * @param from - The directory to start from (default: root directory)\n * @returns Promise that resolves to the file handle\n * @throws {PathError} If the path is empty\n * @throws {OPFSError} If the file cannot be accessed or created\n * \n * @example\n * ```typescript\n * const fileHandle = await fs.getFileHandle('/config/settings.json', true);\n * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);\n * ```\n */\n private async getFileHandle(path: string | string[], create = false, from: FileSystemDirectoryHandle | null = this.root): Promise<FileSystemFileHandle> {\n const segments = splitPath(path);\n\n if (segments.length === 0) {\n throw new PathError('Path must not be empty', Array.isArray(path) ? path.join('/') : path);\n }\n\n const fileName = segments.pop()!;\n const dir = await this.getDirectoryHandle(segments, create, from);\n\n return dir.getFileHandle(fileName, { create });\n }\n\n /**\n * Get a complete index of all files and directories in the file system\n * \n * This method recursively traverses the entire file system and returns\n * a Map containing FileStat objects for every file and directory.\n * \n * @returns Promise that resolves to a Map of paths to FileStat objects\n * @throws {OPFSError} If the file system is not mounted\n * \n * @example\n * ```typescript\n * const index = await fs.index();\n * const fileStats = index.get('/data/config.json');\n * if (fileStats) {\n * console.log(`File size: ${fileStats.size} bytes`);\n * if (fileStats.hash) console.log(`Hash: ${fileStats.hash}`);\n * }\n * ```\n */\n async index(): Promise<Map<string, FileStat>> {\n const result = new Map<string, FileStat>();\n\n const walk = async(dirPath: string) => {\n const items = await this.readDir(dirPath);\n\n for (const item of items) {\n const fullPath = `${ dirPath === '/' ? '' : dirPath }/${ item.name }`;\n\n try {\n const stat = await this.stat(fullPath);\n\n result.set(fullPath, stat);\n\n if (stat.isDirectory) {\n await walk(fullPath);\n }\n }\n catch (err) {\n console.warn(`Skipping broken entry: ${ fullPath }`, err);\n }\n }\n };\n\n result.set('/', {\n kind: 'directory',\n size: 0,\n mtime: new Date(0).toISOString(),\n ctime: new Date(0).toISOString(),\n isFile: false,\n isDirectory: true,\n });\n\n await walk('/');\n\n return result;\n }\n\n /**\n * Read a file from the file system\n * \n * Reads the contents of a file and returns it as a string or binary data\n * depending on the specified encoding.\n * \n * @param path - The path to the file to read\n * @param encoding - The encoding to use for reading the file\n * @returns Promise that resolves to the file contents\n * @throws {FileNotFoundError} If the file does not exist\n * @throws {OPFSError} If reading the file fails\n * \n * @example\n * ```typescript\n * // Read as text\n * const content = await fs.readFile('/config/settings.json');\n * \n * // Read as binary\n * const binaryData = await fs.readFile('/images/logo.png', 'binary');\n * \n * // Read with specific encoding\n * const utf8Content = await fs.readFile('/data/utf8.txt', 'utf-8');\n * ```\n */\n async readFile(path: string, encoding: 'binary'): Promise<Uint8Array>;\n async readFile(path: string, encoding: Encoding): Promise<string>;\n async readFile(path: string, encoding: Encoding | 'binary'): Promise<string | Uint8Array>;\n async readFile(\n path: string,\n encoding?: any\n ): Promise<string | Uint8Array> {\n await this.mount();\n\n if (!encoding) {\n encoding = isBinaryFileExtension(path) ? 'binary' : 'utf-8';\n }\n\n try {\n const fileHandle = await this.getFileHandle(path, false, this.root);\n const buffer = await readFileData(fileHandle, path);\n\n return (encoding === 'binary') ? buffer : decodeBuffer(buffer, encoding);\n }\n catch (err) {\n throw new FileNotFoundError(path, err);\n }\n }\n\n /**\n * Write data to a file\n * \n * Creates or overwrites a file with the specified data. If the file already\n * exists, it will be truncated before writing.\n * \n * @param path - The path to the file to write\n * @param data - The data to write to the file (string, Uint8Array, or ArrayBuffer)\n * @param encoding - The encoding to use when writing string data (default: 'utf-8')\n * @returns Promise that resolves when the write operation is complete\n * @throws {OPFSError} If writing the file fails\n * \n * @example\n * ```typescript\n * // Write text data\n * await fs.writeFile('/config/settings.json', JSON.stringify({ theme: 'dark' }));\n * \n * // Write binary data\n * const binaryData = new Uint8Array([1, 2, 3, 4, 5]);\n * await fs.writeFile('/data/binary.dat', binaryData);\n * \n * // Write with specific encoding\n * await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');\n * ```\n */\n async writeFile(\n path: string,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: BufferEncoding\n ): Promise<void> {\n await this.mount();\n\n const fileExists = await this.exists(path);\n const fileHandle = await this.getFileHandle(path, true);\n\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(path)) ? 'binary' : 'utf-8';\n }\n\n await writeFileData(fileHandle, data, encoding, path);\n\n // Only notify changes if the file didn't exist before or if content actually changed\n if (!fileExists) {\n await this.notifyChange({ path, type: 'added', isDirectory: false });\n }\n else {\n await this.notifyChange({ path, type: 'changed', isDirectory: false });\n }\n }\n\n /**\n * Append data to a file\n * \n * Adds data to the end of an existing file. If the file doesn't exist,\n * it will be created.\n * \n * @param path - The path to the file to append to\n * @param data - The data to append to the file (string, Uint8Array, or ArrayBuffer)\n * @param encoding - The encoding to use when appending string data (default: 'utf-8')\n * @returns Promise that resolves when the append operation is complete\n * @throws {OPFSError} If appending to the file fails\n * \n * @example\n * ```typescript\n * // Append text to a log file\n * await fs.appendFile('/logs/app.log', `[${new Date().toISOString()}] User logged in\\n`);\n * \n * // Append binary data\n * const additionalData = new Uint8Array([6, 7, 8]);\n * await fs.appendFile('/data/binary.dat', additionalData);\n * ```\n */\n async appendFile(\n path: string,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: BufferEncoding\n ): Promise<void> {\n await this.mount();\n\n const fileHandle = await this.getFileHandle(path, true);\n\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(path)) ? 'binary' : 'utf-8';\n }\n\n await writeFileData(fileHandle, data, encoding, path, { append: true });\n await this.notifyChange({ path, type: 'changed', isDirectory: false });\n }\n\n /**\n * Create a directory\n * \n * Creates a new directory at the specified path. If the recursive option\n * is enabled, parent directories will be created as needed.\n * \n * @param path - The path where the directory should be created\n * @param options - Options for directory creation\n * @param options.recursive - Whether to create parent directories if they don't exist (default: false)\n * @returns Promise that resolves when the directory is created\n * @throws {OPFSError} If the directory cannot be created\n * \n * @example\n * ```typescript\n * // Create a single directory\n * await fs.mkdir('/users/john');\n * \n * // Create nested directories\n * await fs.mkdir('/users/john/documents/projects', { recursive: true });\n * ```\n */\n async mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {\n await this.mount();\n\n const recursive = options?.recursive ?? false;\n const segments = splitPath(path);\n\n let current: FileSystemDirectoryHandle | null = this.root;\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i];\n\n try {\n current = await current.getDirectoryHandle(segment!, { create: recursive || i === segments.length - 1 });\n }\n catch (err: any) {\n if (err.name === 'NotFoundError') {\n throw new OPFSError(\n `Parent directory does not exist: ${ joinPath(segments.slice(0, i + 1)) }`,\n 'ENOENT',\n undefined,\n err\n );\n }\n\n if (err.name === 'TypeMismatchError') {\n throw new OPFSError(`Path segment is not a directory: ${ segment }`, 'ENOTDIR', undefined, err);\n }\n\n throw new OPFSError('Failed to create directory', 'MKDIR_FAILED', undefined, err);\n }\n }\n\n await this.notifyChange({ path, type: 'added', isDirectory: true });\n }\n\n /**\n * Get file or directory statistics\n * \n * Returns detailed information about a file or directory, including\n * size, modification time, and optionally a hash of the file content.\n * \n * @param path - The path to the file or directory\n * @returns Promise that resolves to FileStat object\n * @throws {OPFSError} If the path does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * const stats = await fs.stat('/data/config.json');\n * console.log(`File size: ${stats.size} bytes`);\n * console.log(`Last modified: ${stats.mtime}`);\n * \n * // If hashing is enabled, hash will be included\n * if (stats.hash) {\n * console.log(`Hash: ${stats.hash}`);\n * }\n * ```\n */\n async stat(path: string): Promise<FileStat> {\n await this.mount();\n\n // Special handling for root directory\n if (path === '/') {\n return {\n kind: 'directory',\n size: 0,\n mtime: new Date(0).toISOString(),\n ctime: new Date(0).toISOString(),\n isFile: false,\n isDirectory: true,\n };\n }\n\n const name = basename(path);\n const parentDir = await this.getDirectoryHandle(dirname(path), false);\n const includeHash = this.options.hashAlgorithm !== null;\n\n try {\n const fileHandle = await parentDir.getFileHandle(name, { create: false });\n const file = await fileHandle.getFile();\n\n const baseStat: FileStat = {\n kind: 'file',\n size: file.size,\n mtime: new Date(file.lastModified).toISOString(),\n ctime: new Date(file.lastModified).toISOString(),\n isFile: true,\n isDirectory: false,\n };\n\n if (includeHash && this.options.hashAlgorithm) {\n try {\n const hash = await calculateFileHash(file, this.options.hashAlgorithm, this.options.maxFileSize);\n\n baseStat.hash = hash;\n }\n catch (error) {\n console.warn(`Failed to calculate hash for ${ path }:`, error);\n }\n }\n\n return baseStat;\n }\n catch (e: any) {\n if (e.name !== 'TypeMismatchError' && e.name !== 'NotFoundError') {\n throw new OPFSError('Failed to stat (file)', 'STAT_FAILED', undefined, e);\n }\n }\n\n try {\n await parentDir.getDirectoryHandle(name, { create: false });\n\n return {\n kind: 'directory',\n size: 0,\n mtime: new Date(0).toISOString(),\n ctime: new Date(0).toISOString(),\n isFile: false,\n isDirectory: true,\n };\n }\n catch (e: any) {\n if (e.name === 'NotFoundError') {\n throw new OPFSError(`No such file or directory: ${ path }`, 'ENOENT', undefined, e);\n }\n\n throw new OPFSError('Failed to stat (directory)', 'STAT_FAILED', undefined, e);\n }\n }\n\n /**\n * Read a directory's contents\n * \n * Lists all files and subdirectories within the specified directory.\n * \n * @param path - The path to the directory to read\n * @returns Promise that resolves to an array of detailed file/directory information\n * @throws {OPFSError} If the directory does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * // Get detailed information about files and directories\n * const detailed = await fs.readDir('/users/john/documents');\n * detailed.forEach(item => {\n * console.log(`${item.name} - ${item.isFile ? 'file' : 'directory'}`);\n * });\n * ```\n */\n async readDir(path: string): Promise<DirentData[]> {\n await this.mount();\n\n const dir = await this.getDirectoryHandle(path, false);\n\n const results: DirentData[] = [];\n\n for await (const [name, handle] of (dir as any).entries()) {\n const isFile = handle.kind === 'file';\n\n results.push({\n name,\n kind: handle.kind,\n isFile,\n isDirectory: !isFile,\n });\n }\n\n return results;\n }\n\n /**\n * Check if a file or directory exists\n * \n * Verifies if a file or directory exists at the specified path.\n * \n * @param path - The path to check\n * @returns Promise that resolves to true if the file or directory exists, false otherwise \n * \n * @example\n * ```typescript\n * const exists = await fs.exists('/config/settings.json');\n * console.log(`File exists: ${exists}`);\n * ```\n */\n async exists(path: string): Promise<boolean> {\n await this.mount();\n\n if (path === '/') {\n return true;\n }\n\n const name = basename(path);\n let dir: FileSystemDirectoryHandle | null = null;\n\n try {\n dir = await this.getDirectoryHandle(dirname(path), false);\n }\n catch (e: any) {\n if (e.name === 'NotFoundError' || e.name === 'TypeMismatchError') {\n dir = null;\n }\n\n throw e;\n }\n\n if (!dir || !name) {\n return false;\n }\n\n try {\n await dir.getFileHandle(name, { create: false });\n\n return true;\n }\n catch (err: any) {\n if (err.name !== 'NotFoundError' && err.name !== 'TypeMismatchError') {\n throw err;\n }\n\n try {\n await dir.getDirectoryHandle(name, { create: false });\n\n return true;\n }\n catch (err: any) {\n if (err.name !== 'NotFoundError' && err.name !== 'TypeMismatchError') {\n throw err;\n }\n\n return false;\n }\n }\n }\n\n /**\n * Clear all contents of a directory without removing the directory itself\n * \n * Removes all files and subdirectories within the specified directory,\n * but keeps the directory itself.\n * \n * @param path - The path to the directory to clear (default: '/')\n * @returns Promise that resolves when all contents are removed\n * @throws {OPFSError} If the operation fails\n * \n * @example\n * ```typescript\n * // Clear root directory contents\n * await fs.clear('/');\n * \n * // Clear specific directory contents\n * await fs.clear('/data');\n * ```\n */\n async clear(path: string = '/'): Promise<void> {\n await this.mount();\n\n try {\n const items = await this.readDir(path);\n\n for (const item of items) {\n const itemPath = `${ path === '/' ? '' : path }/${ item.name }`;\n\n await this.remove(itemPath, { recursive: true });\n }\n\n await this.notifyChange({ path, type: 'changed', isDirectory: true });\n }\n catch (error: any) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to clear directory: ${ path }`, 'CLEAR_FAILED', undefined, error);\n }\n }\n\n /**\n * Remove files and directories\n * \n * Removes files and directories. Similar to Node.js fs.rm().\n * \n * @param path - The path to remove\n * @param options - Options for removal\n * @param options.recursive - Whether to remove directories and their contents recursively (default: false)\n * @param options.force - Whether to ignore errors if the path doesn't exist (default: false)\n * @returns Promise that resolves when the removal is complete\n * @throws {OPFSError} If the removal fails\n * \n * @example\n * ```typescript\n * // Remove a file\n * await fs.rm('/path/to/file.txt');\n * \n * // Remove a directory and all its contents\n * await fs.rm('/path/to/directory', { recursive: true });\n * \n * // Remove with force (ignore if doesn't exist)\n * await fs.rm('/maybe/exists', { force: true });\n * ```\n */\n async remove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n await this.mount();\n\n // Special handling for root directory\n if (path === '/') {\n throw new OPFSError('Cannot remove root directory', 'EROOT');\n }\n\n const { recursive = false, force = false } = options || {};\n\n const parent = await this.getDirectoryHandle(dirname(path), false);\n\n await removeEntry(parent, path, { recursive, force });\n\n await this.notifyChange({ path, type: 'removed', isDirectory: false });\n }\n\n /**\n * Resolve a path to an absolute path\n * \n * Resolves relative paths and normalizes path segments (like '..' and '.').\n * Similar to Node.js fs.realpath() but without symlink resolution since OPFS doesn't support symlinks.\n * \n * @param path - The path to resolve\n * @returns Promise that resolves to the absolute normalized path\n * @throws {FileNotFoundError} If the path does not exist\n * @throws {OPFSError} If path resolution fails\n * \n * @example\n * ```typescript\n * // Resolve relative path\n * const absolute = await fs.realpath('./config/../data/file.txt');\n * console.log(absolute); // '/data/file.txt'\n * ```\n */\n async realpath(path: string): Promise<string> {\n await this.mount();\n\n try {\n const normalizedPath = resolvePath(path);\n const exists = await this.exists(normalizedPath);\n\n if (!exists) {\n throw new FileNotFoundError(normalizedPath);\n }\n\n return normalizedPath;\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to resolve path: ${ path }`, 'REALPATH_FAILED', undefined, error);\n }\n }\n\n /**\n * Rename a file or directory\n * \n * Changes the name of a file or directory. If the target path already exists,\n * it will be replaced only if overwrite option is enabled.\n * \n * @param oldPath - The current path of the file or directory\n * @param newPath - The new path for the file or directory\n * @param options - Options for renaming\n * @param options.overwrite - Whether to overwrite existing files (default: false)\n * @returns Promise that resolves when the rename operation is complete\n * @throws {OPFSError} If the rename operation fails\n * \n * @example\n * ```typescript\n * // Basic rename (fails if target exists)\n * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');\n * \n * // Rename with overwrite\n * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });\n * ```\n */\n async rename(oldPath: string, newPath: string, options?: RenameOptions): Promise<void> {\n await this.mount();\n\n try {\n const overwrite = options?.overwrite ?? false;\n\n const sourceExists = await this.exists(oldPath);\n\n if (!sourceExists) {\n throw new FileNotFoundError(oldPath);\n }\n\n const destExists = await this.exists(newPath);\n\n if (destExists && !overwrite) {\n throw new OPFSError(`Destination already exists: ${ newPath }`, 'EEXIST', undefined);\n }\n\n await this.copy(oldPath, newPath, { recursive: true, overwrite });\n await this.remove(oldPath, { recursive: true });\n\n // Notify about the rename operation\n await this.notifyChange({ path: oldPath, type: 'removed', isDirectory: false });\n await this.notifyChange({ path: newPath, type: 'added', isDirectory: false });\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to rename from ${ oldPath } to ${ newPath }`, 'RENAME_FAILED', undefined, error);\n }\n }\n\n /**\n * Copy files and directories\n * \n * Copies files and directories. Similar to Node.js fs.cp().\n * \n * @param source - The source path to copy from\n * @param destination - The destination path to copy to\n * @param options - Options for copying\n * @param options.recursive - Whether to copy directories recursively (default: false)\n * @param options.overwrite - Whether to overwrite existing files (default: true)\n * @returns Promise that resolves when the copy operation is complete\n * @throws {OPFSError} If the copy operation fails\n * \n * @example\n * ```typescript\n * // Copy a file\n * await fs.copy('/source/file.txt', '/dest/file.txt');\n * \n * // Copy a directory and all its contents\n * await fs.copy('/source/dir', '/dest/dir', { recursive: true });\n * \n * // Copy without overwriting existing files\n * await fs.copy('/source', '/dest', { recursive: true, overwrite: false });\n * ```\n */\n async copy(source: string, destination: string, options?: { recursive?: boolean; overwrite?: boolean }): Promise<void> {\n await this.mount();\n\n try {\n const recursive = options?.recursive ?? false;\n const overwrite = options?.overwrite ?? true;\n\n const sourceExists = await this.exists(source);\n\n if (!sourceExists) {\n throw new OPFSError(`Source does not exist: ${ source }`, 'ENOENT', undefined);\n }\n\n const destExists = await this.exists(destination);\n\n if (destExists && !overwrite) {\n throw new OPFSError(`Destination already exists: ${ destination }`, 'EEXIST', undefined);\n }\n\n const sourceStats = await this.stat(source);\n\n if (sourceStats.isFile) {\n const content = await this.readFile(source, 'binary');\n\n await this.writeFile(destination, content);\n }\n else {\n if (!recursive) {\n throw new OPFSError(`Cannot copy directory without recursive option: ${ source }`, 'EISDIR', undefined);\n }\n\n await this.mkdir(destination, { recursive: true });\n\n const items = await this.readDir(source);\n\n for (const item of items) {\n const sourceItemPath = `${ source }/${ item.name }`;\n const destItemPath = `${ destination }/${ item.name }`;\n\n await this.copy(sourceItemPath, destItemPath, { recursive: true, overwrite });\n }\n }\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to copy from ${ source } to ${ destination }`, 'CP_FAILED', undefined, error);\n }\n }\n\n /**\n * Start watching a file or directory for changes\n * \n * @param path - The path to watch (minimatch syntax allowed)\n * @param options - Watch options\n * @param options.recursive - Whether to watch recursively (default: true)\n * @param options.exclude - Glob pattern(s) to exclude (minimatch).\n * @returns Promise that resolves when watching starts\n * \n * @example\n * ```typescript\n * // Watch entire directory tree recursively (default)\n * await fs.watch('/data');\n * \n * // Watch only immediate children (shallow)\n * await fs.watch('/data', { recursive: false });\n * \n * // Watch a single file\n * await fs.watch('/config.json', { recursive: false });\n * \n * // Watch all json files but not in dist directory\n * await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });\n *\n * ```\n */\n async watch(path: string, options?: WatchOptions): Promise<void> {\n if (!this.options.broadcastChannel) {\n throw new OPFSError('This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.', 'ENOENT');\n }\n\n const snapshot: WatchSnapshot = {\n pattern: normalizeMinimatch(path, options?.recursive ?? true),\n include: Array.isArray(options?.include) ? options.include : [options?.include ?? '**'],\n exclude: Array.isArray(options?.exclude) ? options.exclude : [options?.exclude ?? ''],\n };\n\n this.watchers.set(path, snapshot);\n }\n\n /**\n * Stop watching a previously watched path\n */\n unwatch(path: string): void {\n this.watchers.delete(path);\n }\n\n /**\n * Dispose of resources and clean up the file system instance\n * \n * This method should be called when the file system instance is no longer needed\n * to properly clean up resources like the broadcast channel and watch timers.\n */\n dispose(): void {\n if (this.broadcastChannel) {\n this.broadcastChannel.close();\n this.broadcastChannel = null;\n }\n\n this.watchers.clear();\n }\n\n /**\n * Synchronize the file system with external data\n * \n * Syncs the file system with an array of entries containing paths and data.\n * This is useful for importing data from external sources or syncing with remote data.\n * \n * @param entries - Array of [path, data] tuples to sync\n * @param options - Options for synchronization\n * @param options.cleanBefore - Whether to clear the file system before syncing (default: false)\n * @returns Promise that resolves when synchronization is complete\n * @throws {OPFSError} If the synchronization fails\n * \n * @example\n * ```typescript\n * // Sync with external data\n * const entries: [string, string | Uint8Array | Blob][] = [\n * ['/config.json', JSON.stringify({ theme: 'dark' })],\n * ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],\n * ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })]\n * ];\n * \n * // Sync without clearing existing files\n * await fs.sync(entries);\n * \n * // Clean file system and then sync\n * await fs.sync(entries, { cleanBefore: true });\n * ```\n */\n async sync(entries: [string, string | Uint8Array | Blob][], options?: { cleanBefore?: boolean }): Promise<void> {\n await this.mount();\n\n try {\n const cleanBefore = options?.cleanBefore ?? false;\n\n if (cleanBefore) {\n await this.clear('/');\n }\n\n for (const [path, data] of entries) {\n const normalizedPath = normalizePath(path);\n\n let fileData: string | Uint8Array;\n\n if (data instanceof Blob) {\n fileData = await convertBlobToUint8Array(data);\n }\n else {\n fileData = data;\n }\n\n await this.writeFile(normalizedPath, fileData);\n }\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError('Failed to sync file system', 'SYNC_FAILED', undefined, error);\n }\n }\n}\n\n// Only expose the worker when running in a Web Worker environment\nif (typeof globalThis !== 'undefined' && globalThis.constructor.name === 'DedicatedWorkerGlobalScope') {\n expose(new OPFSWorker());\n}\n"],"names":["OPFSWorker","event","path","snapshot","matchMinimatch","include","exclude","hash","watchEvent","error","options","checkOPFSSupport","root","resolve","reject","rootDir","OPFSError","normalizePath","create","from","segments","splitPath","current","segment","PathError","fileName","result","walk","dirPath","items","item","fullPath","stat","err","encoding","isBinaryFileExtension","fileHandle","buffer","readFileData","decodeBuffer","FileNotFoundError","data","fileExists","writeFileData","recursive","i","joinPath","name","basename","parentDir","dirname","includeHash","file","baseStat","calculateFileHash","e","dir","results","handle","isFile","itemPath","force","parent","removeEntry","normalizedPath","resolvePath","oldPath","newPath","overwrite","source","destination","content","sourceItemPath","destItemPath","normalizeMinimatch","entries","fileData","convertBlobToUint8Array","expose"],"mappings":";;AA8CO,MAAMA,EAAW;AAAA;AAAA,EAEZ;AAAA;AAAA,EAGA,+BAAe,IAAA;AAAA;AAAA,EAGf,kBAA2C;AAAA;AAAA,EAG3C,mBAA4C;AAAA;AAAA,EAG5C,UAAiC;AAAA,IACrC,MAAM;AAAA,IACN,WAAW;AAAA,IACX,aAAa,KAAK,OAAO;AAAA,IACzB,eAAe;AAAA,IACf,kBAAkB;AAAA,EAAA;AAAA;AAAA;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nimport { decodeBuffer, isBinaryFileExtension } from './utils/encoder';\nimport {\n FileNotFoundError,\n OPFSError,\n PathError,\n createFDError\n} from './utils/errors';\n\nimport {\n basename,\n calculateFileHash,\n calculateReadLength,\n checkOPFSSupport,\n convertBlobToUint8Array,\n createSyncHandleSafe,\n dirname,\n joinPath,\n matchMinimatch,\n normalizeMinimatch,\n normalizePath,\n readFileData,\n removeEntry,\n resolvePath,\n safeCloseSyncHandle,\n splitPath,\n validateReadWriteArgs,\n withLock,\n writeFileData\n} from './utils/helpers';\n\nimport type { DirentData, Encoding, FileOpenOptions, FileStat, OPFSOptions, RenameOptions, WatchEvent, WatchOptions, WatchSnapshot } from './types';\nimport type { BufferEncoding } from 'typescript';\n\n\n/**\n * OPFS (Origin Private File System) File System implementation\n * \n * This class provides a high-level interface for working with the browser's\n * Origin Private File System API, offering file and directory operations\n * similar to Node.js fs module.\n * \n * @example\n * ```typescript\n * const fs = new OPFSFileSystem();\n * await fs.init('/my-app');\n * await fs.writeFile('/data/config.json', JSON.stringify({ theme: 'dark' }));\n * const config = await fs.readFile('/data/config.json');\n * ```\n */\nexport class OPFSWorker {\n /** Root directory handle for the file system */\n private root!: FileSystemDirectoryHandle;\n\n /** Map of watched paths and options */\n private watchers = new Map<string, WatchSnapshot>();\n\n /** Promise to prevent concurrent mount operations */\n private mountingPromise: Promise<boolean> | null = null;\n\n /** BroadcastChannel instance for sending events */\n private broadcastChannel: BroadcastChannel | null = null;\n\n /** Configuration options */\n private options: Required<OPFSOptions> = {\n root: '/',\n namespace: '',\n maxFileSize: 50 * 1024 * 1024,\n hashAlgorithm: null,\n broadcastChannel: 'opfs-worker',\n };\n\n /** Map of open file descriptors to their metadata */\n private openFiles = new Map<number, {\n path: string;\n fileHandle: FileSystemFileHandle;\n syncHandle: FileSystemSyncAccessHandle;\n position: number;\n }>();\n\n /** Next available file descriptor number */\n private nextFd = 1;\n\n /**\n * Get file info by descriptor with validation\n * @private\n */\n private _getFileDescriptor(fd: number): { path: string; fileHandle: FileSystemFileHandle; syncHandle: FileSystemSyncAccessHandle; position: number } {\n const fileInfo = this.openFiles.get(fd);\n\n if (!fileInfo) {\n throw new OPFSError(`Invalid file descriptor: ${ fd }`, 'EBADF');\n }\n\n return fileInfo;\n }\n\n\n /**\n * Notify about internal changes to the file system\n * \n * This method is called by internal operations to notify clients about\n * changes, even when no specific paths are being watched.\n * \n * @param path - The path that was changed\n * @param type - The type of change (create, change, delete)\n */\n private async notifyChange(event: Omit<WatchEvent, 'timestamp' | 'hash' | 'namespace'>): Promise<void> {\n // This instance not configured to send events\n if (!this.options.broadcastChannel) {\n return;\n }\n\n const path = event.path;\n\n const match = [...this.watchers.values()].some((snapshot) => {\n return (\n matchMinimatch(path, snapshot.pattern)\n && snapshot.include.some(include => include && matchMinimatch(path, include))\n && !snapshot.exclude.some(exclude => exclude && matchMinimatch(path, exclude))\n );\n });\n\n if (!match) {\n return;\n }\n\n let hash: string | undefined;\n\n if (this.options.hashAlgorithm) {\n try {\n const stat = await this.stat(path);\n\n hash = stat.hash;\n }\n catch {}\n }\n\n // Send event via BroadcastChannel\n try {\n if (!this.broadcastChannel) {\n this.broadcastChannel = new BroadcastChannel(this.options.broadcastChannel as string);\n }\n\n const watchEvent: WatchEvent = {\n namespace: this.options.namespace,\n timestamp: new Date().toISOString(),\n ...event,\n ...(hash && { hash }),\n };\n\n this.broadcastChannel.postMessage(watchEvent);\n }\n catch (error) {\n console.warn('Failed to send event via BroadcastChannel:', error);\n }\n }\n\n /**\n * Creates a new OPFSFileSystem instance\n * \n * @param options - Optional configuration options\n * @param options.root - Root path for the file system (default: '/')\n * @param options.watchInterval - Polling interval in milliseconds for file watching\n * @param options.hashAlgorithm - Hash algorithm for file hashing\n * @param options.maxFileSize - Maximum file size for hashing in bytes (default: 50MB)\n * @throws {OPFSError} If OPFS is not supported in the current browser\n */\n constructor(options?: OPFSOptions) {\n checkOPFSSupport();\n\n if (options) {\n void this.setOptions(options);\n }\n }\n\n /**\n * Initialize the file system within a given directory\n * \n * This method sets up the root directory for all subsequent operations.\n * If no root is specified, it will use the OPFS root directory.\n * \n * @param root - The root path for the file system (default: '/')\n * @returns Promise that resolves to true if initialization was successful\n * @throws {OPFSError} If initialization fails\n * \n * @example\n * ```typescript\n * const fs = new OPFSFileSystem();\n * \n * // Use OPFS root (default)\n * await fs.mount();\n * \n * // Use custom directory\n * await fs.mount('/my-app');\n * ```\n */\n private async mount(): Promise<boolean> {\n const root = this.options.root;\n\n // If already mounting, wait for previous operation to complete first\n if (this.mountingPromise) {\n await this.mountingPromise;\n }\n\n // eslint-disable-next-line no-async-promise-executor\n this.mountingPromise = new Promise<boolean>(async(resolve, reject) => {\n try {\n const rootDir = await navigator.storage.getDirectory();\n\n this.root = (root === '/') ? rootDir : await this.getDirectoryHandle(root, true, rootDir);\n\n resolve(true);\n }\n catch (error) {\n reject(new OPFSError('Failed to initialize OPFS', 'INIT_FAILED', root, error));\n }\n finally {\n this.mountingPromise = null;\n }\n });\n\n return this.mountingPromise;\n }\n\n\n /**\n * Update configuration options\n * \n * @param options - Configuration options to update\n * @param options.root - Root path for the file system\n * @param options.watchInterval - Polling interval in milliseconds for file watching\n * @param options.hashAlgorithm - Hash algorithm for file hashing\n * @param options.maxFileSize - Maximum file size for hashing in bytes\n * @param options.broadcastChannel - Custom name for the broadcast channel\n */\n async setOptions(options: OPFSOptions): Promise<void> {\n if (options.hashAlgorithm !== undefined) {\n this.options.hashAlgorithm = options.hashAlgorithm;\n }\n\n if (options.maxFileSize !== undefined) {\n this.options.maxFileSize = options.maxFileSize;\n }\n\n if (options.broadcastChannel !== undefined) {\n // Close existing channel if name changed\n if (this.broadcastChannel && this.options.broadcastChannel !== options.broadcastChannel) {\n this.broadcastChannel.close();\n this.broadcastChannel = null;\n }\n\n this.options.broadcastChannel = options.broadcastChannel;\n }\n\n if (options.namespace) {\n this.options.namespace = options.namespace;\n }\n\n if (options.root !== undefined) {\n this.options.root = normalizePath(options.root);\n\n if (!this.options.namespace) {\n this.options.namespace = `opfs-worker:${ this.options.root }`;\n }\n\n await this.mount();\n }\n }\n\n /**\n * Get a directory handle from a path\n * \n * Navigates through the directory structure to find or create a directory\n * at the specified path.\n * \n * @param path - The path to the directory (string or array of segments)\n * @param create - Whether to create the directory if it doesn't exist (default: false)\n * @param from - The directory to start from (default: root directory)\n * @returns Promise that resolves to the directory handle\n * @throws {OPFSError} If the directory cannot be accessed or created\n * \n * @example\n * ```typescript\n * const docsDir = await fs.getDirectoryHandle('/users/john/documents', true);\n * const docsDir2 = await fs.getDirectoryHandle(['users', 'john', 'documents'], true);\n * ```\n */\n private async getDirectoryHandle(path: string | string[], create: boolean = false, from: FileSystemDirectoryHandle | null = this.root): Promise<FileSystemDirectoryHandle> {\n const segments = Array.isArray(path) ? path : splitPath(path);\n let current = from;\n\n for (const segment of segments) {\n current = await current!.getDirectoryHandle(segment, { create });\n }\n\n return current!;\n }\n\n /**\n * Get a file handle from a path\n * \n * Navigates to the parent directory and retrieves or creates a file handle\n * for the specified file path.\n * \n * @param path - The path to the file (string or array of segments)\n * @param create - Whether to create the file if it doesn't exist (default: false)\n * @param _from - The directory to start from (default: root directory)\n * @returns Promise that resolves to the file handle\n * @throws {PathError} If the path is empty\n * @throws {OPFSError} If the file cannot be accessed or created\n * \n * @example\n * ```typescript\n * const fileHandle = await fs.getFileHandle('/config/settings.json', true);\n * const fileHandle2 = await fs.getFileHandle(['config', 'settings.json'], true);\n * ```\n */\n private async getFileHandle(path: string | string[], create = false, _from: FileSystemDirectoryHandle | null = this.root): Promise<FileSystemFileHandle> {\n const segments = splitPath(path);\n\n if (segments.length === 0) {\n throw new PathError('Path must not be empty', Array.isArray(path) ? path.join('/') : path);\n }\n\n const fileName = segments.pop()!;\n const dir = await this.getDirectoryHandle(segments, create, _from);\n\n return dir.getFileHandle(fileName, { create });\n }\n\n /**\n * Get a complete index of all files and directories in the file system\n * \n * This method recursively traverses the entire file system and returns\n * a Map containing FileStat objects for every file and directory.\n * \n * @returns Promise that resolves to a Map of paths to FileStat objects\n * @throws {OPFSError} If the file system is not mounted\n * \n * @example\n * ```typescript\n * const index = await fs.index();\n * const fileStats = index.get('/data/config.json');\n * if (fileStats) {\n * console.log(`File size: ${fileStats.size} bytes`);\n * if (fileStats.hash) console.log(`Hash: ${fileStats.hash}`);\n * }\n * ```\n */\n async index(): Promise<Map<string, FileStat>> {\n const result = new Map<string, FileStat>();\n\n const walk = async(dirPath: string) => {\n const items = await this.readDir(dirPath);\n\n for (const item of items) {\n const fullPath = `${ dirPath === '/' ? '' : dirPath }/${ item.name }`;\n\n try {\n const stat = await this.stat(fullPath);\n\n result.set(fullPath, stat);\n\n if (stat.isDirectory) {\n await walk(fullPath);\n }\n }\n catch (err) {\n console.warn(`Skipping broken entry: ${ fullPath }`, err);\n }\n }\n };\n\n result.set('/', {\n kind: 'directory',\n size: 0,\n mtime: new Date(0).toISOString(),\n ctime: new Date(0).toISOString(),\n isFile: false,\n isDirectory: true,\n });\n\n await walk('/');\n\n return result;\n }\n\n /**\n * Read a file from the file system\n * \n * Reads the contents of a file and returns it as a string or binary data\n * depending on the specified encoding.\n * \n * @param path - The path to the file to read\n * @param encoding - The encoding to use for reading the file\n * @returns Promise that resolves to the file contents\n * @throws {FileNotFoundError} If the file does not exist\n * @throws {OPFSError} If reading the file fails\n * \n * @example\n * ```typescript\n * // Read as text\n * const content = await fs.readFile('/config/settings.json');\n * \n * // Read as binary\n * const binaryData = await fs.readFile('/images/logo.png', 'binary');\n * \n * // Read with specific encoding\n * const utf8Content = await fs.readFile('/data/utf8.txt', 'utf-8');\n * ```\n */\n async readFile(path: string, encoding: 'binary'): Promise<Uint8Array>;\n async readFile(path: string, encoding: Encoding): Promise<string>;\n async readFile(path: string, encoding: Encoding | 'binary'): Promise<string | Uint8Array>;\n async readFile(\n path: string,\n encoding?: any\n ): Promise<string | Uint8Array> {\n await this.mount();\n\n if (!encoding) {\n encoding = isBinaryFileExtension(path) ? 'binary' : 'utf-8';\n }\n\n try {\n const fileHandle = await this.getFileHandle(path, false, this.root);\n const buffer = await readFileData(fileHandle, path);\n\n return (encoding === 'binary') ? buffer : decodeBuffer(buffer, encoding);\n }\n catch (err) {\n throw new FileNotFoundError(path, err);\n }\n }\n\n /**\n * Write data to a file\n * \n * Creates or overwrites a file with the specified data. If the file already\n * exists, it will be truncated before writing.\n * \n * @param path - The path to the file to write\n * @param data - The data to write to the file (string, Uint8Array, or ArrayBuffer)\n * @param encoding - The encoding to use when writing string data (default: 'utf-8')\n * @returns Promise that resolves when the write operation is complete\n * @throws {OPFSError} If writing the file fails\n * \n * @example\n * ```typescript\n * // Write text data\n * await fs.writeFile('/config/settings.json', JSON.stringify({ theme: 'dark' }));\n * \n * // Write binary data\n * const binaryData = new Uint8Array([1, 2, 3, 4, 5]);\n * await fs.writeFile('/data/binary.dat', binaryData);\n * \n * // Write with specific encoding\n * await fs.writeFile('/data/utf16.txt', 'Hello World', 'utf-16le');\n * ```\n */\n async writeFile(\n path: string,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: BufferEncoding\n ): Promise<void> {\n await this.mount();\n\n const fileExists = await this.exists(path);\n const fileHandle = await this.getFileHandle(path, true);\n\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(path)) ? 'binary' : 'utf-8';\n }\n\n await writeFileData(fileHandle, data, encoding, path);\n\n // Only notify changes if the file didn't exist before or if content actually changed\n if (!fileExists) {\n await this.notifyChange({ path, type: 'added', isDirectory: false });\n }\n else {\n await this.notifyChange({ path, type: 'changed', isDirectory: false });\n }\n }\n\n /**\n * Append data to a file\n * \n * Adds data to the end of an existing file. If the file doesn't exist,\n * it will be created.\n * \n * @param path - The path to the file to append to\n * @param data - The data to append to the file (string, Uint8Array, or ArrayBuffer)\n * @param encoding - The encoding to use when appending string data (default: 'utf-8')\n * @returns Promise that resolves when the append operation is complete\n * @throws {OPFSError} If appending to the file fails\n * \n * @example\n * ```typescript\n * // Append text to a log file\n * await fs.appendFile('/logs/app.log', `[${new Date().toISOString()}] User logged in\\n`);\n * \n * // Append binary data\n * const additionalData = new Uint8Array([6, 7, 8]);\n * await fs.appendFile('/data/binary.dat', additionalData);\n * ```\n */\n async appendFile(\n path: string,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: BufferEncoding\n ): Promise<void> {\n await this.mount();\n\n const fileHandle = await this.getFileHandle(path, true);\n\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(path)) ? 'binary' : 'utf-8';\n }\n\n await writeFileData(fileHandle, data, encoding, path, { append: true });\n await this.notifyChange({ path, type: 'changed', isDirectory: false });\n }\n\n /**\n * Create a directory\n * \n * Creates a new directory at the specified path. If the recursive option\n * is enabled, parent directories will be created as needed.\n * \n * @param path - The path where the directory should be created\n * @param options - Options for directory creation\n * @param options.recursive - Whether to create parent directories if they don't exist (default: false)\n * @returns Promise that resolves when the directory is created\n * @throws {OPFSError} If the directory cannot be created\n * \n * @example\n * ```typescript\n * // Create a single directory\n * await fs.mkdir('/users/john');\n * \n * // Create nested directories\n * await fs.mkdir('/users/john/documents/projects', { recursive: true });\n * ```\n */\n async mkdir(path: string, options?: { recursive?: boolean }): Promise<void> {\n await this.mount();\n\n const recursive = options?.recursive ?? false;\n const segments = splitPath(path);\n\n let current: FileSystemDirectoryHandle | null = this.root;\n\n for (let i = 0; i < segments.length; i++) {\n const segment = segments[i];\n\n try {\n current = await current.getDirectoryHandle(segment!, { create: recursive || i === segments.length - 1 });\n }\n catch (err: any) {\n if (err.name === 'NotFoundError') {\n throw new OPFSError(\n `Parent directory does not exist: ${ joinPath(segments.slice(0, i + 1)) }`,\n 'ENOENT',\n undefined,\n err\n );\n }\n\n if (err.name === 'TypeMismatchError') {\n throw new OPFSError(`Path segment is not a directory: ${ segment }`, 'ENOTDIR', undefined, err);\n }\n\n throw new OPFSError('Failed to create directory', 'MKDIR_FAILED', undefined, err);\n }\n }\n\n await this.notifyChange({ path, type: 'added', isDirectory: true });\n }\n\n /**\n * Get file or directory statistics\n * \n * Returns detailed information about a file or directory, including\n * size, modification time, and optionally a hash of the file content.\n * \n * @param path - The path to the file or directory\n * @returns Promise that resolves to FileStat object\n * @throws {OPFSError} If the path does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * const stats = await fs.stat('/data/config.json');\n * console.log(`File size: ${stats.size} bytes`);\n * console.log(`Last modified: ${stats.mtime}`);\n * \n * // If hashing is enabled, hash will be included\n * if (stats.hash) {\n * console.log(`Hash: ${stats.hash}`);\n * }\n * ```\n */\n async stat(path: string): Promise<FileStat> {\n await this.mount();\n\n // Special handling for root directory\n if (path === '/') {\n return {\n kind: 'directory',\n size: 0,\n mtime: new Date(0).toISOString(),\n ctime: new Date(0).toISOString(),\n isFile: false,\n isDirectory: true,\n };\n }\n\n const name = basename(path);\n const parentDir = await this.getDirectoryHandle(dirname(path), false);\n const includeHash = this.options.hashAlgorithm !== null;\n\n try {\n const fileHandle = await parentDir.getFileHandle(name, { create: false });\n const file = await fileHandle.getFile();\n\n const baseStat: FileStat = {\n kind: 'file',\n size: file.size,\n mtime: new Date(file.lastModified).toISOString(),\n ctime: new Date(file.lastModified).toISOString(),\n isFile: true,\n isDirectory: false,\n };\n\n if (includeHash && this.options.hashAlgorithm) {\n try {\n const hash = await calculateFileHash(file, this.options.hashAlgorithm, this.options.maxFileSize);\n\n baseStat.hash = hash;\n }\n catch (error) {\n console.warn(`Failed to calculate hash for ${ path }:`, error);\n }\n }\n\n return baseStat;\n }\n catch (e: any) {\n if (e.name !== 'TypeMismatchError' && e.name !== 'NotFoundError') {\n throw new OPFSError('Failed to stat (file)', 'STAT_FAILED', undefined, e);\n }\n }\n\n try {\n await parentDir.getDirectoryHandle(name, { create: false });\n\n return {\n kind: 'directory',\n size: 0,\n mtime: new Date(0).toISOString(),\n ctime: new Date(0).toISOString(),\n isFile: false,\n isDirectory: true,\n };\n }\n catch (e: any) {\n if (e.name === 'NotFoundError') {\n throw new OPFSError(`No such file or directory: ${ path }`, 'ENOENT', undefined, e);\n }\n\n throw new OPFSError('Failed to stat (directory)', 'STAT_FAILED', undefined, e);\n }\n }\n\n /**\n * Read a directory's contents\n * \n * Lists all files and subdirectories within the specified directory.\n * \n * @param path - The path to the directory to read\n * @returns Promise that resolves to an array of detailed file/directory information\n * @throws {OPFSError} If the directory does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * // Get detailed information about files and directories\n * const detailed = await fs.readDir('/users/john/documents');\n * detailed.forEach(item => {\n * console.log(`${item.name} - ${item.isFile ? 'file' : 'directory'}`);\n * });\n * ```\n */\n async readDir(path: string): Promise<DirentData[]> {\n await this.mount();\n\n const dir = await this.getDirectoryHandle(path, false);\n\n const results: DirentData[] = [];\n\n for await (const [name, handle] of (dir as any).entries()) {\n const isFile = handle.kind === 'file';\n\n results.push({\n name,\n kind: handle.kind,\n isFile,\n isDirectory: !isFile,\n });\n }\n\n return results;\n }\n\n /**\n * Check if a file or directory exists\n * \n * Verifies if a file or directory exists at the specified path.\n * \n * @param path - The path to check\n * @returns Promise that resolves to true if the file or directory exists, false otherwise \n * \n * @example\n * ```typescript\n * const exists = await fs.exists('/config/settings.json');\n * console.log(`File exists: ${exists}`);\n * ```\n */\n async exists(path: string): Promise<boolean> {\n await this.mount();\n\n if (path === '/') {\n return true;\n }\n\n const name = basename(path);\n let dir: FileSystemDirectoryHandle | null = null;\n\n try {\n dir = await this.getDirectoryHandle(dirname(path), false);\n }\n catch (e: any) {\n dir = null;\n\n if (e.name !== 'NotFoundError' && e.name !== 'TypeMismatchError') {\n throw e;\n }\n }\n\n if (!dir || !name) {\n return false;\n }\n\n try {\n await dir.getFileHandle(name, { create: false });\n\n return true;\n }\n catch (err: any) {\n if (err.name !== 'NotFoundError' && err.name !== 'TypeMismatchError') {\n throw err;\n }\n\n try {\n await dir.getDirectoryHandle(name, { create: false });\n\n return true;\n }\n catch (err: any) {\n if (err.name !== 'NotFoundError' && err.name !== 'TypeMismatchError') {\n throw err;\n }\n\n return false;\n }\n }\n }\n\n /**\n * Clear all contents of a directory without removing the directory itself\n * \n * Removes all files and subdirectories within the specified directory,\n * but keeps the directory itself.\n * \n * @param path - The path to the directory to clear (default: '/')\n * @returns Promise that resolves when all contents are removed\n * @throws {OPFSError} If the operation fails\n * \n * @example\n * ```typescript\n * // Clear root directory contents\n * await fs.clear('/');\n * \n * // Clear specific directory contents\n * await fs.clear('/data');\n * ```\n */\n async clear(path: string = '/'): Promise<void> {\n await this.mount();\n\n try {\n const items = await this.readDir(path);\n\n for (const item of items) {\n const itemPath = `${ path === '/' ? '' : path }/${ item.name }`;\n\n await this.remove(itemPath, { recursive: true });\n }\n\n await this.notifyChange({ path, type: 'changed', isDirectory: true });\n }\n catch (error: any) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to clear directory: ${ path }`, 'CLEAR_FAILED', undefined, error);\n }\n }\n\n /**\n * Remove files and directories\n * \n * Removes files and directories. Similar to Node.js fs.rm().\n * \n * @param path - The path to remove\n * @param options - Options for removal\n * @param options.recursive - Whether to remove directories and their contents recursively (default: false)\n * @param options.force - Whether to ignore errors if the path doesn't exist (default: false)\n * @returns Promise that resolves when the removal is complete\n * @throws {OPFSError} If the removal fails\n * \n * @example\n * ```typescript\n * // Remove a file\n * await fs.rm('/path/to/file.txt');\n * \n * // Remove a directory and all its contents\n * await fs.rm('/path/to/directory', { recursive: true });\n * \n * // Remove with force (ignore if doesn't exist)\n * await fs.rm('/maybe/exists', { force: true });\n * ```\n */\n async remove(path: string, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n await this.mount();\n\n // Special handling for root directory\n if (path === '/') {\n throw new OPFSError('Cannot remove root directory', 'EROOT');\n }\n\n const { recursive = false, force = false } = options || {};\n\n const parent = await this.getDirectoryHandle(dirname(path), false);\n\n await removeEntry(parent, path, { recursive, force });\n\n await this.notifyChange({ path, type: 'removed', isDirectory: false });\n }\n\n /**\n * Resolve a path to an absolute path\n * \n * Resolves relative paths and normalizes path segments (like '..' and '.').\n * Similar to Node.js fs.realpath() but without symlink resolution since OPFS doesn't support symlinks.\n * \n * @param path - The path to resolve\n * @returns Promise that resolves to the absolute normalized path\n * @throws {FileNotFoundError} If the path does not exist\n * @throws {OPFSError} If path resolution fails\n * \n * @example\n * ```typescript\n * // Resolve relative path\n * const absolute = await fs.realpath('./config/../data/file.txt');\n * console.log(absolute); // '/data/file.txt'\n * ```\n */\n async realpath(path: string): Promise<string> {\n await this.mount();\n\n try {\n const normalizedPath = resolvePath(path);\n const exists = await this.exists(normalizedPath);\n\n if (!exists) {\n throw new FileNotFoundError(normalizedPath);\n }\n\n return normalizedPath;\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to resolve path: ${ path }`, 'REALPATH_FAILED', undefined, error);\n }\n }\n\n /**\n * Rename a file or directory\n * \n * Changes the name of a file or directory. If the target path already exists,\n * it will be replaced only if overwrite option is enabled.\n * \n * @param oldPath - The current path of the file or directory\n * @param newPath - The new path for the file or directory\n * @param options - Options for renaming\n * @param options.overwrite - Whether to overwrite existing files (default: false)\n * @returns Promise that resolves when the rename operation is complete\n * @throws {OPFSError} If the rename operation fails\n * \n * @example\n * ```typescript\n * // Basic rename (fails if target exists)\n * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');\n * \n * // Rename with overwrite\n * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt', { overwrite: true });\n * ```\n */\n async rename(oldPath: string, newPath: string, options?: RenameOptions): Promise<void> {\n await this.mount();\n\n try {\n const overwrite = options?.overwrite ?? false;\n\n const sourceExists = await this.exists(oldPath);\n\n if (!sourceExists) {\n throw new FileNotFoundError(oldPath);\n }\n\n const destExists = await this.exists(newPath);\n\n if (destExists && !overwrite) {\n throw new OPFSError(`Destination already exists: ${ newPath }`, 'EEXIST', undefined);\n }\n\n await this.copy(oldPath, newPath, { recursive: true, overwrite });\n await this.remove(oldPath, { recursive: true });\n\n // Notify about the rename operation\n await this.notifyChange({ path: oldPath, type: 'removed', isDirectory: false });\n await this.notifyChange({ path: newPath, type: 'added', isDirectory: false });\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to rename from ${ oldPath } to ${ newPath }`, 'RENAME_FAILED', undefined, error);\n }\n }\n\n /**\n * Copy files and directories\n * \n * Copies files and directories. Similar to Node.js fs.cp().\n * \n * @param source - The source path to copy from\n * @param destination - The destination path to copy to\n * @param options - Options for copying\n * @param options.recursive - Whether to copy directories recursively (default: false)\n * @param options.overwrite - Whether to overwrite existing files (default: true)\n * @returns Promise that resolves when the copy operation is complete\n * @throws {OPFSError} If the copy operation fails\n * \n * @example\n * ```typescript\n * // Copy a file\n * await fs.copy('/source/file.txt', '/dest/file.txt');\n * \n * // Copy a directory and all its contents\n * await fs.copy('/source/dir', '/dest/dir', { recursive: true });\n * \n * // Copy without overwriting existing files\n * await fs.copy('/source', '/dest', { recursive: true, overwrite: false });\n * ```\n */\n async copy(source: string, destination: string, options?: { recursive?: boolean; overwrite?: boolean }): Promise<void> {\n await this.mount();\n\n try {\n const recursive = options?.recursive ?? false;\n const overwrite = options?.overwrite ?? true;\n\n const sourceExists = await this.exists(source);\n\n if (!sourceExists) {\n throw new OPFSError(`Source does not exist: ${ source }`, 'ENOENT', undefined);\n }\n\n const destExists = await this.exists(destination);\n\n if (destExists && !overwrite) {\n throw new OPFSError(`Destination already exists: ${ destination }`, 'EEXIST', undefined);\n }\n\n const sourceStats = await this.stat(source);\n\n if (sourceStats.isFile) {\n const content = await this.readFile(source, 'binary');\n\n await this.writeFile(destination, content);\n }\n else {\n if (!recursive) {\n throw new OPFSError(`Cannot copy directory without recursive option: ${ source }`, 'EISDIR', undefined);\n }\n\n await this.mkdir(destination, { recursive: true });\n\n const items = await this.readDir(source);\n\n for (const item of items) {\n const sourceItemPath = `${ source }/${ item.name }`;\n const destItemPath = `${ destination }/${ item.name }`;\n\n await this.copy(sourceItemPath, destItemPath, { recursive: true, overwrite });\n }\n }\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to copy from ${ source } to ${ destination }`, 'CP_FAILED', undefined, error);\n }\n }\n\n /**\n * Start watching a file or directory for changes\n * \n * @param path - The path to watch (minimatch syntax allowed)\n * @param options - Watch options\n * @param options.recursive - Whether to watch recursively (default: true)\n * @param options.exclude - Glob pattern(s) to exclude (minimatch).\n * @returns Promise that resolves when watching starts\n * \n * @example\n * ```typescript\n * // Watch entire directory tree recursively (default)\n * await fs.watch('/data');\n * \n * // Watch only immediate children (shallow)\n * await fs.watch('/data', { recursive: false });\n * \n * // Watch a single file\n * await fs.watch('/config.json', { recursive: false });\n * \n * // Watch all json files but not in dist directory\n * await fs.watch('/**\\/*.json', { recursive: false, exclude: ['dist/**'] });\n *\n * ```\n */\n async watch(path: string, options?: WatchOptions): Promise<void> {\n if (!this.options.broadcastChannel) {\n throw new OPFSError('This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.', 'ENOENT');\n }\n\n const snapshot: WatchSnapshot = {\n pattern: normalizeMinimatch(path, options?.recursive ?? true),\n include: Array.isArray(options?.include) ? options.include : [options?.include ?? '**'],\n exclude: Array.isArray(options?.exclude) ? options.exclude : [options?.exclude ?? ''],\n };\n\n this.watchers.set(path, snapshot);\n }\n\n /**\n * Stop watching a previously watched path\n */\n unwatch(path: string): void {\n this.watchers.delete(path);\n }\n\n /**\n * Open a file and return a file descriptor\n * \n * @param path - The path to the file to open\n * @param options - Options for opening the file\n * @param options.create - Whether to create the file if it doesn't exist (default: false)\n * @param options.exclusive - If true and create is true, fails if file already exists (default: false)\n * Note: This is best-effort in OPFS, not fully atomic due to browser limitations\n * @param options.truncate - Whether to truncate the file to zero length (default: false)\n * @returns Promise that resolves to a file descriptor number\n * @throws {OPFSError} If opening the file fails\n * \n * @example\n * ```typescript\n * // Open existing file for reading\n * const fd = await fs.open('/data/config.json');\n * \n * // Create new file for writing\n * const fd = await fs.open('/data/new.txt', { create: true });\n * \n * // Create file exclusively (fails if exists)\n * const fd = await fs.open('/data/unique.txt', { create: true, exclusive: true });\n * \n * // Open and truncate file\n * const fd = await fs.open('/data/log.txt', { create: true, truncate: true });\n * ```\n */\n async open(path: string, options?: FileOpenOptions): Promise<number> {\n await this.mount();\n\n const { create = false, exclusive = false, truncate = false } = options || {};\n\n // Normalize path to prevent path-related issues\n const normalizedPath = normalizePath(resolvePath(path));\n\n try {\n // Use lock for atomic operations when creating files\n if (create && exclusive) {\n return await withLock(normalizedPath, 'exclusive', async() => {\n const exists = await this.exists(normalizedPath);\n\n if (exists) {\n throw new OPFSError(`File already exists: ${ normalizedPath }`, 'EEXIST', normalizedPath);\n }\n\n return this._openFile(normalizedPath, create, truncate);\n });\n }\n\n return await this._openFile(normalizedPath, create, truncate);\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to open file: ${ normalizedPath }`, 'OPEN_FAILED', normalizedPath, error);\n }\n }\n\n /**\n * Internal method to open a file (without locking)\n * @private\n */\n private async _openFile(path: string, create: boolean, truncate: boolean): Promise<number> {\n const fileHandle = await this.getFileHandle(path, create);\n\n // Verify that we got a file handle, not a directory\n try {\n // If getFile() succeeds, it's a file\n await fileHandle.getFile();\n }\n catch (error: any) {\n if (error.name === 'TypeMismatchError') {\n throw new OPFSError(`Is a directory: ${ path }`, 'EISDIR', path);\n }\n\n throw error;\n }\n\n // Create sync access handle safely with proper error mapping\n const syncHandle = await createSyncHandleSafe(fileHandle, path);\n\n // If truncate is requested, use efficient truncate() method\n if (truncate) {\n syncHandle.truncate(0);\n syncHandle.flush();\n }\n\n const fd = this.nextFd++;\n\n this.openFiles.set(fd, {\n path,\n fileHandle,\n syncHandle,\n position: 0,\n });\n\n return fd;\n }\n\n /**\n * Close a file descriptor\n * \n * @param fd - The file descriptor to close\n * @returns Promise that resolves when the file descriptor is closed\n * @throws {OPFSError} If the file descriptor is invalid or closing fails\n * \n * @example\n * ```typescript\n * const fd = await fs.open('/data/file.txt');\n * // ... use the file descriptor ...\n * await fs.close(fd);\n * ```\n */\n async close(fd: number): Promise<void> {\n const fileInfo = this._getFileDescriptor(fd);\n\n safeCloseSyncHandle(fd, fileInfo.syncHandle, fileInfo.path);\n\n this.openFiles.delete(fd);\n }\n\n /**\n * Read data from a file descriptor\n * \n * @param fd - The file descriptor to read from\n * @param buffer - The buffer to read data into\n * @param offset - The offset in the buffer to start writing at\n * @param length - The number of bytes to read\n * @param position - The position in the file to read from (null for current position)\n * @returns Promise that resolves to the number of bytes read and the modified buffer\n * @throws {OPFSError} If the file descriptor is invalid or reading fails\n * \n * @note This method uses Comlink.transfer() to efficiently pass the buffer as a Transferable Object,\n * ensuring zero-copy performance across Web Worker boundaries.\n * \n * @example\n * ```typescript\n * const fd = await fs.open('/data/file.txt');\n * const buffer = new Uint8Array(1024);\n * const { bytesRead, buffer: modifiedBuffer } = await fs.read(fd, buffer, 0, 1024, null);\n * console.log(`Read ${bytesRead} bytes`);\n * // Use modifiedBuffer which contains the actual data\n * await fs.close(fd);\n * ```\n */\n async read(\n fd: number,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number | null | undefined\n ): Promise<{ bytesRead: number; buffer: Uint8Array }> {\n const fileInfo = this._getFileDescriptor(fd);\n\n // Validate arguments\n validateReadWriteArgs(buffer.length, offset, length, position);\n\n try {\n const readPosition = position ?? fileInfo.position;\n\n // Get file size and calculate read length\n const fileSize = fileInfo.syncHandle.getSize();\n const { isEOF, actualLength } = calculateReadLength(readPosition, length, fileSize);\n\n if (isEOF) {\n return transfer({ bytesRead: 0, buffer }, [buffer.buffer]); // End of file\n }\n\n // Create a subarray view for the read operation\n const targetBuffer = buffer.subarray(offset, offset + actualLength);\n\n // Perform efficient positioned read\n const bytesRead = fileInfo.syncHandle.read(targetBuffer, { at: readPosition });\n\n // Update position if position was not explicitly specified (null means use current position)\n if (position === null) {\n fileInfo.position = readPosition + bytesRead;\n }\n\n return transfer({ bytesRead, buffer }, [buffer.buffer]);\n }\n catch (error) {\n throw createFDError('read', fd, fileInfo.path, error);\n }\n }\n\n /**\n * Write data to a file descriptor\n * \n * @param fd - The file descriptor to write to\n * @param buffer - The buffer containing data to write\n * @param offset - The offset in the buffer to start reading from (default: 0)\n * @param length - The number of bytes to write (default: entire buffer)\n * @param position - The position in the file to write to (null/undefined for current position)\n * @returns Promise that resolves to the number of bytes written\n * @throws {OPFSError} If the file descriptor is invalid or writing fails\n * \n * @example\n * ```typescript\n * const fd = await fs.open('/data/file.txt', { create: true });\n * const data = new TextEncoder().encode('Hello, World!');\n * const bytesWritten = await fs.write(fd, data, 0, data.length, null);\n * console.log(`Wrote ${bytesWritten} bytes`);\n * await fs.close(fd);\n * ```\n */\n async write(\n fd: number,\n buffer: Uint8Array,\n offset: number = 0,\n length?: number,\n position?: number | null | undefined\n ): Promise<number> {\n const fileInfo = this._getFileDescriptor(fd);\n\n // Calculate actual length to write\n const actualLength = length ?? (buffer.length - offset);\n\n // Validate arguments using helper\n validateReadWriteArgs(buffer.length, offset, actualLength, position);\n\n try {\n // Determine write position: use specified position, or current position if null/undefined\n const writePosition = position ?? fileInfo.position;\n\n // Create a subarray view for the write operation\n const sourceBuffer = buffer.subarray(offset, offset + actualLength);\n\n // Perform efficient positioned write\n const bytesWritten = fileInfo.syncHandle.write(sourceBuffer, { at: writePosition });\n\n // Update position if position was null or undefined (i.e., use current position)\n // Also update position when writing at current position (position === fileInfo.position)\n if (position == null || position === fileInfo.position) {\n fileInfo.position = writePosition + bytesWritten;\n }\n\n // Notify about the change\n await this.notifyChange({ path: fileInfo.path, type: 'changed', isDirectory: false });\n\n return bytesWritten;\n }\n catch (error) {\n throw createFDError('write', fd, fileInfo.path, error);\n }\n }\n\n /**\n * Get file status information by file descriptor\n * \n * @param fd - The file descriptor\n * @returns Promise that resolves to FileStat object\n * @throws {OPFSError} If the file descriptor is invalid\n * \n * @example\n * ```typescript\n * const fd = await fs.open('/data/file.txt');\n * const stats = await fs.fstat(fd);\n * console.log(`File size: ${stats.size} bytes`);\n * console.log(`Last modified: ${stats.mtime}`);\n * \n * // If hashing is enabled, hash will be included\n * if (stats.hash) {\n * console.log(`Hash: ${stats.hash}`);\n * }\n * ```\n */\n async fstat(fd: number): Promise<FileStat> {\n const fileInfo = this._getFileDescriptor(fd);\n\n // Simply reuse existing stat() method with the file path\n return this.stat(fileInfo.path);\n }\n\n /**\n * Truncate file to specified size\n * \n * @param fd - The file descriptor\n * @param size - The new size of the file (default: 0)\n * @returns Promise that resolves when truncation is complete\n * @throws {OPFSError} If the file descriptor is invalid or truncation fails\n * \n * @example\n * ```typescript\n * const fd = await fs.open('/data/file.txt', { create: true });\n * await fs.truncate(fd, 100); // Truncate to 100 bytes\n * ```\n */\n async ftruncate(fd: number, size: number = 0): Promise<void> {\n const fileInfo = this._getFileDescriptor(fd);\n\n // Validate size parameter\n if (size < 0 || !Number.isInteger(size)) {\n throw new OPFSError('Invalid size', 'EINVAL');\n }\n\n try {\n fileInfo.syncHandle.truncate(size);\n fileInfo.syncHandle.flush();\n\n // Adjust position if it's beyond the new file size\n if (fileInfo.position > size) {\n fileInfo.position = size;\n }\n\n await this.notifyChange({ path: fileInfo.path, type: 'changed', isDirectory: false });\n }\n catch (error) {\n throw createFDError('truncate', fd, fileInfo.path, error);\n }\n }\n\n /**\n * Synchronize file data to storage (fsync equivalent)\n * \n * @param fd - The file descriptor\n * @returns Promise that resolves when synchronization is complete\n * @throws {OPFSError} If the file descriptor is invalid or sync fails\n * \n * @example\n * ```typescript\n * const fd = await fs.open('/data/file.txt', { create: true });\n * await fs.write(fd, data);\n * await fs.fsync(fd); // Ensure data is written to storage\n * ```\n */\n async fsync(fd: number): Promise<void> {\n const fileInfo = this._getFileDescriptor(fd);\n\n try {\n fileInfo.syncHandle.flush();\n }\n catch (error) {\n throw createFDError('sync', fd, fileInfo.path, error);\n }\n }\n\n /**\n * Dispose of resources and clean up the file system instance\n * \n * This method should be called when the file system instance is no longer needed\n * to properly clean up resources like the broadcast channel and watch timers.\n */\n dispose(): void {\n if (this.broadcastChannel) {\n this.broadcastChannel.close();\n this.broadcastChannel = null;\n }\n\n this.watchers.clear();\n\n // Close all open file descriptors\n for (const [fd, fileInfo] of this.openFiles) {\n safeCloseSyncHandle(fd, fileInfo.syncHandle, fileInfo.path);\n }\n\n this.openFiles.clear();\n this.nextFd = 1;\n }\n\n /**\n * Synchronize the file system with external data\n * \n * Syncs the file system with an array of entries containing paths and data.\n * This is useful for importing data from external sources or syncing with remote data.\n * \n * @param entries - Array of [path, data] tuples to sync\n * @param options - Options for synchronization\n * @param options.cleanBefore - Whether to clear the file system before syncing (default: false)\n * @returns Promise that resolves when synchronization is complete\n * @throws {OPFSError} If the synchronization fails\n * \n * @example\n * ```typescript\n * // Sync with external data\n * const entries: [string, string | Uint8Array | Blob][] = [\n * ['/config.json', JSON.stringify({ theme: 'dark' })],\n * ['/data/binary.dat', new Uint8Array([1, 2, 3, 4])],\n * ['/upload.txt', new Blob(['file content'], { type: 'text/plain' })]\n * ];\n * \n * // Sync without clearing existing files\n * await fs.sync(entries);\n * \n * // Clean file system and then sync\n * await fs.sync(entries, { cleanBefore: true });\n * ```\n */\n async sync(entries: [string, string | Uint8Array | Blob][], options?: { cleanBefore?: boolean }): Promise<void> {\n await this.mount();\n\n try {\n const cleanBefore = options?.cleanBefore ?? false;\n\n if (cleanBefore) {\n await this.clear('/');\n }\n\n for (const [path, data] of entries) {\n const normalizedPath = normalizePath(path);\n\n let fileData: string | Uint8Array;\n\n if (data instanceof Blob) {\n fileData = await convertBlobToUint8Array(data);\n }\n else {\n fileData = data;\n }\n\n await this.writeFile(normalizedPath, fileData);\n }\n }\n catch (error) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError('Failed to sync file system', 'SYNC_FAILED', undefined, error);\n }\n }\n}\n\n// Only expose the worker when running in a Web Worker environment\nif (typeof globalThis !== 'undefined' && globalThis.constructor.name === 'DedicatedWorkerGlobalScope') {\n expose(new OPFSWorker());\n}\n"],"names":["OPFSWorker","fd","fileInfo","OPFSError","event","path","snapshot","matchMinimatch","include","exclude","hash","watchEvent","error","options","checkOPFSSupport","root","resolve","reject","rootDir","normalizePath","create","from","segments","splitPath","current","segment","_from","PathError","fileName","result","walk","dirPath","items","item","fullPath","stat","err","encoding","isBinaryFileExtension","fileHandle","buffer","readFileData","decodeBuffer","FileNotFoundError","data","fileExists","writeFileData","recursive","i","joinPath","name","basename","parentDir","dirname","includeHash","file","baseStat","calculateFileHash","e","dir","results","handle","isFile","itemPath","force","parent","removeEntry","normalizedPath","resolvePath","oldPath","newPath","overwrite","source","destination","content","sourceItemPath","destItemPath","normalizeMinimatch","exclusive","truncate","withLock","syncHandle","createSyncHandleSafe","safeCloseSyncHandle","offset","length","position","validateReadWriteArgs","readPosition","fileSize","isEOF","actualLength","calculateReadLength","transfer","targetBuffer","bytesRead","createFDError","writePosition","sourceBuffer","bytesWritten","size","entries","fileData","convertBlobToUint8Array","expose"],"mappings":";;AAoDO,MAAMA,EAAW;AAAA;AAAA,EAEZ;AAAA;AAAA,EAGA,+BAAe,IAAA;AAAA;AAAA,EAGf,kBAA2C;AAAA;AAAA,EAG3C,mBAA4C;AAAA;AAAA,EAG5C,UAAiC;AAAA,IACrC,MAAM;AAAA,IACN,WAAW;AAAA,IACX,aAAa,KAAK,OAAO;AAAA,IACzB,eAAe;AAAA,IACf,kBAAkB;AAAA,EAAA;AAAA;AAAA,EAId,gCAAgB,IAAA;AAAA;AAAA,EAQhB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA,EAMT,mBAAmBC,GAA0H;AACjJ,UAAMC,IAAW,KAAK,UAAU,IAAID,CAAE;AAEtC,QAAI,CAACC;AACD,YAAM,IAAIC,EAAU,4BAA6BF,CAAG,IAAI,OAAO;AAGnE,WAAOC;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAc,aAAaE,GAA4E;AAEnG,QAAI,CAAC,KAAK,QAAQ;AACd;AAGJ,UAAMC,IAAOD,EAAM;AAUnB,QAAI,CARU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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BA,MAAM,KAAKmG,GAAiDxF,GAAoD;AAC5G,UAAM,KAAK,MAAA;AAEX,QAAI;AAGA,OAFoBA,GAAS,eAAe,OAGxC,MAAM,KAAK,MAAM,GAAG;AAGxB,iBAAW,CAACR,GAAMuC,CAAI,KAAKyD,GAAS;AAChC,cAAMlC,IAAiBhD,EAAcd,CAAI;AAEzC,YAAIiG;AAEJ,QAAI1D,aAAgB,OAChB0D,IAAW,MAAMC,EAAwB3D,CAAI,IAG7C0D,IAAW1D,GAGf,MAAM,KAAK,UAAUuB,GAAgBmC,CAAQ;AAAA,MACjD;AAAA,IACJ,SACO1F,GAAO;AACV,YAAIA,aAAiBT,IACXS,IAGJ,IAAIT,EAAU,8BAA8B,eAAe,QAAWS,CAAK;AAAA,IACrF;AAAA,EACJ;AACJ;AAGI,OAAO,aAAe,OAAe,WAAW,YAAY,SAAS,gCACrE4F,EAAO,IAAIxG,GAAY;"}
package/dist/types.d.ts CHANGED
@@ -52,6 +52,11 @@ export interface WatchOptions {
52
52
  /** Glob patterns to exclude from watching (minimatch syntax, default: []) */
53
53
  exclude?: string | string[];
54
54
  }
55
+ export interface FileOpenOptions {
56
+ create?: boolean;
57
+ exclusive?: boolean;
58
+ truncate?: boolean;
59
+ }
55
60
  export interface WatchSnapshot {
56
61
  pattern: string;
57
62
  include: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,WAAW,CAAC;AAExC,MAAM,MAAM,QAAQ,GAAG,OAAO,GAC1B,MAAM,GACN,OAAO,GACP,SAAS,GACT,UAAU,GACV,MAAM,GACN,O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type { Encoding } from '../types';
2
2
  import type { BufferEncoding } from 'typescript';
3
+ /**
4
+ * Common binary file extensions
5
+ */
6
+ export declare const BINARY_FILE_EXTENSIONS: readonly [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".ico", ".tiff", ".tga", ".mp3", ".wav", ".ogg", ".flac", ".aac", ".wma", ".m4a", ".mp4", ".avi", ".mov", ".wmv", ".flv", ".webm", ".mkv", ".m4v", ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".zip", ".rar", ".7z", ".tar", ".gz", ".bz2", ".exe", ".dll", ".so", ".dylib", ".dat", ".db", ".sqlite", ".bin", ".obj", ".fbx", ".3ds"];
7
+ /**
8
+ * Check if a file extension indicates a binary file
9
+ *
10
+ * @param path - The file path or filename
11
+ * @returns True if the file extension suggests binary content
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * isBinaryFileExtension('/path/to/image.jpg'); // true
16
+ * isBinaryFileExtension('/path/to/document.txt'); // false
17
+ * isBinaryFileExtension('data.bin'); // true
18
+ * isBinaryFileExtension('data'); // true
19
+ * ```
20
+ */
21
+ export declare function isBinaryFileExtension(path: string): boolean;
3
22
  export declare function encodeString(data: string, encoding?: BufferEncoding): Uint8Array;
4
23
  export declare function decodeBuffer(buffer: Uint8Array, encoding?: Encoding): string;
5
24
  //# sourceMappingURL=encoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/utils/encoder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,cAAwB,GAAG,UAAU,CAmCzF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAE,QAAkB,GAAG,MAAM,CA6BrF"}
1
+ {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../src/utils/encoder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGjD;;GAEG;AACH,eAAO,MAAM,sBAAsB,oZAwDzB,CAAC;AAEX;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAU3D;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,cAAwB,GAAG,UAAU,CAmCzF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,GAAE,QAAkB,GAAG,MAAM,CA6BrF"}
@@ -54,4 +54,27 @@ export declare class StorageError extends OPFSError {
54
54
  export declare class TimeoutError extends OPFSError {
55
55
  constructor(operation: string, path?: string, cause?: unknown);
56
56
  }
57
+ /**
58
+ * Create an OPFSError with file descriptor context
59
+ *
60
+ * @param operation - The operation that failed (e.g., 'read', 'write', 'close')
61
+ * @param fd - The file descriptor number
62
+ * @param path - The file path
63
+ * @param error - The underlying error (optional)
64
+ * @returns OPFSError with appropriate context
65
+ */
66
+ export declare function createFDError(operation: string, fd: number, path: string, error?: any): OPFSError;
67
+ /**
68
+ * Map DOM exceptions to OPFS error codes
69
+ *
70
+ * @param error - The DOM exception to map
71
+ * @param context - Context information for better error mapping
72
+ * @param context.path - File path for context-specific errors
73
+ * @param context.isDirectory - Whether the operation involves a directory
74
+ * @returns OPFSError with appropriate error code
75
+ */
76
+ export declare function mapDomError(error: any, context?: {
77
+ path?: string;
78
+ isDirectory?: boolean;
79
+ }): OPFSError;
57
80
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;A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,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,SAAS,CAIjG;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CA8CrG"}
@@ -1,22 +1,4 @@
1
1
  import type { BufferEncoding } from 'typescript';
2
- /**
3
- * Common binary file extensions
4
- */
5
- export declare const BINARY_FILE_EXTENSIONS: readonly [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp", ".svg", ".ico", ".tiff", ".tga", ".mp3", ".wav", ".ogg", ".flac", ".aac", ".wma", ".m4a", ".mp4", ".avi", ".mov", ".wmv", ".flv", ".webm", ".mkv", ".m4v", ".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".zip", ".rar", ".7z", ".tar", ".gz", ".bz2", ".exe", ".dll", ".so", ".dylib", ".bin", ".dat", ".db", ".sqlite", ".bin", ".obj", ".fbx", ".3ds"];
6
- /**
7
- * Check if a file extension indicates a binary file
8
- *
9
- * @param path - The file path or filename
10
- * @returns True if the file extension suggests binary content
11
- *
12
- * @example
13
- * ```typescript
14
- * isBinaryFileExtension('/path/to/image.jpg'); // true
15
- * isBinaryFileExtension('/path/to/document.txt'); // false
16
- * isBinaryFileExtension('data.bin'); // true
17
- * ```
18
- */
19
- export declare function isBinaryFileExtension(path: string): boolean;
20
2
  /**
21
3
  * Check if the browser supports the OPFS API
22
4
  *
@@ -200,4 +182,44 @@ export declare function removeEntry(parentHandle: FileSystemDirectoryHandle, pat
200
182
  force?: boolean;
201
183
  useTrash?: boolean;
202
184
  }): Promise<void>;
185
+ /**
186
+ * Validate read/write arguments for file descriptor operations
187
+ *
188
+ * @param bufferLen - Length of the buffer
189
+ * @param offset - Offset in the buffer
190
+ * @param length - Number of bytes to read/write
191
+ * @param position - Position in the file (null for current position)
192
+ * @param opts - Options for validation
193
+ * @throws {OPFSError} If arguments are invalid
194
+ */
195
+ export declare function validateReadWriteArgs(bufferLen: number, offset: number, length: number, position: number | null | undefined): void;
196
+ /**
197
+ * Safely close a file descriptor's sync handle
198
+ *
199
+ * @param fd - The file descriptor number (for logging)
200
+ * @param syncHandle - The sync handle to close
201
+ * @param path - The file path (for logging)
202
+ */
203
+ export declare function safeCloseSyncHandle(fd: number, syncHandle: any, path: string): void;
204
+ /**
205
+ * Check if position is at or beyond end of file and calculate actual read length
206
+ *
207
+ * @param position - The position to read from
208
+ * @param requestedLength - The requested length to read
209
+ * @param fileSize - The current file size
210
+ * @returns Object with isEOF flag and actual length to read
211
+ */
212
+ export declare function calculateReadLength(position: number, requestedLength: number, fileSize: number): {
213
+ isEOF: boolean;
214
+ actualLength: number;
215
+ };
216
+ /**
217
+ * Safely create a sync access handle with proper error mapping
218
+ *
219
+ * @param fileHandle - The file handle to create sync access handle from
220
+ * @param path - The file path for error context
221
+ * @returns Promise that resolves to FileSystemSyncAccessHandle
222
+ * @throws {OPFSError} If creation fails
223
+ */
224
+ export declare function createSyncHandleSafe(fileHandle: FileSystemFileHandle, path: string): Promise<FileSystemSyncAccessHandle>;
203
225
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,sBAAsB,oaA0DzB,CAAC;AAEX;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAI3D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAIvC;AAED,wBAAsB,QAAQ,CAAC,CAAC,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,GAAG,WAAW,EAC5B,EAAE,EAAE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