opfs-worker 1.2.3 → 1.2.4

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/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { wrap as u } from "comlink";
2
- import { i as c, d as l, e as h } from "./helpers-BXhw_-Ar.js";
3
- import { E as x, D as S, F as P, O as F, b as O, a as A, P as T, c as I, S as R, T as $, W as C, h as _, v as N, u as D, B as z, g as k, x as M, t as j, f as L, C as W, k as U, q as H, p as B, j as G, m as q, o as V, l as Y, n as X, y as Z, r as J, A as K, s as Q, z as nn, w as tn } from "./helpers-BXhw_-Ar.js";
4
- const f = `/**
2
+ import { i as c, d as l, e as h } from "./helpers-BwklIUit.js";
3
+ import { E as x, D as S, F as P, O as F, b as O, a as A, P as T, c as I, S as R, T as $, W as _, h as C, v as N, u as D, B as z, g as k, x as M, t as j, f as L, C as W, k as U, q as H, p as B, j as G, m as q, o as Y, l as V, n as X, y as Z, r as J, A as K, s as Q, z as nn, w as tn } from "./helpers-BwklIUit.js";
4
+ const p = `/**
5
5
  * @license
6
6
  * Copyright 2019 Google LLC
7
7
  * SPDX-License-Identifier: Apache-2.0
@@ -1314,7 +1314,6 @@ async function Qe(s, t, e = {}) {
1314
1314
  const n = K(t);
1315
1315
  return T(t, "exclusive", async () => {
1316
1316
  const i = e.recursive ?? !1, r = e.force ?? !1;
1317
- e.useTrash;
1318
1317
  try {
1319
1318
  await s.removeEntry(n, { recursive: i });
1320
1319
  } catch (o) {
@@ -1369,7 +1368,7 @@ class ss {
1369
1368
  root: "/",
1370
1369
  namespace: "",
1371
1370
  maxFileSize: 50 * 1024 * 1024,
1372
- hashAlgorithm: !1,
1371
+ hashAlgorithm: "etag",
1373
1372
  broadcastChannel: "opfs-worker"
1374
1373
  };
1375
1374
  /** Map of open file descriptors to their metadata */
@@ -1750,7 +1749,7 @@ class ss {
1750
1749
  isFile: !1,
1751
1750
  isDirectory: !0
1752
1751
  };
