opfs-worker 0.2.3 → 0.2.5
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/README.md +5 -3
- package/dist/assets/worker-BL3varjN.js.map +1 -0
- package/dist/{helpers-Co-qCBmA.js → helpers-3TGPHd1h.js} +6 -5
- package/dist/{helpers-Co-qCBmA.js.map → helpers-3TGPHd1h.js.map} +1 -1
- package/dist/{helpers-hEpet7x7.cjs → helpers-DjY2OR7f.cjs} +2 -2
- package/dist/{helpers-hEpet7x7.cjs.map → helpers-DjY2OR7f.cjs.map} +1 -1
- package/dist/index.cjs +480 -464
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +500 -481
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +168 -153
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +4 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +1 -1
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +45 -53
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-CRHhlrlS.js.map +0 -1
package/dist/raw.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"raw.js","sources":["../src/worker.ts"],"sourcesContent":["import { expose } from 'comlink';\n\nimport { decodeBuffer } from './utils/encoder';\nimport {\n FileNotFoundError,\n OPFSError,\n OPFSNotMountedError,\n PathError\n} from './utils/errors';\n\nimport { \n calculateFileHash, \n checkOPFSSupport, \n joinPath, \n readFileData, \n splitPath, \n writeFileData,\n basename,\n dirname,\n normalizePath,\n resolvePath,\n convertBlobToUint8Array\n} from './utils/helpers';\n\nimport type { DirentData, FileStat, WatchEvent } 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 | null = null;\n\n /** Watch event callback */\n private watchCallback: ((event: WatchEvent) => void) | null = null;\n\n /** Map of watched paths to their last known state */\n private watchers = new Map<string, Map<string, FileStat>>();\n\n /** Interval handle for polling watched paths */\n private watchTimer: ReturnType<typeof setInterval> | null = null;\n\n /** Polling interval in milliseconds */\n private watchInterval = 1000;\n\n /** Flag to avoid concurrent scans */\n private scanning = false;\n\n /** Promise to prevent concurrent mount operations */\n private mountingPromise: Promise<boolean> | null = null;\n\n /**\n * Creates a new OPFSFileSystem instance\n * \n * @param watchCallback - Optional callback for file change events\n * @param watchOptions - Optional configuration for watching\n * @throws {OPFSError} If OPFS is not supported in the current browser\n */\n constructor(\n watchCallback?: (event: WatchEvent) => void,\n watchOptions?: { watchInterval?: number }\n ) {\n checkOPFSSupport();\n \n if (watchCallback) {\n this.watchCallback = watchCallback;\n if (watchOptions?.watchInterval) {\n this.watchInterval = watchOptions.watchInterval;\n }\n }\n \n void this.mount('/');\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 async mount(root: string = '/'): Promise<boolean> {\n // If already mounting, wait for previous operation to complete first\n if (this.mountingPromise) {\n await this.mountingPromise;\n }\n\n this.mountingPromise = new Promise<boolean>(async(resolve, reject) => {\n this.root = null;\n \n try {\n const rootDir = await navigator.storage.getDirectory();\n \n if (root === '/') {\n this.root = rootDir;\n } \n else {\n this.root = await this.getDirectoryHandle(root, true, rootDir);\n }\n resolve(true);\n }\n catch (error) {\n console.error(error);\n reject(new OPFSError('Failed to initialize OPFS', 'INIT_FAILED'));\n }\n finally {\n this.mountingPromise = null;\n }\n });\n\n return this.mountingPromise;\n }\n\n /**\n * Set the watch callback for file change events\n * \n * @param callback - The callback function to invoke when files change\n * @param options - Optional configuration for watching\n */\n setWatchCallback(callback: (event: WatchEvent) => void, options?: { watchInterval?: number }): void {\n this.watchCallback = callback;\n\n if (options?.watchInterval) {\n this.watchInterval = options.watchInterval;\n }\n }\n\n /**\n * Automatically mount the OPFS root if not already mounted\n * \n * This method is called internally when file operations are performed\n * without explicitly mounting first.\n * \n * @returns Promise that resolves when auto-mount is complete\n * @throws {OPFSError} If auto-mount fails\n */\n private async ensureMounted(): Promise<void> {\n // If already mounted, return immediately\n if (this.root) {\n return;\n }\n\n // If already mounting, wait for that operation to complete\n if (this.mountingPromise) {\n await this.mountingPromise;\n return;\n }\n\n throw new OPFSError('OPFS not mounted', 'NOT_MOUNTED');\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 if (!from) {\n throw new OPFSNotMountedError();\n }\n\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 if (!from) {\n throw new OPFSNotMountedError();\n }\n\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 /**\n * Recursively list all files and directories with their stats\n * \n * Traverses the entire file system starting from the root and returns\n * a Map containing all paths and their corresponding file statistics.\n * \n * @param options - Options for indexing\n * @param options.includeHash - Whether to calculate file hash (default: false)\n * @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)\n * @returns Promise that resolves to a Map of path => FileStat\n * @throws {OPFSError} If the indexing operation fails\n * \n * @example\n * ```typescript\n * // Basic index without hash\n * const index = await fs.index();\n * \n * // Index with file hash\n * const indexWithHash = await fs.index({ \n * includeHash: true,\n * hashAlgorithm: 'SHA-1'\n * });\n * \n * // Iterate through all files and directories\n * for (const [path, stat] of index) {\n * console.log(`${path}: ${stat.isFile ? 'file' : 'directory'} (${stat.size} bytes)`);\n * if (stat.hash) console.log(` Hash: ${stat.hash}`);\n * }\n * \n * // Get specific file stats\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(options?: { includeHash?: boolean; hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' }): 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, { withFileTypes: true });\n\n for (const item of items) {\n const fullPath = `${ dirPath === '/' ? '' : dirPath }/${ item.name }`;\n\n try {\n const stat = await this.stat(fullPath, options);\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?: BufferEncoding): Promise<string>;\n async readFile(\n path: string,\n encoding: BufferEncoding | 'binary' = 'utf-8'\n ): Promise<string | Uint8Array> {\n await this.ensureMounted();\n \n try {\n const fileHandle = await this.getFileHandle(path, false);\n const buffer = await readFileData(fileHandle);\n\n if (encoding === 'binary') {\n return buffer;\n }\n\n return decodeBuffer(buffer, encoding);\n }\n catch (err) {\n console.error(err);\n\n throw new FileNotFoundError(path);\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.ensureMounted();\n \n const fileHandle = await this.getFileHandle(path, true);\n\n await writeFileData(fileHandle, data, encoding, { truncate: true });\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.ensureMounted();\n \n const fileHandle = await this.getFileHandle(path, true);\n\n await writeFileData(fileHandle, data, encoding, { append: true });\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.ensureMounted();\n\n if (!this.root) {\n throw new OPFSNotMountedError();\n }\n\n const recursive = options?.recursive ?? false;\n const segments = splitPath(path);\n\n let current = 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 (e: any) {\n if (e.name === 'NotFoundError') {\n throw new OPFSError(\n `Parent directory does not exist: ${ joinPath(segments.slice(0, i + 1)) }`,\n 'ENOENT'\n );\n }\n\n if (e.name === 'TypeMismatchError') {\n throw new OPFSError(`Path segment is not a directory: ${ segment }`, 'ENOTDIR');\n }\n\n throw new OPFSError('Failed to create directory', 'MKDIR_FAILED');\n }\n }\n }\n\n /**\n * Get file or directory stats\n * \n * Retrieves metadata about a file or directory, including size, modification time,\n * type information, and optionally file hashes.\n * \n * @param path - The path to the file or directory\n * @param options - Options for stat operation\n * @param options.includeHash - Whether to calculate file hash (default: false, only for files)\n * @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)\n * @returns Promise that resolves to file/directory statistics\n * @throws {OPFSError} If the file or directory does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * // Basic stats\n * const stats = await fs.stat('/config/settings.json');\n * console.log(`File size: ${stats.size} bytes`);\n * console.log(`Is file: ${stats.isFile}`);\n * console.log(`Modified: ${stats.mtime}`);\n * \n * // Stats with hash (SHA-1 is fastest)\n * const statsWithHash = await fs.stat('/config/settings.json', { \n * includeHash: true,\n * hashAlgorithm: 'SHA-1'\n * });\n * console.log(`Hash: ${statsWithHash.hash}`);\n * ```\n */\n async stat(path: string, options?: { includeHash?: boolean; hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' }): Promise<FileStat> {\n await this.ensureMounted();\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 = options?.includeHash ?? false;\n const hashAlgorithm = options?.hashAlgorithm ?? 'SHA-1';\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) {\n try {\n const buffer = new Uint8Array(await file.arrayBuffer());\n const hash = await calculateFileHash(buffer, hashAlgorithm);\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');\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');\n }\n\n throw new OPFSError('Failed to stat (directory)', 'STAT_FAILED');\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 * @param options - Options for the readdir operation\n * @param options.withFileTypes - Whether to return detailed file information (default: false)\n * @returns Promise that resolves to an array of file/directory names or detailed information\n * @throws {OPFSError} If the directory does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * // Get simple list of names\n * const files = await fs.readdir('/users/john/documents');\n * console.log('Files:', files); // ['readme.txt', 'config.json', 'images']\n * \n * // Get detailed information\n * const detailed = await fs.readdir('/users/john/documents', { withFileTypes: true });\n * detailed.forEach(item => {\n * console.log(`${item.name} - ${item.isFile ? 'file' : 'directory'}`);\n * });\n * ```\n */\n async readdir(path: string): Promise<string[]>;\n async readdir(path: string, options: { withFileTypes: true }): Promise<DirentData[]>;\n async readdir(path: string, options: { withFileTypes: false }): Promise<string[]>;\n async readdir(path: string, options?: { withFileTypes?: boolean }): Promise<string[] | DirentData[]> {\n await this.ensureMounted();\n \n const withTypes = options?.withFileTypes ?? false;\n const dir = await this.getDirectoryHandle(path, false);\n\n if (withTypes) {\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 else {\n const results: string[] = [];\n\n for await (const [name] of (dir as any).entries()) {\n results.push(name);\n }\n\n return results;\n }\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.ensureMounted();\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 (e: any) {\n if (e.name !== 'NotFoundError' && e.name !== 'TypeMismatchError') {\n throw e;\n }\n }\n\n try {\n await dir.getDirectoryHandle(name, { create: false });\n\n return true;\n }\n catch (e: any) {\n if (e.name !== 'NotFoundError' && e.name !== 'TypeMismatchError') {\n throw e;\n }\n }\n\n return false;\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.ensureMounted();\n \n try {\n const items = await this.readdir(path, { withFileTypes: true });\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 catch (error: any) {\n if (error instanceof OPFSError) {\n throw error;\n }\n\n throw new OPFSError(`Failed to clear directory: ${ path }`, 'CLEAR_FAILED');\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.ensureMounted();\n \n const recursive = options?.recursive ?? false;\n const force = options?.force ?? false;\n\n // Special handling for root directory\n if (path === '/') {\n throw new OPFSError('Cannot remove root directory', 'EROOT');\n }\n\n const name = basename(path);\n\n if (!name) {\n throw new PathError('Invalid path', path);\n }\n\n const parent = await this.getDirectoryHandle(dirname(path), false);\n\n try {\n await parent.removeEntry(name, { recursive });\n }\n catch (e: any) {\n if (e.name === 'NotFoundError') {\n if (!force) {\n throw new OPFSError(`No such file or directory: ${ path }`, 'ENOENT');\n }\n }\n else if (e.name === 'InvalidModificationError') {\n throw new OPFSError(`Directory not empty: ${ path }. Use recursive option to force removal.`, 'ENOTEMPTY');\n }\n else if (e.name === 'TypeMismatchError' && !recursive) {\n throw new OPFSError(`Cannot remove directory without recursive option: ${ path }`, 'EISDIR');\n }\n else {\n throw new OPFSError(`Failed to remove path: ${ path }`, 'RM_FAILED');\n }\n }\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.ensureMounted();\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');\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.\n * \n * @param oldPath - The current path of the file or directory\n * @param newPath - The new path for the file or directory\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 * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');\n * ```\n */\n async rename(oldPath: string, newPath: string): Promise<void> {\n await this.ensureMounted();\n \n try {\n const sourceExists = await this.exists(oldPath);\n\n if (!sourceExists) {\n throw new FileNotFoundError(oldPath);\n }\n\n await this.copy(oldPath, newPath, { recursive: true });\n await this.remove(oldPath, { recursive: true });\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');\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.force - 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, force: false });\n * ```\n */\n async copy(source: string, destination: string, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n await this.ensureMounted();\n \n try {\n const recursive = options?.recursive ?? false;\n const force = options?.force ?? true;\n\n const sourceExists = await this.exists(source);\n\n if (!sourceExists) {\n throw new OPFSError(`Source does not exist: ${ source }`, 'ENOENT');\n }\n\n const destExists = await this.exists(destination);\n\n if (destExists && !force) {\n throw new OPFSError(`Destination already exists: ${ destination }`, 'EEXIST');\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');\n }\n\n await this.mkdir(destination, { recursive: true });\n\n const items = await this.readdir(source, { withFileTypes: true });\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, force });\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');\n }\n }\n\n /**\n * Start watching a file or directory for changes\n */\n async watch(path: string): Promise<void> {\n await this.ensureMounted();\n \n const normalizedPath = normalizePath(path);\n const snapshot = await this.buildSnapshot(normalizedPath);\n this.watchers.set(normalizedPath, snapshot);\n\n if (!this.watchTimer) {\n this.watchTimer = setInterval(() => {\n void this.scanWatches();\n }, this.watchInterval);\n }\n }\n\n /**\n * Stop watching a previously watched path\n */\n unwatch(path: string): void {\n const normalizedPath = normalizePath(path);\n this.watchers.delete(normalizedPath);\n\n if (this.watchers.size === 0 && this.watchTimer) {\n clearInterval(this.watchTimer);\n this.watchTimer = null;\n }\n }\n\n private async buildSnapshot(rootPath: string): Promise<Map<string, FileStat>> {\n const result = new Map<string, FileStat>();\n\n const walk = async (current: string) => {\n const stat = await this.stat(current);\n result.set(current, stat);\n\n if (stat.isDirectory) {\n const entries = await this.readdir(current, { withFileTypes: true });\n for (const entry of entries) {\n const child = `${ current === '/' ? '' : current }/${ entry.name }`;\n await walk(child);\n }\n }\n };\n\n await walk(rootPath);\n return result;\n }\n\n private async scanWatches(): Promise<void> {\n if (this.scanning) {\n return;\n }\n\n this.scanning = true;\n\n try {\n await Promise.all(\n [...this.watchers.entries()].map(async ([rootPath, prev]) => {\n let next: Map<string, FileStat>;\n\n try {\n next = await this.buildSnapshot(rootPath);\n }\n catch {\n next = new Map();\n }\n\n const events: WatchEvent[] = [];\n\n for (const [p, stat] of next) {\n const old = prev.get(p);\n if (!old) {\n events.push({ path: p, type: 'create' });\n }\n else if (old.mtime !== stat.mtime || old.size !== stat.size) {\n events.push({ path: p, type: 'change' });\n }\n }\n\n for (const p of prev.keys()) {\n if (!next.has(p)) {\n events.push({ path: p, type: 'delete' });\n }\n }\n\n if (events.length && this.watchCallback) {\n for (const event of events) {\n this.watchCallback(event);\n }\n }\n\n this.watchers.set(rootPath, next);\n })\n );\n }\n finally {\n this.scanning = false;\n }\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.ensureMounted();\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');\n }\n }\n}\n\n// Only expose the worker when running in a Web Worker environment\nif (typeof self !== 'undefined' && self.constructor.name === 'DedicatedWorkerGlobalScope') {\n expose(new OPFSWorker());\n}\n"],"names":["OPFSWorker","watchCallback","watchOptions","checkOPFSSupport","root","resolve","reject","rootDir","error","OPFSError","callback","options","path","create","from","OPFSNotMountedError","segments","splitPath","current","segment","PathError","fileName","result","walk","dirPath","items","item","fullPath","stat","err","encoding","fileHandle","buffer","readFileData","decodeBuffer","FileNotFoundError","data","writeFileData","recursive","i","e","joinPath","name","basename","parentDir","dirname","includeHash","hashAlgorithm","file","baseStat","hash","calculateFileHash","withTypes","dir","results","handle","isFile","itemPath","force","parent","normalizedPath","resolvePath","oldPath","newPath","source","destination","content","sourceItemPath","destItemPath","normalizePath","snapshot","rootPath","entries","entry","child","prev","next","events","p","old","event","fileData","convertBlobToUint8Array","expose"],"mappings":";;AA0CO,MAAMA,EAAW;AAAA;AAAA,EAEZ,OAAyC;AAAA;AAAA,EAGzC,gBAAsD;AAAA;AAAA,EAGtD,+BAAe,IAAA;AAAA;AAAA,EAGf,aAAoD;AAAA;AAAA,EAGpD,gBAAgB;AAAA;AAAA,EAGhB,WAAW;AAAA;AAAA,EAGX,kBAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASnD,YACIC,GACAC,GACF;AACE,IAAAC,EAAA,GAEIF,MACA,KAAK,gBAAgBA,GACjBC,GAAc,kBACd,KAAK,gBAAgBA,EAAa,iBAIrC,KAAK,MAAM,GAAG;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,MAAM,MAAME,IAAe,KAAuB;AAE9C,WAAI,KAAK,mBACL,MAAM,KAAK,iBAGf,KAAK,kBAAkB,IAAI,QAAiB,OAAMC,GAASC,MAAW;AAClE,WAAK,OAAO;AAEZ,UAAI;AACA,cAAMC,IAAU,MAAM,UAAU,QAAQ,aAAA;AAExC,QAAIH,MAAS,MACT,KAAK,OAAOG,IAGZ,KAAK,OAAO,MAAM,KAAK,mBAAmBH,GAAM,IAAMG,CAAO,GAEjEF,EAAQ,EAAI;AAAA,MACh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AK,UAAUwB,GAAgBqB,CAAQ;AAAA,MACjD;AAAA,IACJ,SACOzE,GAAO;AACV,YAAIA,aAAiBC,IACXD,IAGJ,IAAIC,EAAU,8BAA8B,aAAa;AAAA,IACnE;AAAA,EACJ;AACJ;AAGI,OAAO,OAAS,OAAe,KAAK,YAAY,SAAS,gCAC3D0E,EAAO,IAAInF,GAAY;"}
|
|
1
|
+
{"version":3,"file":"raw.js","sources":["../src/worker.ts"],"sourcesContent":["import { expose } from 'comlink';\n\nimport { decodeBuffer } from './utils/encoder';\nimport {\n FileNotFoundError,\n OPFSError,\n OPFSNotMountedError,\n PathError\n} from './utils/errors';\n\nimport { \n calculateFileHash, \n checkOPFSSupport, \n joinPath, \n readFileData, \n splitPath, \n writeFileData,\n basename,\n dirname,\n normalizePath,\n resolvePath,\n convertBlobToUint8Array\n} from './utils/helpers';\n\nimport type { DirentData, FileStat, WatchEvent } 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 | null = null;\n\n /** Watch event callback */\n private watchCallback: ((event: WatchEvent) => void) | null = null;\n\n /** Map of watched paths to their last known state */\n private watchers = new Map<string, Map<string, FileStat>>();\n\n /** Interval handle for polling watched paths */\n private watchTimer: ReturnType<typeof setInterval> | null = null;\n\n /** Polling interval in milliseconds */\n private watchInterval = 1000;\n\n /** Flag to avoid concurrent scans */\n private scanning = false;\n\n /** Promise to prevent concurrent mount operations */\n private mountingPromise: Promise<boolean> | null = null;\n\n /** Hash algorithm for file hashing (null means no hashing) */\n private hashAlgorithm: null | 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512' = null;\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'>): Promise<void> {\n if (!this.watchCallback) {\n return;\n }\n\n // Calculate hash if hashing is enabled and this is a file operation\n let hash: string | undefined;\n if (this.hashAlgorithm && !event.isDirectory && event.type !== 'removed') {\n try {\n const stats = await this.stat(event.path);\n\n if (stats.isFile && stats.hash) {\n hash = stats.hash;\n }\n } \n catch (error) {\n console.warn(`Failed to calculate hash for ${event.path}:`, error);\n }\n }\n\n // Notify about the change immediately\n this.watchCallback({\n timestamp: new Date().toISOString(),\n ...event,\n ...(hash && { hash })\n });\n }\n\n /**\n * Creates a new OPFSFileSystem instance\n * \n * @param watchCallback - Optional callback for file change events\n * @param options - Optional configuration options\n * @param options.watchInterval - Polling interval in milliseconds for file watching\n * @param options.hashAlgorithm - Hash algorithm for file hashing\n * @throws {OPFSError} If OPFS is not supported in the current browser\n */\n constructor(\n watchCallback?: (event: WatchEvent) => void,\n options?: { \n watchInterval?: number;\n hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';\n }\n ) {\n checkOPFSSupport();\n \n if (watchCallback) {\n this.watchCallback = watchCallback;\n }\n \n if (options) {\n this.setOptions(options);\n }\n \n void this.mount('/');\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 async mount(root: string = '/'): Promise<boolean> {\n // If already mounting, wait for previous operation to complete first\n if (this.mountingPromise) {\n await this.mountingPromise;\n }\n\n this.mountingPromise = new Promise<boolean>(async(resolve, reject) => {\n this.root = null;\n \n try {\n const rootDir = await navigator.storage.getDirectory();\n \n if (root === '/') {\n this.root = rootDir;\n } \n else {\n this.root = await this.getDirectoryHandle(root, true, rootDir);\n }\n resolve(true);\n }\n catch (error) {\n console.error(error);\n reject(new OPFSError('Failed to initialize OPFS', 'INIT_FAILED'));\n }\n finally {\n this.mountingPromise = null;\n }\n });\n\n return this.mountingPromise;\n }\n\n /**\n * Set the watch callback for file change events\n * \n * @param callback - The callback function to invoke when files change\n */\n setWatchCallback(\n callback: (event: WatchEvent) => void, \n ) {\n this.watchCallback = callback;\n }\n\n /**\n * Set configuration options for the file system\n * \n * @param options - Configuration options to update\n * @param options.watchInterval - Polling interval in milliseconds for file watching\n * @param options.hashAlgorithm - Hash algorithm for file hashing\n */\n setOptions(options: { \n watchInterval?: number;\n hashAlgorithm?: null | 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';\n }): void {\n if (options.watchInterval !== undefined) {\n this.watchInterval = options.watchInterval;\n }\n\n if (options.hashAlgorithm !== undefined) {\n this.hashAlgorithm = options.hashAlgorithm;\n }\n }\n\n /**\n * Automatically mount the OPFS root if not already mounted\n * \n * This method is called internally when file operations are performed\n * without explicitly mounting first.\n * \n * @returns Promise that resolves when auto-mount is complete\n * @throws {OPFSError} If auto-mount fails\n */\n private async ensureMounted(): Promise<void> {\n // If already mounted, return immediately\n if (this.root) {\n return;\n }\n\n // If already mounting, wait for that operation to complete\n if (this.mountingPromise) {\n await this.mountingPromise;\n return;\n }\n\n throw new OPFSError('OPFS not mounted', 'NOT_MOUNTED');\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 if (!from) {\n throw new OPFSNotMountedError();\n }\n\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 if (!from) {\n throw new OPFSNotMountedError();\n }\n\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 /**\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, { withFileTypes: true });\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?: BufferEncoding): Promise<string>;\n async readFile(\n path: string,\n encoding: BufferEncoding | 'binary' = 'utf-8'\n ): Promise<string | Uint8Array> {\n await this.ensureMounted();\n \n try {\n const fileHandle = await this.getFileHandle(path, false);\n const buffer = await readFileData(fileHandle);\n\n if (encoding === 'binary') {\n return buffer;\n }\n\n return decodeBuffer(buffer, encoding);\n }\n catch (err) {\n console.error(err);\n\n throw new FileNotFoundError(path);\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.ensureMounted();\n \n const fileHandle = await this.getFileHandle(path, true);\n\n await writeFileData(fileHandle, data, encoding, { truncate: true });\n await this.notifyChange({ path, type: 'changed', isDirectory: false });\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.ensureMounted();\n \n const fileHandle = await this.getFileHandle(path, true);\n\n await writeFileData(fileHandle, data, encoding, { 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.ensureMounted();\n\n if (!this.root) {\n throw new OPFSNotMountedError();\n }\n\n const recursive = options?.recursive ?? false;\n const segments = splitPath(path);\n\n let current = 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 (e: any) {\n if (e.name === 'NotFoundError') {\n throw new OPFSError(\n `Parent directory does not exist: ${ joinPath(segments.slice(0, i + 1)) }`,\n 'ENOENT'\n );\n }\n\n if (e.name === 'TypeMismatchError') {\n throw new OPFSError(`Path segment is not a directory: ${ segment }`, 'ENOTDIR');\n }\n\n throw new OPFSError('Failed to create directory', 'MKDIR_FAILED');\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.ensureMounted();\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.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.hashAlgorithm) {\n try {\n const hash = await calculateFileHash(file, this.hashAlgorithm);\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');\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');\n }\n\n throw new OPFSError('Failed to stat (directory)', 'STAT_FAILED');\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 * @param options - Options for the readdir operation\n * @param options.withFileTypes - Whether to return detailed file information (default: false)\n * @returns Promise that resolves to an array of file/directory names or detailed information\n * @throws {OPFSError} If the directory does not exist or cannot be accessed\n * \n * @example\n * ```typescript\n * // Get simple list of names\n * const files = await fs.readdir('/users/john/documents');\n * console.log('Files:', files); // ['readme.txt', 'config.json', 'images']\n * \n * // Get detailed information\n * const detailed = await fs.readdir('/users/john/documents', { withFileTypes: true });\n * detailed.forEach(item => {\n * console.log(`${item.name} - ${item.isFile ? 'file' : 'directory'}`);\n * });\n * ```\n */\n async readdir(path: string): Promise<string[]>;\n async readdir(path: string, options: { withFileTypes: true }): Promise<DirentData[]>;\n async readdir(path: string, options: { withFileTypes: false }): Promise<string[]>;\n async readdir(path: string, options?: { withFileTypes?: boolean }): Promise<string[] | DirentData[]> {\n await this.ensureMounted();\n \n const withTypes = options?.withFileTypes ?? false;\n const dir = await this.getDirectoryHandle(path, false);\n\n if (withTypes) {\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 else {\n const results: string[] = [];\n\n for await (const [name] of (dir as any).entries()) {\n results.push(name);\n }\n\n return results;\n }\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.ensureMounted();\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 (e: any) {\n if (e.name !== 'NotFoundError' && e.name !== 'TypeMismatchError') {\n throw e;\n }\n }\n\n try {\n await dir.getDirectoryHandle(name, { create: false });\n\n return true;\n }\n catch (e: any) {\n if (e.name !== 'NotFoundError' && e.name !== 'TypeMismatchError') {\n throw e;\n }\n }\n\n return false;\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.ensureMounted();\n \n try {\n const items = await this.readdir(path, { withFileTypes: true });\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 // Notify about the clear operation\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');\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.ensureMounted();\n \n const recursive = options?.recursive ?? false;\n const force = options?.force ?? false;\n\n // Special handling for root directory\n if (path === '/') {\n throw new OPFSError('Cannot remove root directory', 'EROOT');\n }\n\n const name = basename(path);\n\n if (!name) {\n throw new PathError('Invalid path', path);\n }\n\n const parent = await this.getDirectoryHandle(dirname(path), false);\n\n try {\n await parent.removeEntry(name, { recursive });\n }\n catch (e: any) {\n if (e.name === 'NotFoundError') {\n if (!force) {\n throw new OPFSError(`No such file or directory: ${ path }`, 'ENOENT');\n }\n }\n else if (e.name === 'InvalidModificationError') {\n throw new OPFSError(`Directory not empty: ${ path }. Use recursive option to force removal.`, 'ENOTEMPTY');\n }\n else if (e.name === 'TypeMismatchError' && !recursive) {\n throw new OPFSError(`Cannot remove directory without recursive option: ${ path }`, 'EISDIR');\n }\n else {\n throw new OPFSError(`Failed to remove path: ${ path }`, 'RM_FAILED');\n }\n }\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.ensureMounted();\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');\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.\n * \n * @param oldPath - The current path of the file or directory\n * @param newPath - The new path for the file or directory\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 * await fs.rename('/old/path/file.txt', '/new/path/renamed.txt');\n * ```\n */\n async rename(oldPath: string, newPath: string): Promise<void> {\n await this.ensureMounted();\n \n try {\n const sourceExists = await this.exists(oldPath);\n\n if (!sourceExists) {\n throw new FileNotFoundError(oldPath);\n }\n\n await this.copy(oldPath, newPath, { recursive: true });\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');\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.force - 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, force: false });\n * ```\n */\n async copy(source: string, destination: string, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n await this.ensureMounted();\n \n try {\n const recursive = options?.recursive ?? false;\n const force = options?.force ?? true;\n\n const sourceExists = await this.exists(source);\n\n if (!sourceExists) {\n throw new OPFSError(`Source does not exist: ${ source }`, 'ENOENT');\n }\n\n const destExists = await this.exists(destination);\n\n if (destExists && !force) {\n throw new OPFSError(`Destination already exists: ${ destination }`, 'EEXIST');\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');\n }\n\n await this.mkdir(destination, { recursive: true });\n\n const items = await this.readdir(source, { withFileTypes: true });\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, force });\n }\n }\n \n // Notify about the copy operation\n await this.notifyChange({ path: destination, type: 'added', isDirectory: false });\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');\n }\n }\n\n /**\n * Start watching a file or directory for changes\n */\n async watch(path: string): Promise<void> {\n await this.ensureMounted();\n \n const normalizedPath = normalizePath(path);\n const snapshot = await this.buildSnapshot(normalizedPath);\n\n this.watchers.set(normalizedPath, snapshot);\n\n if (!this.watchTimer) {\n this.watchTimer = setInterval(() => {\n void this.scanWatches();\n }, this.watchInterval);\n }\n }\n\n /**\n * Stop watching a previously watched path\n */\n unwatch(path: string): void {\n const normalizedPath = normalizePath(path);\n this.watchers.delete(normalizedPath);\n\n if (this.watchers.size === 0 && this.watchTimer) {\n clearInterval(this.watchTimer);\n this.watchTimer = null;\n }\n }\n\n private async buildSnapshot(rootPath: string): Promise<Map<string, FileStat>> {\n const result = new Map<string, FileStat>();\n\n const walk = async (current: string) => {\n const stat = await this.stat(current);\n result.set(current, stat);\n\n if (stat.isDirectory) {\n const entries = await this.readdir(current, { withFileTypes: true });\n for (const entry of entries) {\n const child = `${ current === '/' ? '' : current }/${ entry.name }`;\n await walk(child);\n }\n }\n };\n\n await walk(rootPath);\n return result;\n }\n\n private async scanWatches(): Promise<void> {\n if (this.scanning) {\n return;\n }\n\n this.scanning = true;\n\n try {\n await Promise.all(\n [...this.watchers.entries()].map(async([rootPath, prev]) => {\n let next: Map<string, FileStat>;\n\n try {\n next = await this.buildSnapshot(rootPath);\n }\n catch {\n next = new Map();\n }\n\n for (const [p, stat] of next) {\n const old = prev.get(p);\n \n if (!old) {\n await this.notifyChange({ path: p, type: 'added', isDirectory: false });\n }\n else if (old.mtime !== stat.mtime || old.size !== stat.size) {\n await this.notifyChange({ path: p, type: 'changed', isDirectory: false });\n }\n }\n\n for (const p of prev.keys()) {\n if (!next.has(p)) {\n await this.notifyChange({ path: p, type: 'removed', isDirectory: false });\n }\n }\n\n this.watchers.set(rootPath, next);\n })\n );\n }\n finally {\n this.scanning = false;\n }\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.ensureMounted();\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 // Notify about the sync operation\n await this.notifyChange({ path: '/', type: 'changed', isDirectory: true });\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');\n }\n }\n}\n\n// Only expose the worker when running in a Web Worker environment\nif (typeof self !== 'undefined' && self.constructor.name === 'DedicatedWorkerGlobalScope') {\n expose(new OPFSWorker());\n}\n"],"names":["OPFSWorker","event","hash","stats","error","watchCallback","options","checkOPFSSupport","root","resolve","reject","rootDir","OPFSError","callback","path","create","from","OPFSNotMountedError","segments","splitPath","current","segment","PathError","fileName","result","walk","dirPath","items","item","fullPath","stat","err","encoding","fileHandle","buffer","readFileData","decodeBuffer","FileNotFoundError","data","writeFileData","recursive","i","e","joinPath","name","basename","parentDir","dirname","includeHash","file","baseStat","calculateFileHash","withTypes","dir","results","handle","isFile","itemPath","force","parent","normalizedPath","resolvePath","oldPath","newPath","source","destination","content","sourceItemPath","destItemPath","normalizePath","snapshot","rootPath","entries","entry","child","prev","next","p","old","fileData","convertBlobToUint8Array","expose"],"mappings":";;AA0CO,MAAMA,EAAW;AAAA;AAAA,EAEZ,OAAyC;AAAA;AAAA,EAGzC,gBAAsD;AAAA;AAAA,EAGtD,+BAAe,IAAA;AAAA;AAAA,EAGf,aAAoD;AAAA;AAAA,EAGpD,gBAAgB;AAAA;AAAA,EAGhB,WAAW;AAAA;AAAA,EAGX,kBAA2C;AAAA;AAAA,EAG3C,gBAAoE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAW5E,MAAc,aAAaC,GAA8D;AACrF,QAAI,CAAC,KAAK;AACN;AAIJ,QAAIC;AACJ,QAAI,KAAK,iBAAiB,CAACD,EAAM,eAAeA,EAAM,SAAS;AAC3D,UAAI;AACA,cAAME,IAAQ,MAAM,KAAK,KAAKF,EAAM,IAAI;AAExC,QAAIE,EAAM,UAAUA,EAAM,SACtBD,IAAOC,EAAM;AAAA,MAErB,SACOC,GAAO;AACV,gBAAQ,KAAK,gCAAgCH,EAAM,IAAI,KAAKG,CAAK;AAAA,MACrE;AAIJ,SAAK,cAAc;AAAA,MACf,YAAW,oBAAI,KAAA,GAAO,YAAA;AAAA,MACtB,GAAGH;AAAA,MACH,GAAIC,KAAQ,EAAE,MAAAA,EAAA;AAAA,IAAK,CACtB;AAAA,EACL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,YACIG,GACAC,GAIF;AACE,IAAAC,EAAA,GAEIF,MACA,KAAK,gBAAgBA,IAGrBC,KACA,KAAK,WAAWA,CAAO,GAGtB,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
|
|
19
19
|
}
|
|
20
20
|
export interface WatchEvent {
|
|
21
21
|
path: string;
|
|
22
|
-
type: '
|
|
22
|
+
type: 'added' | 'changed' | 'removed';
|
|
23
|
+
isDirectory: boolean;
|
|
24
|
+
timestamp: string;
|
|
25
|
+
hash?: string;
|
|
23
26
|
}
|
|
24
27
|
export type { OPFSWorker };
|
|
25
28
|
export type RemoteOPFSWorker = Remote<OPFSWorker>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,WAAW,CAAC;AAExC,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,WAAW,CAAC;AAExC,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAAC;IACtC,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,YAAY,EAAE,UAAU,EAAE,CAAC;AAC3B,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC"}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -117,7 +117,7 @@ export declare function writeFileData(fileHandle: FileSystemFileHandle, data: st
|
|
|
117
117
|
* @param algorithm - Hash algorithm to use (default: 'SHA-1')
|
|
118
118
|
* @returns Promise that resolves to the hash string
|
|
119
119
|
*/
|
|
120
|
-
export declare function calculateFileHash(buffer: Uint8Array, algorithm?: string): Promise<string>;
|
|
120
|
+
export declare function calculateFileHash(buffer: File | ArrayBuffer | Uint8Array, algorithm?: string): Promise<string>;
|
|
121
121
|
/**
|
|
122
122
|
* Convert a Blob to Uint8Array
|
|
123
123
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.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CAC/B,UAAU,EAAE,oBAAoB,EAChC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,EACvC,QAAQ,CAAC,EAAE,cAAc,EACzB,OAAO,GAAE;IAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACvD,OAAO,CAAC,IAAI,CAAC,CA+Bf;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,IAAI,GAAG,WAAW,GAAG,UAAU,EAAE,SAAS,GAAE,MAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB7H;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,uBAAuB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAG7E"}
|
package/dist/worker.d.ts
CHANGED
|
@@ -30,15 +30,30 @@ export declare class OPFSWorker {
|
|
|
30
30
|
private scanning;
|
|
31
31
|
/** Promise to prevent concurrent mount operations */
|
|
32
32
|
private mountingPromise;
|
|
33
|
+
/** Hash algorithm for file hashing (null means no hashing) */
|
|
34
|
+
private hashAlgorithm;
|
|
35
|
+
/**
|
|
36
|
+
* Notify about internal changes to the file system
|
|
37
|
+
*
|
|
38
|
+
* This method is called by internal operations to notify clients about
|
|
39
|
+
* changes, even when no specific paths are being watched.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The path that was changed
|
|
42
|
+
* @param type - The type of change (create, change, delete)
|
|
43
|
+
*/
|
|
44
|
+
private notifyChange;
|
|
33
45
|
/**
|
|
34
46
|
* Creates a new OPFSFileSystem instance
|
|
35
47
|
*
|
|
36
48
|
* @param watchCallback - Optional callback for file change events
|
|
37
|
-
* @param
|
|
49
|
+
* @param options - Optional configuration options
|
|
50
|
+
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
51
|
+
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
38
52
|
* @throws {OPFSError} If OPFS is not supported in the current browser
|
|
39
53
|
*/
|
|
40
|
-
constructor(watchCallback?: (event: WatchEvent) => void,
|
|
54
|
+
constructor(watchCallback?: (event: WatchEvent) => void, options?: {
|
|
41
55
|
watchInterval?: number;
|
|
56
|
+
hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
42
57
|
});
|
|
43
58
|
/**
|
|
44
59
|
* Initialize the file system within a given directory
|
|
@@ -66,10 +81,18 @@ export declare class OPFSWorker {
|
|
|
66
81
|
* Set the watch callback for file change events
|
|
67
82
|
*
|
|
68
83
|
* @param callback - The callback function to invoke when files change
|
|
69
|
-
* @param options - Optional configuration for watching
|
|
70
84
|
*/
|
|
71
|
-
setWatchCallback(callback: (event: WatchEvent) => void
|
|
85
|
+
setWatchCallback(callback: (event: WatchEvent) => void): void;
|
|
86
|
+
/**
|
|
87
|
+
* Set configuration options for the file system
|
|
88
|
+
*
|
|
89
|
+
* @param options - Configuration options to update
|
|
90
|
+
* @param options.watchInterval - Polling interval in milliseconds for file watching
|
|
91
|
+
* @param options.hashAlgorithm - Hash algorithm for file hashing
|
|
92
|
+
*/
|
|
93
|
+
setOptions(options: {
|
|
72
94
|
watchInterval?: number;
|
|
95
|
+
hashAlgorithm?: null | 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
73
96
|
}): void;
|
|
74
97
|
/**
|
|
75
98
|
* Automatically mount the OPFS root if not already mounted
|
|
@@ -121,35 +144,17 @@ export declare class OPFSWorker {
|
|
|
121
144
|
*/
|
|
122
145
|
private getFileHandle;
|
|
123
146
|
/**
|
|
124
|
-
*
|
|
147
|
+
* Get a complete index of all files and directories in the file system
|
|
125
148
|
*
|
|
126
|
-
*
|
|
127
|
-
* a Map containing
|
|
149
|
+
* This method recursively traverses the entire file system and returns
|
|
150
|
+
* a Map containing FileStat objects for every file and directory.
|
|
128
151
|
*
|
|
129
|
-
* @
|
|
130
|
-
* @
|
|
131
|
-
* @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
|
|
132
|
-
* @returns Promise that resolves to a Map of path => FileStat
|
|
133
|
-
* @throws {OPFSError} If the indexing operation fails
|
|
152
|
+
* @returns Promise that resolves to a Map of paths to FileStat objects
|
|
153
|
+
* @throws {OPFSError} If the file system is not mounted
|
|
134
154
|
*
|
|
135
155
|
* @example
|
|
136
156
|
* ```typescript
|
|
137
|
-
* // Basic index without hash
|
|
138
157
|
* const index = await fs.index();
|
|
139
|
-
*
|
|
140
|
-
* // Index with file hash
|
|
141
|
-
* const indexWithHash = await fs.index({
|
|
142
|
-
* includeHash: true,
|
|
143
|
-
* hashAlgorithm: 'SHA-1'
|
|
144
|
-
* });
|
|
145
|
-
*
|
|
146
|
-
* // Iterate through all files and directories
|
|
147
|
-
* for (const [path, stat] of index) {
|
|
148
|
-
* console.log(`${path}: ${stat.isFile ? 'file' : 'directory'} (${stat.size} bytes)`);
|
|
149
|
-
* if (stat.hash) console.log(` Hash: ${stat.hash}`);
|
|
150
|
-
* }
|
|
151
|
-
*
|
|
152
|
-
* // Get specific file stats
|
|
153
158
|
* const fileStats = index.get('/data/config.json');
|
|
154
159
|
* if (fileStats) {
|
|
155
160
|
* console.log(`File size: ${fileStats.size} bytes`);
|
|
@@ -157,10 +162,7 @@ export declare class OPFSWorker {
|
|
|
157
162
|
* }
|
|
158
163
|
* ```
|
|
159
164
|
*/
|
|
160
|
-
index(
|
|
161
|
-
includeHash?: boolean;
|
|
162
|
-
hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
163
|
-
}): Promise<Map<string, FileStat>>;
|
|
165
|
+
index(): Promise<Map<string, FileStat>>;
|
|
164
166
|
/**
|
|
165
167
|
* Read a file from the file system
|
|
166
168
|
*
|
|
@@ -261,38 +263,28 @@ export declare class OPFSWorker {
|
|
|
261
263
|
recursive?: boolean;
|
|
262
264
|
}): Promise<void>;
|
|
263
265
|
/**
|
|
264
|
-
* Get file or directory
|
|
266
|
+
* Get file or directory statistics
|
|
265
267
|
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
+
* Returns detailed information about a file or directory, including
|
|
269
|
+
* size, modification time, and optionally a hash of the file content.
|
|
268
270
|
*
|
|
269
271
|
* @param path - The path to the file or directory
|
|
270
|
-
* @
|
|
271
|
-
* @
|
|
272
|
-
* @param options.hashAlgorithm - Hash algorithm to use (default: 'SHA-1', fastest)
|
|
273
|
-
* @returns Promise that resolves to file/directory statistics
|
|
274
|
-
* @throws {OPFSError} If the file or directory does not exist or cannot be accessed
|
|
272
|
+
* @returns Promise that resolves to FileStat object
|
|
273
|
+
* @throws {OPFSError} If the path does not exist or cannot be accessed
|
|
275
274
|
*
|
|
276
275
|
* @example
|
|
277
276
|
* ```typescript
|
|
278
|
-
*
|
|
279
|
-
* const stats = await fs.stat('/config/settings.json');
|
|
277
|
+
* const stats = await fs.stat('/data/config.json');
|
|
280
278
|
* console.log(`File size: ${stats.size} bytes`);
|
|
281
|
-
* console.log(`
|
|
282
|
-
* console.log(`Modified: ${stats.mtime}`);
|
|
279
|
+
* console.log(`Last modified: ${stats.mtime}`);
|
|
283
280
|
*
|
|
284
|
-
* //
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* });
|
|
289
|
-
* console.log(`Hash: ${statsWithHash.hash}`);
|
|
281
|
+
* // If hashing is enabled, hash will be included
|
|
282
|
+
* if (stats.hash) {
|
|
283
|
+
* console.log(`Hash: ${stats.hash}`);
|
|
284
|
+
* }
|
|
290
285
|
* ```
|
|
291
286
|
*/
|
|
292
|
-
stat(path: string
|
|
293
|
-
includeHash?: boolean;
|
|
294
|
-
hashAlgorithm?: 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
295
|
-
}): Promise<FileStat>;
|
|
287
|
+
stat(path: string): Promise<FileStat>;
|
|
296
288
|
/**
|
|
297
289
|
* Read a directory's contents
|
|
298
290
|
*
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU;IACnB,gDAAgD;IAChD,OAAO,CAAC,IAAI,CAA0C;IAEtD,2BAA2B;IAC3B,OAAO,CAAC,aAAa,CAA8C;IAEnE,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAA4C;IAE5D,gDAAgD;IAChD,OAAO,CAAC,UAAU,CAA+C;IAEjE,uCAAuC;IACvC,OAAO,CAAC,aAAa,CAAQ;IAE7B,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAS;IAEzB,qDAAqD;IACrD,OAAO,CAAC,eAAe,CAAiC;IAExD
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,UAAU;IACnB,gDAAgD;IAChD,OAAO,CAAC,IAAI,CAA0C;IAEtD,2BAA2B;IAC3B,OAAO,CAAC,aAAa,CAA8C;IAEnE,qDAAqD;IACrD,OAAO,CAAC,QAAQ,CAA4C;IAE5D,gDAAgD;IAChD,OAAO,CAAC,UAAU,CAA+C;IAEjE,uCAAuC;IACvC,OAAO,CAAC,aAAa,CAAQ;IAE7B,qCAAqC;IACrC,OAAO,CAAC,QAAQ,CAAS;IAEzB,qDAAqD;IACrD,OAAO,CAAC,eAAe,CAAiC;IAExD,8DAA8D;IAC9D,OAAO,CAAC,aAAa,CAA4D;IAEjF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