1753
- const e = K(t), n = await this.getDirectoryHandle(Y(t), !1), i = this.options.hashAlgorithm !== null;
1752
+ const e = K(t), n = await this.getDirectoryHandle(Y(t), !1), i = this.options.hashAlgorithm;
1754
1753
  try {
1755
1754
  const o = await (await n.getFileHandle(e, { create: !1 })).getFile(), a = {
1756
1755
  kind: "file",
@@ -1760,9 +1759,11 @@ class ss {
1760
1759
  isFile: !0,
1761
1760
  isDirectory: !1
1762
1761
  };
1763
- if (i && this.options.hashAlgorithm)
1762
+ if (i === "etag")
1763
+ a.hash = \`\${o.lastModified.toString(36)}-\${o.size.toString(36)}\`;
1764
+ else if (typeof i == "string")
1764
1765
  try {
1765
- const l = await Je(o, this.options.hashAlgorithm, this.options.maxFileSize);
1766
+ const l = await Je(o, i, this.options.maxFileSize);
1766
1767
  a.hash = l;
1767
1768
  } catch (l) {
1768
1769
  console.warn(\`Failed to calculate hash for \${t}:\`, l);
@@ -2344,12 +2345,12 @@ class ss {
2344
2345
  }
2345
2346
  }
2346
2347
  typeof globalThis < "u" && globalThis.constructor.name === "DedicatedWorkerGlobalScope" && Q(new ss());
2347
- //# sourceMappingURL=worker-CS9nvwsF.js.map
2348
- `, p = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", f], { type: "text/javascript;charset=utf-8" });
2348
+ //# sourceMappingURL=worker-Dy3EFYv_.js.map
2349
+ `, f = typeof self < "u" && self.Blob && new Blob(["URL.revokeObjectURL(import.meta.url);", p], { type: "text/javascript;charset=utf-8" });
2349
2350
  function m(a) {
2350
2351
  let n;
2351
2352
  try {
2352
- if (n = p && (self.URL || self.webkitURL).createObjectURL(p), !n) throw "";
2353
+ if (n = f && (self.URL || self.webkitURL).createObjectURL(f), !n) throw "";
2353
2354
  const t = new Worker(n, {
2354
2355
  type: "module",
2355
2356
  name: a?.name
@@ -2359,7 +2360,7 @@ function m(a) {
2359
2360
  }), t;
2360
2361
  } catch {
2361
2362
  return new Worker(
2362
- "data:text/javascript;charset=utf-8," + encodeURIComponent(f),
2363
+ "data:text/javascript;charset=utf-8," + encodeURIComponent(p),
2363
2364
  {
2364
2365
  type: "module",
2365
2366
  name: a?.name
@@ -2634,8 +2635,8 @@ export {
2634
2635
  I as PermissionError,
2635
2636
  R as StorageError,
2636
2637
  $ as TimeoutError,
2637
- C as WatchEventType,
2638
- _ as basename,
2638
+ _ as WatchEventType,
2639
+ C as basename,
2639
2640
  N as buffersEqual,
2640
2641
  D as calculateFileHash,
2641
2642
  z as calculateReadLength,
@@ -2653,8 +2654,8 @@ export {
2653
2654
  B as isPathExcluded,
2654
2655
  G as joinPath,
2655
2656
  q as mapDomError,
2656
- V as matchMinimatch,
2657
- Y as normalizeMinimatch,
2657
+ Y as matchMinimatch,
2658
+ V as normalizeMinimatch,
2658
2659
  X as normalizePath,
2659
2660
  Z as removeEntry,
2660
2661
  J as resolvePath,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/facade.ts","../src/index.ts"],"sourcesContent":["import { wrap } from 'comlink';\n\nimport { decodeBuffer, encodeString, isBinaryFileExtension } from './utils/encoder';\nimport WorkerCtor from './worker?worker&inline';\n\nimport type {\n BinaryEncoding,\n DirentData,\n Encoding,\n FileOpenOptions,\n FileStat,\n OPFSOptions,\n PathLike,\n RemoteOPFSWorker,\n RenameOptions,\n StringEncoding,\n WatchOptions\n} from './types';\n\n/**\n * Utility function to convert a PathLike to a string path\n * If it's a URI, extracts the pathname; otherwise returns the string as-is\n */\nfunction normalizePath(path: PathLike): string {\n if (path instanceof URL) {\n return path.pathname;\n }\n\n return path;\n}\n\n/**\n * Facade class that provides a clean interface for communicating with the OPFS worker\n * while hiding Comlink implementation details.\n */\nexport class OPFSFileSystem {\n #worker: RemoteOPFSWorker;\n promises: OPFSFileSystem = this;\n\n constructor(options?: OPFSOptions) {\n this.#worker = wrap<RemoteOPFSWorker>(new WorkerCtor());\n\n // Set up options if provided\n if (options) {\n // We can't pass a BroadcastChannel instance to the worker, so we need to convert it to a string first\n if (options.broadcastChannel && options.broadcastChannel instanceof BroadcastChannel) {\n options.broadcastChannel = options.broadcastChannel.name;\n }\n\n // Initialize options asynchronously\n void this.setOptions(options);\n }\n }\n\n /**\n * Start watching a file or directory for changes\n */\n watch(path: PathLike, options?: WatchOptions): () => void {\n const normalizedPath = normalizePath(path);\n\n void this.#worker.watch(normalizedPath, options);\n\n return () => this.unwatch(normalizedPath);\n }\n\n /**\n * Stop watching a previously watched path\n */\n unwatch(path: PathLike) {\n const normalizedPath = normalizePath(path);\n\n void this.#worker.unwatch(normalizedPath);\n }\n\n /**\n * Update configuration options\n */\n async setOptions(options: OPFSOptions) {\n return this.#worker.setOptions(options);\n }\n\n /**\n * Get a complete index of all files and directories in the file system\n */\n async index(): Promise<Map<string, FileStat>> {\n return this.#worker.index();\n }\n\n /**\n * Read a file from the file system\n */\n // Overload for explicit string encoding - returns string\n async readFile(path: PathLike, encoding: StringEncoding): Promise<string>;\n // Overload for explicit binary encoding - returns Uint8Array\n async readFile(path: PathLike, encoding: BinaryEncoding): Promise<Uint8Array>;\n // Overload for options object with string encoding - returns string\n async readFile(path: PathLike, options: { encoding: StringEncoding }): Promise<string>;\n // Overload for options object with binary encoding - returns Uint8Array\n async readFile(path: PathLike, options: { encoding: BinaryEncoding }): Promise<Uint8Array>;\n // Overload for no encoding (auto-detected) - returns string | Uint8Array based on file extension\n async readFile(path: PathLike): Promise<string | Uint8Array>;\n // Implementation\n async readFile(\n path: PathLike,\n optionsOrEncoding?: Encoding | { encoding?: Encoding }\n ): Promise<string | Uint8Array> {\n const normalizedPath = normalizePath(path);\n\n // Handle both options object and direct encoding parameter for backward compatibility\n let encoding: Encoding | undefined;\n\n if (typeof optionsOrEncoding === 'string') {\n encoding = optionsOrEncoding;\n }\n else if (optionsOrEncoding && typeof optionsOrEncoding === 'object') {\n encoding = optionsOrEncoding.encoding;\n }\n\n // Get binary data from worker\n const buffer = await this.#worker.readFile(normalizedPath);\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = isBinaryFileExtension(normalizedPath) ? 'binary' : 'utf-8';\n }\n\n // Return binary data or decode to string\n return (encoding === 'binary') ? buffer : decodeBuffer(buffer, encoding);\n }\n\n /**\n * Write data to a file\n */\n async writeFile(\n path: PathLike,\n data: string | Uint8Array | ArrayBuffer,\n options?: { encoding?: Encoding } | Encoding\n ): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n let encoding: Encoding | undefined;\n\n if (typeof options === 'string') {\n encoding = options;\n }\n else if (options && typeof options === 'object') {\n encoding = options.encoding;\n }\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(normalizedPath)) ? 'binary' : 'utf-8';\n }\n\n // Convert data to Uint8Array\n const buffer = typeof data === 'string'\n ? encodeString(data, encoding)\n : (data instanceof Uint8Array ? data : new Uint8Array(data));\n\n return this.#worker.writeFile(normalizedPath, buffer);\n }\n\n /**\n * Append data to a file\n */\n async appendFile(\n path: PathLike,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: Encoding\n ): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(normalizedPath)) ? 'binary' : 'utf-8';\n }\n\n // Convert data to Uint8Array\n const buffer = typeof data === 'string'\n ? encodeString(data, encoding)\n : (data instanceof Uint8Array ? data : new Uint8Array(data));\n\n return this.#worker.appendFile(normalizedPath, buffer);\n }\n\n /**\n * Create a directory\n */\n async mkdir(path: PathLike, mode?: number | { recursive?: boolean }): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n let options: { recursive?: boolean } | undefined;\n\n // OPFS doesn't support file modes, so we ignore the mode parameter\n if (typeof mode === 'number') {\n options = { recursive: false };\n }\n else {\n options = mode;\n }\n\n return this.#worker.mkdir(normalizedPath, options);\n }\n\n /**\n * Get file or directory statistics\n */\n async stat(path: PathLike): Promise<FileStat> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.stat(normalizedPath);\n }\n\n /**\n * Read a directory's contents\n */\n async readDir(path: PathLike): Promise<DirentData[]> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.readDir(normalizedPath);\n }\n\n /**\n * Check if a file or directory exists\n */\n async exists(path: PathLike): Promise<boolean> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.exists(normalizedPath);\n }\n\n /**\n * Clear all contents of a directory without removing the directory itself\n */\n async clear(path?: PathLike): Promise<void> {\n const normalizedPath = path ? normalizePath(path) : undefined;\n\n return this.#worker.clear(normalizedPath);\n }\n\n /**\n * Remove files and directories\n */\n async remove(path: PathLike, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.remove(normalizedPath, options);\n }\n\n /**\n * Alias for remove() for NodeJS like API compatibility\n */\n async unlink(path: PathLike): Promise<void> {\n return this.remove(path);\n }\n\n /**\n * Alias for remove() for NodeJS like API compatibility\n */\n async rm(path: PathLike, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n return this.remove(path, options);\n }\n\n /**\n * Alias for remove() for NodeJS like API compatibility\n */\n async rmdir(path: PathLike): Promise<void> {\n return this.remove(path);\n }\n\n /**\n * Alias for readDir() for NodeJS like API compatibility\n */\n async readdir(path: PathLike, _options?: unknown): Promise<DirentData[]> {\n return this.readDir(path);\n }\n\n /**\n * Alias for stat() for NodeJS like API compatibility\n */\n async lstat(path: PathLike): Promise<FileStat> {\n return this.stat(path);\n }\n\n /**\n * Note: OPFS doesn't support file modes, so this is a no-op and exists only for compatibility with tools like isomorphic-git\n */\n async chmod(_path: PathLike, _mode: number): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Resolve a path to an absolute path\n */\n async realpath(path: PathLike): Promise<string> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.realpath(normalizedPath);\n }\n\n /**\n * Rename a file or directory\n */\n async rename(oldPath: PathLike, newPath: PathLike, options?: RenameOptions): Promise<void> {\n const normalizedOldPath = normalizePath(oldPath);\n const normalizedNewPath = normalizePath(newPath);\n\n return this.#worker.rename(normalizedOldPath, normalizedNewPath, options);\n }\n\n /**\n * Copy files and directories\n */\n async copy(source: PathLike, destination: PathLike, options?: { recursive?: boolean; overwrite?: boolean }): Promise<void> {\n const normalizedSource = normalizePath(source);\n const normalizedDestination = normalizePath(destination);\n\n return this.#worker.copy(normalizedSource, normalizedDestination, options);\n }\n\n /**\n * Open a file and return a file descriptor\n */\n async open(path: PathLike, options?: FileOpenOptions): Promise<number> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.open(normalizedPath, options);\n }\n\n /**\n * Close a file descriptor\n */\n async close(fd: number): Promise<void> {\n return this.#worker.close(fd);\n }\n\n /**\n * Read data from a file descriptor\n * \n * This method requires special handling due to Comlink transfer requirements.\n * The buffer is transferred to the worker and back, so the original buffer\n * becomes unusable after the call.\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 { bytesRead, buffer: transferred } = await this.#worker.read(\n fd,\n // Temp buffer to preserve the original buffer\n new Uint8Array(length),\n 0,\n length,\n position\n );\n\n // Copy the data from the transferred buffer to the original buffer\n if (bytesRead > 0) {\n buffer.set(transferred.subarray(0, bytesRead), offset);\n }\n\n return { bytesRead, buffer };\n }\n\n /**\n * Write data to a file descriptor\n */\n async write(\n fd: number,\n buffer: Uint8Array,\n offset?: number,\n length?: number,\n position?: number | null | undefined,\n emitEvent?: boolean\n ): Promise<number> {\n return this.#worker.write(fd, buffer, offset, length, position, emitEvent);\n }\n\n /**\n * Get file status information by file descriptor\n */\n async fstat(fd: number): Promise<FileStat> {\n return this.#worker.fstat(fd);\n }\n\n /**\n * Truncate file to specified size\n */\n async ftruncate(fd: number, size?: number): Promise<void> {\n return this.#worker.ftruncate(fd, size);\n }\n\n /**\n * Synchronize file data to storage (fsync equivalent)\n */\n async fsync(fd: number): Promise<void> {\n return this.#worker.fsync(fd);\n }\n\n /**\n * Dispose of resources and clean up the file system instance\n */\n dispose() {\n void this.#worker.dispose();\n }\n\n /**\n * Synchronize the file system with external data\n */\n async createIndex(entries: [PathLike, string | Uint8Array | Blob][]): Promise<void> {\n const normalizedEntries = entries.map(([path, data]) => [normalizePath(path), data] as [string, string | Uint8Array | Blob]);\n\n return this.#worker.createIndex(normalizedEntries);\n }\n\n /**\n * Read a file as text with automatic encoding detection\n */\n async readText(path: PathLike, encoding: Encoding = 'utf-8'): Promise<string> {\n const normalizedPath = normalizePath(path);\n const buffer = await this.#worker.readFile(normalizedPath);\n\n return decodeBuffer(buffer, encoding);\n }\n\n /**\n * Write text to a file with specified encoding\n */\n async writeText(path: PathLike, text: string, encoding: Encoding = 'utf-8'): Promise<void> {\n const normalizedPath = normalizePath(path);\n const buffer = encodeString(text, encoding);\n\n return this.#worker.writeFile(normalizedPath, buffer);\n }\n\n /**\n * Append text to a file with specified encoding\n */\n async appendText(path: PathLike, text: string, encoding: Encoding = 'utf-8'): Promise<void> {\n const normalizedPath = normalizePath(path);\n const buffer = encodeString(text, encoding);\n\n return this.#worker.appendFile(normalizedPath, buffer);\n }\n}\n","import { OPFSFileSystem } from './facade';\n\nimport type { OPFSOptions } from './types';\n\nexport * from './types';\nexport * from './utils/errors';\nexport * from './utils/helpers';\nexport * from './utils/encoder';\nexport * from './facade';\n\n/**\n * Creates a new file system instance with inline worker\n * @param options - Optional configuration options\n * @returns Promise resolving to the file system interface\n */\nexport function createWorker(\n options?: OPFSOptions\n): OPFSFileSystem {\n return new OPFSFileSystem(options);\n}\n"],"names":["normalizePath","path","OPFSFileSystem","#worker","options","wrap","WorkerCtor","normalizedPath","optionsOrEncoding","encoding","buffer","isBinaryFileExtension","decodeBuffer","data","encodeString","mode","_options","_path","_mode","oldPath","newPath","normalizedOldPath","normalizedNewPath","source","destination","normalizedSource","normalizedDestination","fd","offset","length","position","bytesRead","transferred","emitEvent","size","entries","normalizedEntries","text","create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AAAA;AAAA;AAAA,EAKA,MAAM,UAAUR,GAAgBoC,GAAc5B,IAAqB,SAAwB;AACvF,UAAMF,IAAiBP,EAAcC,CAAI,GACnCS,IAASI,EAAauB,GAAM5B,CAAQ;AAE1C,WAAO,KAAKN,GAAQ,UAAUI,GAAgBG,CAAM;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAWT,GAAgBoC,GAAc5B,IAAqB,SAAwB;AACxF,UAAMF,IAAiBP,EAAcC,CAAI,GACnCS,IAASI,EAAauB,GAAM5B,CAAQ;AAE1C,WAAO,KAAKN,GAAQ,WAAWI,GAAgBG,CAAM;AAAA,EACzD;AACJ;AChbO,SAAS4B,EACZlC,GACc;AACd,SAAO,IAAIF,EAAeE,CAAO;AACrC;"}
1
+ {"version":3,"file":"index.js","sources":["../src/facade.ts","../src/index.ts"],"sourcesContent":["import { wrap } from 'comlink';\n\nimport { decodeBuffer, encodeString, isBinaryFileExtension } from './utils/encoder';\nimport WorkerCtor from './worker?worker&inline';\n\nimport type {\n BinaryEncoding,\n DirentData,\n Encoding,\n FileOpenOptions,\n FileStat,\n OPFSOptions,\n PathLike,\n RemoteOPFSWorker,\n RenameOptions,\n StringEncoding,\n WatchOptions\n} from './types';\n\n/**\n * Utility function to convert a PathLike to a string path\n * If it's a URI, extracts the pathname; otherwise returns the string as-is\n */\nfunction normalizePath(path: PathLike): string {\n if (path instanceof URL) {\n return path.pathname;\n }\n\n return path;\n}\n\n/**\n * Facade class that provides a clean interface for communicating with the OPFS worker\n * while hiding Comlink implementation details.\n */\nexport class OPFSFileSystem {\n #worker: RemoteOPFSWorker;\n promises: OPFSFileSystem = this;\n\n constructor(options?: OPFSOptions) {\n this.#worker = wrap<RemoteOPFSWorker>(new WorkerCtor());\n\n // Set up options if provided\n if (options) {\n // We can't pass a BroadcastChannel instance to the worker, so we need to convert it to a string first\n if (options.broadcastChannel && options.broadcastChannel instanceof BroadcastChannel) {\n options.broadcastChannel = options.broadcastChannel.name;\n }\n\n // Initialize options asynchronously\n void this.setOptions(options);\n }\n }\n\n /**\n * Start watching a file or directory for changes\n */\n watch(path: PathLike, options?: WatchOptions): () => void {\n const normalizedPath = normalizePath(path);\n\n void this.#worker.watch(normalizedPath, options);\n\n return () => this.unwatch(normalizedPath);\n }\n\n /**\n * Stop watching a previously watched path\n */\n unwatch(path: PathLike) {\n const normalizedPath = normalizePath(path);\n\n void this.#worker.unwatch(normalizedPath);\n }\n\n /**\n * Update configuration options\n */\n async setOptions(options: OPFSOptions) {\n return this.#worker.setOptions(options);\n }\n\n /**\n * Get a complete index of all files and directories in the file system\n */\n async index(): Promise<Map<string, FileStat>> {\n return this.#worker.index();\n }\n\n /**\n * Read a file from the file system\n */\n // Overload for explicit string encoding - returns string\n async readFile(path: PathLike, encoding: StringEncoding): Promise<string>;\n // Overload for explicit binary encoding - returns Uint8Array\n async readFile(path: PathLike, encoding: BinaryEncoding): Promise<Uint8Array>;\n // Overload for options object with string encoding - returns string\n async readFile(path: PathLike, options: { encoding: StringEncoding }): Promise<string>;\n // Overload for options object with binary encoding - returns Uint8Array\n async readFile(path: PathLike, options: { encoding: BinaryEncoding }): Promise<Uint8Array>;\n // Overload for no encoding (auto-detected) - returns string | Uint8Array based on file extension\n async readFile(path: PathLike): Promise<string | Uint8Array>;\n // Implementation\n async readFile(\n path: PathLike,\n optionsOrEncoding?: Encoding | { encoding?: Encoding }\n ): Promise<string | Uint8Array> {\n const normalizedPath = normalizePath(path);\n\n // Handle both options object and direct encoding parameter for backward compatibility\n let encoding: Encoding | undefined;\n\n if (typeof optionsOrEncoding === 'string') {\n encoding = optionsOrEncoding;\n }\n else if (optionsOrEncoding && typeof optionsOrEncoding === 'object') {\n encoding = optionsOrEncoding.encoding;\n }\n\n // Get binary data from worker\n const buffer = await this.#worker.readFile(normalizedPath);\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = isBinaryFileExtension(normalizedPath) ? 'binary' : 'utf-8';\n }\n\n // Return binary data or decode to string\n return (encoding === 'binary') ? buffer : decodeBuffer(buffer, encoding);\n }\n\n /**\n * Write data to a file\n */\n async writeFile(\n path: PathLike,\n data: string | Uint8Array | ArrayBuffer,\n options?: { encoding?: Encoding } | Encoding\n ): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n let encoding: Encoding | undefined;\n\n if (typeof options === 'string') {\n encoding = options;\n }\n else if (options && typeof options === 'object') {\n encoding = options.encoding;\n }\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(normalizedPath)) ? 'binary' : 'utf-8';\n }\n\n // Convert data to Uint8Array\n const buffer = typeof data === 'string'\n ? encodeString(data, encoding)\n : (data instanceof Uint8Array ? data : new Uint8Array(data));\n\n return this.#worker.writeFile(normalizedPath, buffer);\n }\n\n /**\n * Append data to a file\n */\n async appendFile(\n path: PathLike,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: Encoding\n ): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(normalizedPath)) ? 'binary' : 'utf-8';\n }\n\n // Convert data to Uint8Array\n const buffer = typeof data === 'string'\n ? encodeString(data, encoding)\n : (data instanceof Uint8Array ? data : new Uint8Array(data));\n\n return this.#worker.appendFile(normalizedPath, buffer);\n }\n\n /**\n * Create a directory\n */\n async mkdir(path: PathLike, mode?: number | { recursive?: boolean }): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n let options: { recursive?: boolean } | undefined;\n\n // OPFS doesn't support file modes, so we ignore the mode parameter\n if (typeof mode === 'number') {\n options = { recursive: false };\n }\n else {\n options = mode;\n }\n\n return this.#worker.mkdir(normalizedPath, options);\n }\n\n /**\n * Get file or directory statistics\n */\n async stat(path: PathLike): Promise<FileStat> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.stat(normalizedPath);\n }\n\n /**\n * Read a directory's contents\n */\n async readDir(path: PathLike): Promise<DirentData[]> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.readDir(normalizedPath);\n }\n\n /**\n * Check if a file or directory exists\n */\n async exists(path: PathLike): Promise<boolean> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.exists(normalizedPath);\n }\n\n /**\n * Clear all contents of a directory without removing the directory itself\n */\n async clear(path?: PathLike): Promise<void> {\n const normalizedPath = path ? normalizePath(path) : undefined;\n\n return this.#worker.clear(normalizedPath);\n }\n\n /**\n * Remove files and directories\n */\n async remove(path: PathLike, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.remove(normalizedPath, options);\n }\n\n /**\n * Alias for remove() for NodeJS like API compatibility\n */\n async unlink(path: PathLike): Promise<void> {\n return this.remove(path);\n }\n\n /**\n * Alias for remove() for NodeJS like API compatibility\n */\n async rm(path: PathLike, options?: { recursive?: boolean; force?: boolean }): Promise<void> {\n return this.remove(path, options);\n }\n\n /**\n * Alias for remove() for NodeJS like API compatibility\n */\n async rmdir(path: PathLike): Promise<void> {\n return this.remove(path);\n }\n\n /**\n * Alias for readDir() for NodeJS like API compatibility\n */\n async readdir(path: PathLike, _options?: unknown): Promise<DirentData[]> {\n return this.readDir(path);\n }\n\n /**\n * Alias for stat() for NodeJS like API compatibility\n */\n async lstat(path: PathLike): Promise<FileStat> {\n return this.stat(path);\n }\n\n /**\n * Note: OPFS doesn't support file modes, so this is a no-op and exists only for compatibility with tools like isomorphic-git\n */\n async chmod(_path: PathLike, _mode: number): Promise<void> {\n return Promise.resolve();\n }\n\n /**\n * Resolve a path to an absolute path\n */\n async realpath(path: PathLike): Promise<string> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.realpath(normalizedPath);\n }\n\n /**\n * Rename a file or directory\n */\n async rename(oldPath: PathLike, newPath: PathLike, options?: RenameOptions): Promise<void> {\n const normalizedOldPath = normalizePath(oldPath);\n const normalizedNewPath = normalizePath(newPath);\n\n return this.#worker.rename(normalizedOldPath, normalizedNewPath, options);\n }\n\n /**\n * Copy files and directories\n */\n async copy(source: PathLike, destination: PathLike, options?: { recursive?: boolean; overwrite?: boolean }): Promise<void> {\n const normalizedSource = normalizePath(source);\n const normalizedDestination = normalizePath(destination);\n\n return this.#worker.copy(normalizedSource, normalizedDestination, options);\n }\n\n /**\n * Open a file and return a file descriptor\n */\n async open(path: PathLike, options?: FileOpenOptions): Promise<number> {\n const normalizedPath = normalizePath(path);\n\n return this.#worker.open(normalizedPath, options);\n }\n\n /**\n * Close a file descriptor\n */\n async close(fd: number): Promise<void> {\n return this.#worker.close(fd);\n }\n\n /**\n * Read data from a file descriptor\n * \n * This method requires special handling due to Comlink transfer requirements.\n * The buffer is transferred to the worker and back, so the original buffer\n * becomes unusable after the call.\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 { bytesRead, buffer: transferred } = await this.#worker.read(\n fd,\n // Temp buffer to preserve the original buffer\n new Uint8Array(length),\n 0,\n length,\n position\n );\n\n // Copy the data from the transferred buffer to the original buffer\n if (bytesRead > 0) {\n buffer.set(transferred.subarray(0, bytesRead), offset);\n }\n\n return { bytesRead, buffer };\n }\n\n /**\n * Write data to a file descriptor\n */\n async write(\n fd: number,\n buffer: Uint8Array,\n offset?: number,\n length?: number,\n position?: number | null | undefined,\n emitEvent?: boolean\n ): Promise<number> {\n return this.#worker.write(fd, buffer, offset, length, position, emitEvent);\n }\n\n /**\n * Get file status information by file descriptor\n */\n async fstat(fd: number): Promise<FileStat> {\n return this.#worker.fstat(fd);\n }\n\n /**\n * Truncate file to specified size\n */\n async ftruncate(fd: number, size?: number): Promise<void> {\n return this.#worker.ftruncate(fd, size);\n }\n\n /**\n * Synchronize file data to storage (fsync equivalent)\n */\n async fsync(fd: number): Promise<void> {\n return this.#worker.fsync(fd);\n }\n\n /**\n * Dispose of resources and clean up the file system instance\n */\n dispose() {\n void this.#worker.dispose();\n }\n\n /**\n * Synchronize the file system with external data\n */\n async createIndex(entries: [PathLike, string | Uint8Array | Blob][]): Promise<void> {\n const normalizedEntries = entries.map(([path, data]) => [normalizePath(path), data] as [string, string | Uint8Array | Blob]);\n\n return this.#worker.createIndex(normalizedEntries);\n }\n\n /**\n * Read a file as text with automatic encoding detection\n */\n async readText(path: PathLike, encoding: Encoding = 'utf-8'): Promise<string> {\n const normalizedPath = normalizePath(path);\n const buffer = await this.#worker.readFile(normalizedPath);\n\n return decodeBuffer(buffer, encoding);\n }\n\n /**\n * Write text to a file with specified encoding\n */\n async writeText(path: PathLike, text: string, encoding: Encoding = 'utf-8'): Promise<void> {\n const normalizedPath = normalizePath(path);\n const buffer = encodeString(text, encoding);\n\n return this.#worker.writeFile(normalizedPath, buffer);\n }\n\n /**\n * Append text to a file with specified encoding\n */\n async appendText(path: PathLike, text: string, encoding: Encoding = 'utf-8'): Promise<void> {\n const normalizedPath = normalizePath(path);\n const buffer = encodeString(text, encoding);\n\n return this.#worker.appendFile(normalizedPath, buffer);\n }\n}\n","import { OPFSFileSystem } from './facade';\n\nimport type { OPFSOptions } from './types';\n\nexport * from './types';\nexport * from './utils/errors';\nexport * from './utils/helpers';\nexport * from './utils/encoder';\nexport * from './facade';\n\n/**\n * Creates a new file system instance with inline worker\n * @param options - Optional configuration options\n * @returns Promise resolving to the file system interface\n */\nexport function createWorker(\n options?: OPFSOptions\n): OPFSFileSystem {\n return new OPFSFileSystem(options);\n}\n"],"names":["normalizePath","path","OPFSFileSystem","#worker","options","wrap","WorkerCtor","normalizedPath","optionsOrEncoding","encoding","buffer","isBinaryFileExtension","decodeBuffer","data","encodeString","mode","_options","_path","_mode","oldPath","newPath","normalizedOldPath","normalizedNewPath","source","destination","normalizedSource","normalizedDestination","fd","offset","length","position","bytesRead","transferred","emitEvent","size","entries","normalizedEntries","text","createWorker"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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MF,IAAiBP,EAAcC,CAAI,GACnCS,IAASI,EAAauB,GAAM5B,CAAQ;AAE1C,WAAO,KAAKN,GAAQ,UAAUI,GAAgBG,CAAM;AAAA,EACxD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAWT,GAAgBoC,GAAc5B,IAAqB,SAAwB;AACxF,UAAMF,IAAiBP,EAAcC,CAAI,GACnCS,IAASI,EAAauB,GAAM5B,CAAQ;AAE1C,WAAO,KAAKN,GAAQ,WAAWI,GAAgBG,CAAM;AAAA,EACzD;AACJ;AChbO,SAAS4B,EACZlC,GACc;AACd,SAAO,IAAIF,EAAeE,CAAO;AACrC;"}
package/dist/raw.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("comlink"),r=require("./helpers-04x7UBul.cjs");class f{root;watchers=new Map;mountingPromise=null;broadcastChannel=null;options={root:"/",namespace:"",maxFileSize:50*1024*1024,hashAlgorithm:!1,broadcastChannel:"opfs-worker"};openFiles=new Map;nextFd=1;_getFileDescriptor(t){const e=this.openFiles.get(t);if(!e)throw new r.OPFSError(`Invalid file descriptor: ${t}`,"EBADF");return e}async notifyChange(t){if(!this.options.broadcastChannel)return;const e=t.path;if(![...this.watchers.values()].some(s=>r.matchMinimatch(e,s.pattern)&&s.include.some(n=>n&&r.matchMinimatch(e,n))&&!s.exclude.some(n=>n&&r.matchMinimatch(e,n))))return;let a;if(this.options.hashAlgorithm)try{a=(await this.stat(e)).hash}catch{}try{this.broadcastChannel||(this.broadcastChannel=new BroadcastChannel(this.options.broadcastChannel));const s={namespace:this.options.namespace,timestamp:new Date().toISOString(),...t,...a&&{hash:a}};this.broadcastChannel.postMessage(s)}catch(s){console.warn("Failed to send event via BroadcastChannel:",s)}}constructor(t){r.checkOPFSSupport(),t&&this.setOptions(t)}async mount(){const t=this.options.root;return this.mountingPromise&&await this.mountingPromise,this.mountingPromise=new Promise(async(e,i)=>{try{const a=await navigator.storage.getDirectory();this.root=t==="/"?a:await this.getDirectoryHandle(t,!0,a),e(!0)}catch(a){i(new r.OPFSError("Failed to initialize OPFS","INIT_FAILED",t,a))}finally{this.mountingPromise=null}}),this.mountingPromise}async setOptions(t){t.hashAlgorithm!==void 0&&(this.options.hashAlgorithm=t.hashAlgorithm),t.maxFileSize!==void 0&&(this.options.maxFileSize=t.maxFileSize),t.broadcastChannel!==void 0&&(this.broadcastChannel&&this.options.broadcastChannel!==t.broadcastChannel&&(this.broadcastChannel.close(),this.broadcastChannel=null),this.options.broadcastChannel=t.broadcastChannel),t.namespace&&(this.options.namespace=t.namespace),t.root!==void 0&&(this.options.root=r.normalizePath(t.root),this.options.namespace||(this.options.namespace=`opfs-worker:${this.options.root}`),await this.mount())}async getDirectoryHandle(t,e=!1,i=this.root){const a=Array.isArray(t)?t:r.splitPath(t);let s=i;for(const n of a)s=await s.getDirectoryHandle(n,{create:e});return s}async getFileHandle(t,e=!1,i=this.root){const a=r.splitPath(t);if(a.length===0)throw new r.PathError("Path must not be empty",Array.isArray(t)?t.join("/"):t);const s=a.pop();return(await this.getDirectoryHandle(a,e,i)).getFileHandle(s,{create:e})}async index(){const t=new Map,e=async i=>{const a=await this.readDir(i);for(const s of a){const n=`${i==="/"?"":i}/${s.name}`;try{const o=await this.stat(n);t.set(n,o),o.isDirectory&&await e(n)}catch(o){console.warn(`Skipping broken entry: ${n}`,o)}}};return t.set("/",{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}),await e("/"),t}async readFile(t){await this.mount();try{return await r.withLock(t,"shared",async()=>{const e=await this.open(t);try{const{size:i}=await this.fstat(e),a=new Uint8Array(i);return i>0&&await this.read(e,a,0,i,0),d.transfer(a,[a.buffer])}finally{await this.close(e)}})}catch(e){throw new r.FileNotFoundError(t,e)}}async writeFile(t,e){await this.mount();const i=e instanceof Uint8Array?e:new Uint8Array(e);await r.withLock(t,"exclusive",async()=>{const a=await this.exists(t),s=await this.open(t,{create:!0,truncate:!0});try{await this.write(s,i,0,i.length,null,!1),await this.fsync(s)}finally{await this.close(s)}await this.notifyChange({path:t,type:a?r.WatchEventType.Changed:r.WatchEventType.Added,isDirectory:!1})})}async appendFile(t,e){await this.mount();const i=e instanceof Uint8Array?e:new Uint8Array(e);await r.withLock(t,"exclusive",async()=>{const a=await this.open(t,{create:!0});try{const{size:s}=await this.fstat(a);await this.write(a,i,0,i.length,s,!1),await this.fsync(a)}finally{await this.close(a)}await this.notifyChange({path:t,type:r.WatchEventType.Changed,isDirectory:!1})})}async mkdir(t,e){await this.mount();const i=e?.recursive??!1,a=r.splitPath(t);let s=this.root;for(let n=0;n<a.length;n++){const o=a[n];try{s=await s.getDirectoryHandle(o,{create:i||n===a.length-1})}catch(c){throw c.name==="NotFoundError"?new r.OPFSError(`Parent directory does not exist: ${r.joinPath(a.slice(0,n+1))}`,"ENOENT",void 0,c):c.name==="TypeMismatchError"?new r.OPFSError(`Path segment is not a directory: ${o}`,"ENOTDIR",void 0,c):new r.OPFSError("Failed to create directory","MKDIR_FAILED",void 0,c)}}await this.notifyChange({path:t,type:r.WatchEventType.Added,isDirectory:!0})}async stat(t){if(await this.mount(),t==="/")return{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0};const e=r.basename(t),i=await this.getDirectoryHandle(r.dirname(t),!1),a=this.options.hashAlgorithm!==null;try{const n=await(await i.getFileHandle(e,{create:!1})).getFile(),o={kind:"file",size:n.size,mtime:new Date(n.lastModified).toISOString(),ctime:new Date(n.lastModified).toISOString(),isFile:!0,isDirectory:!1};if(a&&this.options.hashAlgorithm)try{const c=await r.calculateFileHash(n,this.options.hashAlgorithm,this.options.maxFileSize);o.hash=c}catch(c){console.warn(`Failed to calculate hash for ${t}:`,c)}return o}catch(s){if(s.name!=="TypeMismatchError"&&s.name!=="NotFoundError")throw new r.OPFSError("Failed to stat (file)","STAT_FAILED",void 0,s)}try{return await i.getDirectoryHandle(e,{create:!1}),{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}}catch(s){throw s.name==="NotFoundError"?new r.OPFSError(`No such file or directory: ${t}`,"ENOENT",void 0,s):new r.OPFSError("Failed to stat (directory)","STAT_FAILED",void 0,s)}}async readDir(t){await this.mount();const e=await this.getDirectoryHandle(t,!1),i=[];for await(const[a,s]of e.entries()){const n=s.kind==="file";i.push({name:a,kind:s.kind,isFile:n,isDirectory:!n})}return i}async exists(t){if(await this.mount(),t==="/")return!0;const e=r.basename(t);let i=null;try{i=await this.getDirectoryHandle(r.dirname(t),!1)}catch(a){if(i=null,a.name!=="NotFoundError"&&a.name!=="TypeMismatchError")throw a}if(!i||!e)return!1;try{return await i.getFileHandle(e,{create:!1}),!0}catch(a){if(a.name!=="NotFoundError"&&a.name!=="TypeMismatchError")throw a;try{return await i.getDirectoryHandle(e,{create:!1}),!0}catch(s){if(s.name!=="NotFoundError"&&s.name!=="TypeMismatchError")throw s;return!1}}}async clear(t="/"){await this.mount();try{const e=await this.readDir(t);for(const i of e){const a=`${t==="/"?"":t}/${i.name}`;await this.remove(a,{recursive:!0})}await this.notifyChange({path:t,type:r.WatchEventType.Changed,isDirectory:!0})}catch(e){throw e instanceof r.OPFSError?e:new r.OPFSError(`Failed to clear directory: ${t}`,"CLEAR_FAILED",void 0,e)}}async remove(t,e){if(await this.mount(),t==="/")throw new r.OPFSError("Cannot remove root directory","EROOT");const{recursive:i=!1,force:a=!1}=e||{},s=await this.getDirectoryHandle(r.dirname(t),!1),n=await this.stat(t);await r.removeEntry(s,t,{recursive:i,force:a}),await this.notifyChange({path:t,type:r.WatchEventType.Removed,isDirectory:n.isDirectory})}async realpath(t){await this.mount();try{const e=r.resolvePath(t);if(!await this.exists(e))throw new r.FileNotFoundError(e);return e}catch(e){throw e instanceof r.OPFSError?e:new r.OPFSError(`Failed to resolve path: ${t}`,"REALPATH_FAILED",void 0,e)}}async rename(t,e,i){await this.mount();try{const a=i?.overwrite??!1,s=await this.stat(t);if(await this.exists(e)&&!a)throw new r.OPFSError(`Destination already exists: ${e}`,"EEXIST",void 0);await this.copy(t,e,{recursive:!0,overwrite:a}),await this.remove(t,{recursive:!0}),await this.notifyChange({path:t,type:r.WatchEventType.Removed,isDirectory:s.isDirectory}),await this.notifyChange({path:e,type:r.WatchEventType.Added,isDirectory:s.isDirectory})}catch(a){throw a instanceof r.OPFSError?a:new r.OPFSError(`Failed to rename from ${t} to ${e}`,"RENAME_FAILED",void 0,a)}}async copy(t,e,i){await this.mount();try{const a=i?.recursive??!1,s=i?.overwrite??!0;if(!await this.exists(t))throw new r.OPFSError(`Source does not exist: ${t}`,"ENOENT",void 0);if(await this.exists(e)&&!s)throw new r.OPFSError(`Destination already exists: ${e}`,"EEXIST",void 0);if((await this.stat(t)).isFile){const h=await this.readFile(t);await this.writeFile(e,h)}else{if(!a)throw new r.OPFSError(`Cannot copy directory without recursive option: ${t}`,"EISDIR",void 0);await this.mkdir(e,{recursive:!0});const h=await this.readDir(t);for(const l of h){const w=`${t}/${l.name}`,y=`${e}/${l.name}`;await this.copy(w,y,{recursive:!0,overwrite:s})}}}catch(a){throw a instanceof r.OPFSError?a:new r.OPFSError(`Failed to copy from ${t} to ${e}`,"CP_FAILED",void 0,a)}}async watch(t,e){if(!this.options.broadcastChannel)throw new r.OPFSError("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.","ENOENT");const i={pattern:r.normalizeMinimatch(t,e?.recursive??!0),include:Array.isArray(e?.include)?e.include:[e?.include??"**"],exclude:Array.isArray(e?.exclude)?e.exclude:[e?.exclude??""]};this.watchers.set(t,i)}unwatch(t){this.watchers.delete(t)}async open(t,e){await this.mount();const{create:i=!1,exclusive:a=!1,truncate:s=!1}=e||{},n=r.normalizePath(r.resolvePath(t));try{return i&&a?await r.withLock(n,"exclusive",async()=>{if(await this.exists(n))throw new r.OPFSError(`File already exists: ${n}`,"EEXIST",n);return this._openFile(n,i,s)}):await this._openFile(n,i,s)}catch(o){throw o instanceof r.OPFSError?o:new r.OPFSError(`Failed to open file: ${n}`,"OPEN_FAILED",n,o)}}async _openFile(t,e,i){const a=await this.getFileHandle(t,e);try{await a.getFile()}catch(o){throw o.name==="TypeMismatchError"?new r.OPFSError(`Is a directory: ${t}`,"EISDIR",t):o}const s=await r.createSyncHandleSafe(a,t);i&&(s.truncate(0),s.flush());const n=this.nextFd++;return this.openFiles.set(n,{path:t,fileHandle:a,syncHandle:s,position:0}),n}async close(t){const e=this._getFileDescriptor(t);r.safeCloseSyncHandle(t,e.syncHandle,e.path),this.openFiles.delete(t)}async read(t,e,i,a,s){const n=this._getFileDescriptor(t);r.validateReadWriteArgs(e.length,i,a,s);try{const o=s??n.position,c=n.syncHandle.getSize(),{isEOF:h,actualLength:l}=r.calculateReadLength(o,a,c);if(h)return d.transfer({bytesRead:0,buffer:e},[e.buffer]);const w=e.subarray(i,i+l),y=n.syncHandle.read(w,{at:o});return s==null&&(n.position=o+y),d.transfer({bytesRead:y,buffer:e},[e.buffer])}catch(o){throw r.createFDError("read",t,n.path,o)}}async write(t,e,i=0,a,s,n=!0){const o=this._getFileDescriptor(t),c=a??e.length-i;r.validateReadWriteArgs(e.length,i,c,s);try{const h=s??o.position,l=e.subarray(i,i+c),w=o.syncHandle.write(l,{at:h});return(s==null||s===o.position)&&(o.position=h+w),n&&await this.notifyChange({path:o.path,type:r.WatchEventType.Changed,isDirectory:!1}),w}catch(h){throw r.createFDError("write",t,o.path,h)}}async fstat(t){const e=this._getFileDescriptor(t);return this.stat(e.path)}async ftruncate(t,e=0){const i=this._getFileDescriptor(t);if(e<0||!Number.isInteger(e))throw new r.OPFSError("Invalid size","EINVAL");try{i.syncHandle.truncate(e),i.syncHandle.flush(),i.position>e&&(i.position=e),await this.notifyChange({path:i.path,type:r.WatchEventType.Changed,isDirectory:!1})}catch(a){throw r.createFDError("truncate",t,i.path,a)}}async fsync(t){const e=this._getFileDescriptor(t);try{e.syncHandle.flush()}catch(i){throw r.createFDError("sync",t,e.path,i)}}dispose(){this.broadcastChannel&&(this.broadcastChannel.close(),this.broadcastChannel=null),this.watchers.clear();for(const[t,e]of this.openFiles)r.safeCloseSyncHandle(t,e.syncHandle,e.path);this.openFiles.clear(),this.nextFd=1}async createIndex(t){await this.mount();try{for(const[e,i]of t){const a=r.normalizePath(e);let s;i instanceof Blob?s=await r.convertBlobToUint8Array(i):typeof i=="string"?s=new TextEncoder().encode(i):s=i,await this.writeFile(a,s)}}catch(e){throw e instanceof r.OPFSError?e:new r.OPFSError("Failed to sync file system","SYNC_FAILED",void 0,e)}}}typeof globalThis<"u"&&globalThis.constructor.name==="DedicatedWorkerGlobalScope"&&d.expose(new f);exports.OPFSWorker=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("comlink"),i=require("./helpers-ppMRzIAJ.cjs");class f{root;watchers=new Map;mountingPromise=null;broadcastChannel=null;options={root:"/",namespace:"",maxFileSize:50*1024*1024,hashAlgorithm:"etag",broadcastChannel:"opfs-worker"};openFiles=new Map;nextFd=1;_getFileDescriptor(t){const e=this.openFiles.get(t);if(!e)throw new i.OPFSError(`Invalid file descriptor: ${t}`,"EBADF");return e}async notifyChange(t){if(!this.options.broadcastChannel)return;const e=t.path;if(![...this.watchers.values()].some(s=>i.matchMinimatch(e,s.pattern)&&s.include.some(n=>n&&i.matchMinimatch(e,n))&&!s.exclude.some(n=>n&&i.matchMinimatch(e,n))))return;let r;if(this.options.hashAlgorithm)try{r=(await this.stat(e)).hash}catch{}try{this.broadcastChannel||(this.broadcastChannel=new BroadcastChannel(this.options.broadcastChannel));const s={namespace:this.options.namespace,timestamp:new Date().toISOString(),...t,...r&&{hash:r}};this.broadcastChannel.postMessage(s)}catch(s){console.warn("Failed to send event via BroadcastChannel:",s)}}constructor(t){i.checkOPFSSupport(),t&&this.setOptions(t)}async mount(){const t=this.options.root;return this.mountingPromise&&await this.mountingPromise,this.mountingPromise=new Promise(async(e,a)=>{try{const r=await navigator.storage.getDirectory();this.root=t==="/"?r:await this.getDirectoryHandle(t,!0,r),e(!0)}catch(r){a(new i.OPFSError("Failed to initialize OPFS","INIT_FAILED",t,r))}finally{this.mountingPromise=null}}),this.mountingPromise}async setOptions(t){t.hashAlgorithm!==void 0&&(this.options.hashAlgorithm=t.hashAlgorithm),t.maxFileSize!==void 0&&(this.options.maxFileSize=t.maxFileSize),t.broadcastChannel!==void 0&&(this.broadcastChannel&&this.options.broadcastChannel!==t.broadcastChannel&&(this.broadcastChannel.close(),this.broadcastChannel=null),this.options.broadcastChannel=t.broadcastChannel),t.namespace&&(this.options.namespace=t.namespace),t.root!==void 0&&(this.options.root=i.normalizePath(t.root),this.options.namespace||(this.options.namespace=`opfs-worker:${this.options.root}`),await this.mount())}async getDirectoryHandle(t,e=!1,a=this.root){const r=Array.isArray(t)?t:i.splitPath(t);let s=a;for(const n of r)s=await s.getDirectoryHandle(n,{create:e});return s}async getFileHandle(t,e=!1,a=this.root){const r=i.splitPath(t);if(r.length===0)throw new i.PathError("Path must not be empty",Array.isArray(t)?t.join("/"):t);const s=r.pop();return(await this.getDirectoryHandle(r,e,a)).getFileHandle(s,{create:e})}async index(){const t=new Map,e=async a=>{const r=await this.readDir(a);for(const s of r){const n=`${a==="/"?"":a}/${s.name}`;try{const o=await this.stat(n);t.set(n,o),o.isDirectory&&await e(n)}catch(o){console.warn(`Skipping broken entry: ${n}`,o)}}};return t.set("/",{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}),await e("/"),t}async readFile(t){await this.mount();try{return await i.withLock(t,"shared",async()=>{const e=await this.open(t);try{const{size:a}=await this.fstat(e),r=new Uint8Array(a);return a>0&&await this.read(e,r,0,a,0),d.transfer(r,[r.buffer])}finally{await this.close(e)}})}catch(e){throw new i.FileNotFoundError(t,e)}}async writeFile(t,e){await this.mount();const a=e instanceof Uint8Array?e:new Uint8Array(e);await i.withLock(t,"exclusive",async()=>{const r=await this.exists(t),s=await this.open(t,{create:!0,truncate:!0});try{await this.write(s,a,0,a.length,null,!1),await this.fsync(s)}finally{await this.close(s)}await this.notifyChange({path:t,type:r?i.WatchEventType.Changed:i.WatchEventType.Added,isDirectory:!1})})}async appendFile(t,e){await this.mount();const a=e instanceof Uint8Array?e:new Uint8Array(e);await i.withLock(t,"exclusive",async()=>{const r=await this.open(t,{create:!0});try{const{size:s}=await this.fstat(r);await this.write(r,a,0,a.length,s,!1),await this.fsync(r)}finally{await this.close(r)}await this.notifyChange({path:t,type:i.WatchEventType.Changed,isDirectory:!1})})}async mkdir(t,e){await this.mount();const a=e?.recursive??!1,r=i.splitPath(t);let s=this.root;for(let n=0;n<r.length;n++){const o=r[n];try{s=await s.getDirectoryHandle(o,{create:a||n===r.length-1})}catch(c){throw c.name==="NotFoundError"?new i.OPFSError(`Parent directory does not exist: ${i.joinPath(r.slice(0,n+1))}`,"ENOENT",void 0,c):c.name==="TypeMismatchError"?new i.OPFSError(`Path segment is not a directory: ${o}`,"ENOTDIR",void 0,c):new i.OPFSError("Failed to create directory","MKDIR_FAILED",void 0,c)}}await this.notifyChange({path:t,type:i.WatchEventType.Added,isDirectory:!0})}async stat(t){if(await this.mount(),t==="/")return{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0};const e=i.basename(t),a=await this.getDirectoryHandle(i.dirname(t),!1),r=this.options.hashAlgorithm;try{const n=await(await a.getFileHandle(e,{create:!1})).getFile(),o={kind:"file",size:n.size,mtime:new Date(n.lastModified).toISOString(),ctime:new Date(n.lastModified).toISOString(),isFile:!0,isDirectory:!1};if(r==="etag")o.hash=`${n.lastModified.toString(36)}-${n.size.toString(36)}`;else if(typeof r=="string")try{const c=await i.calculateFileHash(n,r,this.options.maxFileSize);o.hash=c}catch(c){console.warn(`Failed to calculate hash for ${t}:`,c)}return o}catch(s){if(s.name!=="TypeMismatchError"&&s.name!=="NotFoundError")throw new i.OPFSError("Failed to stat (file)","STAT_FAILED",void 0,s)}try{return await a.getDirectoryHandle(e,{create:!1}),{kind:"directory",size:0,mtime:new Date(0).toISOString(),ctime:new Date(0).toISOString(),isFile:!1,isDirectory:!0}}catch(s){throw s.name==="NotFoundError"?new i.OPFSError(`No such file or directory: ${t}`,"ENOENT",void 0,s):new i.OPFSError("Failed to stat (directory)","STAT_FAILED",void 0,s)}}async readDir(t){await this.mount();const e=await this.getDirectoryHandle(t,!1),a=[];for await(const[r,s]of e.entries()){const n=s.kind==="file";a.push({name:r,kind:s.kind,isFile:n,isDirectory:!n})}return a}async exists(t){if(await this.mount(),t==="/")return!0;const e=i.basename(t);let a=null;try{a=await this.getDirectoryHandle(i.dirname(t),!1)}catch(r){if(a=null,r.name!=="NotFoundError"&&r.name!=="TypeMismatchError")throw r}if(!a||!e)return!1;try{return await a.getFileHandle(e,{create:!1}),!0}catch(r){if(r.name!=="NotFoundError"&&r.name!=="TypeMismatchError")throw r;try{return await a.getDirectoryHandle(e,{create:!1}),!0}catch(s){if(s.name!=="NotFoundError"&&s.name!=="TypeMismatchError")throw s;return!1}}}async clear(t="/"){await this.mount();try{const e=await this.readDir(t);for(const a of e){const r=`${t==="/"?"":t}/${a.name}`;await this.remove(r,{recursive:!0})}await this.notifyChange({path:t,type:i.WatchEventType.Changed,isDirectory:!0})}catch(e){throw e instanceof i.OPFSError?e:new i.OPFSError(`Failed to clear directory: ${t}`,"CLEAR_FAILED",void 0,e)}}async remove(t,e){if(await this.mount(),t==="/")throw new i.OPFSError("Cannot remove root directory","EROOT");const{recursive:a=!1,force:r=!1}=e||{},s=await this.getDirectoryHandle(i.dirname(t),!1),n=await this.stat(t);await i.removeEntry(s,t,{recursive:a,force:r}),await this.notifyChange({path:t,type:i.WatchEventType.Removed,isDirectory:n.isDirectory})}async realpath(t){await this.mount();try{const e=i.resolvePath(t);if(!await this.exists(e))throw new i.FileNotFoundError(e);return e}catch(e){throw e instanceof i.OPFSError?e:new i.OPFSError(`Failed to resolve path: ${t}`,"REALPATH_FAILED",void 0,e)}}async rename(t,e,a){await this.mount();try{const r=a?.overwrite??!1,s=await this.stat(t);if(await this.exists(e)&&!r)throw new i.OPFSError(`Destination already exists: ${e}`,"EEXIST",void 0);await this.copy(t,e,{recursive:!0,overwrite:r}),await this.remove(t,{recursive:!0}),await this.notifyChange({path:t,type:i.WatchEventType.Removed,isDirectory:s.isDirectory}),await this.notifyChange({path:e,type:i.WatchEventType.Added,isDirectory:s.isDirectory})}catch(r){throw r instanceof i.OPFSError?r:new i.OPFSError(`Failed to rename from ${t} to ${e}`,"RENAME_FAILED",void 0,r)}}async copy(t,e,a){await this.mount();try{const r=a?.recursive??!1,s=a?.overwrite??!0;if(!await this.exists(t))throw new i.OPFSError(`Source does not exist: ${t}`,"ENOENT",void 0);if(await this.exists(e)&&!s)throw new i.OPFSError(`Destination already exists: ${e}`,"EEXIST",void 0);if((await this.stat(t)).isFile){const h=await this.readFile(t);await this.writeFile(e,h)}else{if(!r)throw new i.OPFSError(`Cannot copy directory without recursive option: ${t}`,"EISDIR",void 0);await this.mkdir(e,{recursive:!0});const h=await this.readDir(t);for(const l of h){const w=`${t}/${l.name}`,y=`${e}/${l.name}`;await this.copy(w,y,{recursive:!0,overwrite:s})}}}catch(r){throw r instanceof i.OPFSError?r:new i.OPFSError(`Failed to copy from ${t} to ${e}`,"CP_FAILED",void 0,r)}}async watch(t,e){if(!this.options.broadcastChannel)throw new i.OPFSError("This instance is not configured to send events. Please specify options.broadcastChannel to enable watching.","ENOENT");const a={pattern:i.normalizeMinimatch(t,e?.recursive??!0),include:Array.isArray(e?.include)?e.include:[e?.include??"**"],exclude:Array.isArray(e?.exclude)?e.exclude:[e?.exclude??""]};this.watchers.set(t,a)}unwatch(t){this.watchers.delete(t)}async open(t,e){await this.mount();const{create:a=!1,exclusive:r=!1,truncate:s=!1}=e||{},n=i.normalizePath(i.resolvePath(t));try{return a&&r?await i.withLock(n,"exclusive",async()=>{if(await this.exists(n))throw new i.OPFSError(`File already exists: ${n}`,"EEXIST",n);return this._openFile(n,a,s)}):await this._openFile(n,a,s)}catch(o){throw o instanceof i.OPFSError?o:new i.OPFSError(`Failed to open file: ${n}`,"OPEN_FAILED",n,o)}}async _openFile(t,e,a){const r=await this.getFileHandle(t,e);try{await r.getFile()}catch(o){throw o.name==="TypeMismatchError"?new i.OPFSError(`Is a directory: ${t}`,"EISDIR",t):o}const s=await i.createSyncHandleSafe(r,t);a&&(s.truncate(0),s.flush());const n=this.nextFd++;return this.openFiles.set(n,{path:t,fileHandle:r,syncHandle:s,position:0}),n}async close(t){const e=this._getFileDescriptor(t);i.safeCloseSyncHandle(t,e.syncHandle,e.path),this.openFiles.delete(t)}async read(t,e,a,r,s){const n=this._getFileDescriptor(t);i.validateReadWriteArgs(e.length,a,r,s);try{const o=s??n.position,c=n.syncHandle.getSize(),{isEOF:h,actualLength:l}=i.calculateReadLength(o,r,c);if(h)return d.transfer({bytesRead:0,buffer:e},[e.buffer]);const w=e.subarray(a,a+l),y=n.syncHandle.read(w,{at:o});return s==null&&(n.position=o+y),d.transfer({bytesRead:y,buffer:e},[e.buffer])}catch(o){throw i.createFDError("read",t,n.path,o)}}async write(t,e,a=0,r,s,n=!0){const o=this._getFileDescriptor(t),c=r??e.length-a;i.validateReadWriteArgs(e.length,a,c,s);try{const h=s??o.position,l=e.subarray(a,a+c),w=o.syncHandle.write(l,{at:h});return(s==null||s===o.position)&&(o.position=h+w),n&&await this.notifyChange({path:o.path,type:i.WatchEventType.Changed,isDirectory:!1}),w}catch(h){throw i.createFDError("write",t,o.path,h)}}async fstat(t){const e=this._getFileDescriptor(t);return this.stat(e.path)}async ftruncate(t,e=0){const a=this._getFileDescriptor(t);if(e<0||!Number.isInteger(e))throw new i.OPFSError("Invalid size","EINVAL");try{a.syncHandle.truncate(e),a.syncHandle.flush(),a.position>e&&(a.position=e),await this.notifyChange({path:a.path,type:i.WatchEventType.Changed,isDirectory:!1})}catch(r){throw i.createFDError("truncate",t,a.path,r)}}async fsync(t){const e=this._getFileDescriptor(t);try{e.syncHandle.flush()}catch(a){throw i.createFDError("sync",t,e.path,a)}}dispose(){this.broadcastChannel&&(this.broadcastChannel.close(),this.broadcastChannel=null),this.watchers.clear();for(const[t,e]of this.openFiles)i.safeCloseSyncHandle(t,e.syncHandle,e.path);this.openFiles.clear(),this.nextFd=1}async createIndex(t){await this.mount();try{for(const[e,a]of t){const r=i.normalizePath(e);let s;a instanceof Blob?s=await i.convertBlobToUint8Array(a):typeof a=="string"?s=new TextEncoder().encode(a):s=a,await this.writeFile(r,s)}}catch(e){throw e instanceof i.OPFSError?e:new i.OPFSError("Failed to sync file system","SYNC_FAILED",void 0,e)}}}typeof globalThis<"u"&&globalThis.constructor.name==="DedicatedWorkerGlobalScope"&&d.expose(new f);exports.OPFSWorker=f;
2
2
  //# sourceMappingURL=raw.cjs.map