opfs-worker 2.1.0 → 2.1.1

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.
Files changed (78) hide show
  1. package/README.md +40 -27
  2. package/dist/{BaseOPFS-Cylz6ijk.js → BaseOPFS-BusBkyJX.js} +436 -358
  3. package/dist/BaseOPFS-BusBkyJX.js.map +1 -0
  4. package/dist/{BaseOPFS-BPw9AIQ-.cjs → BaseOPFS-CYwrD7-q.cjs} +4 -4
  5. package/dist/BaseOPFS-CYwrD7-q.cjs.map +1 -0
  6. package/dist/{OPFSAsync-s2P7y3sw.cjs → OPFSAsync-B2dR-2VR.cjs} +2 -2
  7. package/dist/{OPFSAsync-s2P7y3sw.cjs.map → OPFSAsync-B2dR-2VR.cjs.map} +1 -1
  8. package/dist/{OPFSAsync-BKSAJJeh.js → OPFSAsync-CO44W23e.js} +2 -2
  9. package/dist/{OPFSAsync-BKSAJJeh.js.map → OPFSAsync-CO44W23e.js.map} +1 -1
  10. package/dist/OPFSFacade-CEaSqTut.js +308 -0
  11. package/dist/OPFSFacade-CEaSqTut.js.map +1 -0
  12. package/dist/OPFSFacade-hrNXCn6w.cjs +2 -0
  13. package/dist/OPFSFacade-hrNXCn6w.cjs.map +1 -0
  14. package/dist/{OPFSSync-C7KBepe_.cjs → OPFSSync-BPrNtvFS.cjs} +2 -2
  15. package/dist/{OPFSSync-C7KBepe_.cjs.map → OPFSSync-BPrNtvFS.cjs.map} +1 -1
  16. package/dist/{OPFSSync-CsSQkpk5.js → OPFSSync-D7obTsl3.js} +2 -2
  17. package/dist/{OPFSSync-CsSQkpk5.js.map → OPFSSync-D7obTsl3.js.map} +1 -1
  18. package/dist/assets/dedicated.worker-DW6UqFo0.js.map +1 -0
  19. package/dist/core/BaseOPFS.d.ts +38 -7
  20. package/dist/core/BaseOPFS.d.ts.map +1 -1
  21. package/dist/createOPFSAsync-DdhJYoC0.js +10 -0
  22. package/dist/{createOPFSAsync-Y4Mg6qte.js.map → createOPFSAsync-DdhJYoC0.js.map} +1 -1
  23. package/dist/createOPFSAsync-DyWpvmL-.cjs +2 -0
  24. package/dist/{createOPFSAsync-BwKDmHsy.cjs.map → createOPFSAsync-DyWpvmL-.cjs.map} +1 -1
  25. package/dist/{createOPFSDedicated-CsnV6MLP.js → createOPFSDedicated-BwTc0NV5.js} +289 -215
  26. package/dist/{createOPFSDedicated-CsnV6MLP.js.map → createOPFSDedicated-BwTc0NV5.js.map} +1 -1
  27. package/dist/{createOPFSDedicated-pKTRWLdz.cjs → createOPFSDedicated-CEeRexom.cjs} +286 -212
  28. package/dist/{createOPFSDedicated-pKTRWLdz.cjs.map → createOPFSDedicated-CEeRexom.cjs.map} +1 -1
  29. package/dist/{createOPFSShared-CGdd__PH.js → createOPFSShared-BSFWsoLe.js} +2 -2
  30. package/dist/{createOPFSShared-CGdd__PH.js.map → createOPFSShared-BSFWsoLe.js.map} +1 -1
  31. package/dist/{createOPFSShared-CskROt7U.cjs → createOPFSShared-BoCft_BS.cjs} +2 -2
  32. package/dist/{createOPFSShared-CskROt7U.cjs.map → createOPFSShared-BoCft_BS.cjs.map} +1 -1
  33. package/dist/dedicated.worker.js +282 -208
  34. package/dist/dedicated.worker.js.map +1 -1
  35. package/dist/facade/OPFSFacade.d.ts +21 -3
  36. package/dist/facade/OPFSFacade.d.ts.map +1 -1
  37. package/dist/index.async.cjs +1 -1
  38. package/dist/index.async.js +4 -4
  39. package/dist/index.cjs +1 -1
  40. package/dist/index.js +7 -7
  41. package/dist/index.pure.cjs +1 -1
  42. package/dist/index.pure.js +3 -3
  43. package/dist/index.sharedworker.cjs +1 -1
  44. package/dist/index.sharedworker.js +4 -4
  45. package/dist/index.sync.cjs +1 -1
  46. package/dist/index.sync.js +4 -4
  47. package/dist/shared.worker.js +430 -356
  48. package/dist/shared.worker.js.map +1 -1
  49. package/dist/types.d.ts +33 -0
  50. package/dist/types.d.ts.map +1 -1
  51. package/docs/api/backend.md +3 -3
  52. package/docs/api/create.md +1 -1
  53. package/docs/api/facade.md +28 -27
  54. package/docs/choosing-a-mode.md +6 -6
  55. package/docs/file-descriptors.md +46 -604
  56. package/docs/guides/async.md +2 -2
  57. package/docs/guides/dedicated.md +5 -5
  58. package/docs/guides/hashing.md +2 -2
  59. package/docs/guides/pure.md +3 -3
  60. package/docs/guides/sharedworker.md +1 -1
  61. package/docs/guides/streaming.md +145 -11
  62. package/docs/guides/watching.md +3 -3
  63. package/docs/migration.md +3 -3
  64. package/docs/types.md +92 -154
  65. package/package.json +12 -2
  66. package/src/core/BaseOPFS.ts +148 -25
  67. package/src/facade/OPFSFacade.ts +51 -4
  68. package/src/types.ts +37 -0
  69. package/dist/BaseOPFS-BPw9AIQ-.cjs.map +0 -1
  70. package/dist/BaseOPFS-Cylz6ijk.js.map +0 -1
  71. package/dist/OPFSFacade-DePnNRgt.cjs +0 -2
  72. package/dist/OPFSFacade-DePnNRgt.cjs.map +0 -1
  73. package/dist/OPFSFacade-XohWlHuu.js +0 -281
  74. package/dist/OPFSFacade-XohWlHuu.js.map +0 -1
  75. package/dist/assets/dedicated.worker-nY3tK4zi.js.map +0 -1
  76. package/dist/createOPFSAsync-BwKDmHsy.cjs +0 -2
  77. package/dist/createOPFSAsync-Y4Mg6qte.js +0 -10
  78. package/docs/README.md +0 -30
@@ -1,281 +0,0 @@
1
- import { transfer as l, proxy as d } from "comlink";
2
- import { L as u, N as f, M as h } from "./BaseOPFS-Cylz6ijk.js";
3
- function a(o) {
4
- return o instanceof URL ? o.pathname : o;
5
- }
6
- class w {
7
- #t;
8
- #r;
9
- /** Raw backend (`OPFSApi`) — bytes in / bytes out, no encoding helpers */
10
- backend;
11
- /** Dedicated Worker or SharedWorker, if this facade was created with one */
12
- worker;
13
- promises = this;
14
- constructor(t) {
15
- this.#t = t.fs, this.backend = t.fs, this.worker = t.worker, this.#r = t.dispose;
16
- }
17
- /**
18
- * Start watching a file or directory for changes
19
- */
20
- watch(t, r) {
21
- const e = a(t);
22
- return this.#t.watch(e, r), () => this.unwatch(e);
23
- }
24
- /**
25
- * Stop watching a previously watched path
26
- */
27
- unwatch(t) {
28
- const r = a(t);
29
- this.#t.unwatch(r);
30
- }
31
- /**
32
- * Update configuration options
33
- */
34
- async setOptions(t) {
35
- return this.#t.setOptions(t);
36
- }
37
- /**
38
- * Get a complete index of all files and directories in the file system
39
- */
40
- async index() {
41
- return this.#t.index();
42
- }
43
- // Implementation
44
- async readFile(t, r) {
45
- const e = a(t);
46
- let n;
47
- typeof r == "string" ? n = r : r && typeof r == "object" && (n = r.encoding);
48
- const s = await this.#t.readFile(e);
49
- return n || (n = u(e) ? "binary" : "utf-8"), n === "binary" ? s : f(s, n);
50
- }
51
- /**
52
- * Normalize writable data into a Uint8Array.
53
- *
54
- * Accepts strings (encoded via `encoding`, auto-detected from the file
55
- * extension when omitted), raw binary (`Uint8Array` / `ArrayBuffer`), and
56
- * `Blob`/`File` sources (read via `arrayBuffer()`).
57
- */
58
- async #e(t, r, e) {
59
- return r instanceof Blob ? new Uint8Array(await r.arrayBuffer()) : (e || (e = typeof r != "string" || u(t) ? "binary" : "utf-8"), typeof r == "string" ? h(r, e) : r instanceof Uint8Array ? r : new Uint8Array(r));
60
- }
61
- /**
62
- * Write data to a file
63
- */
64
- async writeFile(t, r, e) {
65
- const n = a(t);
66
- let s;
67
- typeof e == "string" ? s = e : e && typeof e == "object" && (s = e.encoding);
68
- const i = await this.#e(n, r, s);
69
- return this.#t.writeFile(n, i);
70
- }
71
- /**
72
- * Append data to a file
73
- */
74
- async appendFile(t, r, e) {
75
- const n = a(t), s = await this.#e(n, r, e);
76
- return this.#t.appendFile(n, s);
77
- }
78
- /**
79
- * Create or overwrite a file from a byte stream without buffering the
80
- * complete source in memory.
81
- *
82
- * Returns the total number of bytes written.
83
- */
84
- async importStream(t, r, e) {
85
- const n = a(t), s = r instanceof Blob ? r.stream() : r, i = l(s, [s]), c = e?.onProgress ? d((y) => e.onProgress(y)) : void 0;
86
- return this.#t.writeStream(n, i, c);
87
- }
88
- /**
89
- * Create a directory
90
- */
91
- async mkdir(t, r) {
92
- const e = a(t);
93
- let n;
94
- return typeof r == "number" ? n = { recursive: !1 } : n = r, this.#t.mkdir(e, n);
95
- }
96
- /**
97
- * Get file or directory statistics
98
- */
99
- async stat(t) {
100
- const r = a(t);
101
- return this.#t.stat(r);
102
- }
103
- /**
104
- * Read a directory's contents
105
- */
106
- async readDir(t) {
107
- const r = a(t);
108
- return this.#t.readDir(r);
109
- }
110
- /**
111
- * Check if a file or directory exists
112
- */
113
- async exists(t) {
114
- const r = a(t);
115
- return this.#t.exists(r);
116
- }
117
- /**
118
- * Clear all contents of a directory without removing the directory itself
119
- */
120
- async clear(t) {
121
- const r = t ? a(t) : void 0;
122
- return this.#t.clear(r);
123
- }
124
- /**
125
- * Remove files and directories
126
- */
127
- async remove(t, r) {
128
- const e = a(t);
129
- return this.#t.remove(e, r);
130
- }
131
- /**
132
- * Alias for remove() for NodeJS like API compatibility
133
- */
134
- async unlink(t) {
135
- return this.remove(t);
136
- }
137
- /**
138
- * Alias for remove() for NodeJS like API compatibility
139
- */
140
- async rm(t, r) {
141
- return this.remove(t, r);
142
- }
143
- /**
144
- * Alias for remove() for NodeJS like API compatibility
145
- */
146
- async rmdir(t) {
147
- return this.remove(t);
148
- }
149
- /**
150
- * Alias for readDir() for NodeJS like API compatibility
151
- */
152
- async readdir(t, r) {
153
- return this.readDir(t);
154
- }
155
- /**
156
- * Alias for stat() for NodeJS like API compatibility
157
- */
158
- async lstat(t) {
159
- return this.stat(t);
160
- }
161
- /**
162
- * Note: OPFS doesn't support file modes, so this is a no-op and exists only for compatibility with tools like isomorphic-git
163
- */
164
- async chmod(t, r) {
165
- return Promise.resolve();
166
- }
167
- /**
168
- * Resolve a path to an absolute path
169
- */
170
- async realpath(t) {
171
- const r = a(t);
172
- return this.#t.realpath(r);
173
- }
174
- /**
175
- * Rename a file or directory
176
- */
177
- async rename(t, r, e) {
178
- const n = a(t), s = a(r);
179
- return this.#t.rename(n, s, e);
180
- }
181
- /**
182
- * Copy files and directories
183
- */
184
- async copy(t, r, e) {
185
- const n = a(t), s = a(r);
186
- return this.#t.copy(n, s, e);
187
- }
188
- /**
189
- * Open a file and return a file descriptor
190
- */
191
- async open(t, r) {
192
- const e = a(t);
193
- return this.#t.open(e, r);
194
- }
195
- /**
196
- * Close a file descriptor
197
- */
198
- async close(t) {
199
- return this.#t.close(t);
200
- }
201
- /**
202
- * Read data from a file descriptor
203
- *
204
- * This method requires special handling due to Comlink transfer requirements.
205
- * The buffer is transferred to the worker and back, so the original buffer
206
- * becomes unusable after the call.
207
- */
208
- async read(t, r, e, n, s) {
209
- const { bytesRead: i, buffer: c } = await this.#t.read(
210
- t,
211
- // Temp buffer to preserve the original buffer
212
- new Uint8Array(n),
213
- 0,
214
- n,
215
- s
216
- );
217
- return i > 0 && r.set(c.subarray(0, i), e), { bytesRead: i, buffer: r };
218
- }
219
- /**
220
- * Write data to a file descriptor
221
- */
222
- async write(t, r, e, n, s, i) {
223
- return this.#t.write(t, r, e, n, s, i);
224
- }
225
- /**
226
- * Get file status information by file descriptor
227
- */
228
- async fstat(t) {
229
- return this.#t.fstat(t);
230
- }
231
- /**
232
- * Truncate file to specified size
233
- */
234
- async ftruncate(t, r) {
235
- return this.#t.ftruncate(t, r);
236
- }
237
- /**
238
- * Synchronize file data to storage (fsync equivalent)
239
- */
240
- async fsync(t) {
241
- return this.#t.fsync(t);
242
- }
243
- /**
244
- * Synchronize the file system with external data
245
- */
246
- async createIndex(t) {
247
- const r = t.map(([e, n]) => [a(e), n]);
248
- return this.#t.createIndex(r);
249
- }
250
- /**
251
- * Read a file as text with automatic encoding detection
252
- */
253
- async readText(t, r = "utf-8") {
254
- const e = a(t), n = await this.#t.readFile(e);
255
- return f(n, r);
256
- }
257
- /**
258
- * Write text to a file with specified encoding
259
- */
260
- async writeText(t, r, e = "utf-8") {
261
- const n = a(t), s = h(r, e);
262
- return this.#t.writeFile(n, s);
263
- }
264
- /**
265
- * Append text to a file with specified encoding
266
- */
267
- async appendText(t, r, e = "utf-8") {
268
- const n = a(t), s = h(r, e);
269
- return this.#t.appendFile(n, s);
270
- }
271
- /**
272
- * Dispose of resources, detach the backend and clean up the file system instance
273
- */
274
- dispose() {
275
- this.#r();
276
- }
277
- }
278
- export {
279
- w as O
280
- };
281
- //# sourceMappingURL=OPFSFacade-XohWlHuu.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"OPFSFacade-XohWlHuu.js","sources":["../src/facade/OPFSFacade.ts"],"sourcesContent":["import { proxy, transfer } from 'comlink';\n\nimport { decodeBuffer, encodeString, isBinaryFileExtension } from '../utils/encoder';\n\nimport type {\n BinaryEncoding,\n DirentData,\n Encoding,\n FileOpenOptions,\n FileStat,\n OPFSApi,\n OPFSOptions,\n PathLike,\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/** Backend the facade talks to: an fs implementation plus its cleanup. */\nexport interface OPFSBackend {\n fs: OPFSApi;\n /** Underlying Worker / SharedWorker when the backend lives off-thread */\n worker?: Worker | SharedWorker;\n dispose: () => void;\n}\n\n/**\n * Node-like facade with encoding helpers and string/binary auto-detection.\n *\n * Transport-agnostic: works over any {@link OPFSBackend} — a Comlink proxy to\n * a worker (`createOPFSDedicated`) or an in-process instance (`createOPFSAsync`).\n *\n * Escape hatch: {@link backend} is the raw bytes API; {@link worker} is the\n * browser Worker / SharedWorker when one was created (undefined for async).\n */\nexport class OPFSFacade {\n #fs: OPFSApi;\n #dispose: () => void;\n /** Raw backend (`OPFSApi`) — bytes in / bytes out, no encoding helpers */\n readonly backend: OPFSApi;\n /** Dedicated Worker or SharedWorker, if this facade was created with one */\n readonly worker: Worker | SharedWorker | undefined;\n promises: OPFSFacade = this;\n\n constructor(backend: OPFSBackend) {\n this.#fs = backend.fs;\n this.backend = backend.fs;\n this.worker = backend.worker;\n this.#dispose = backend.dispose;\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.#fs.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.#fs.unwatch(normalizedPath);\n }\n\n /**\n * Update configuration options\n */\n async setOptions(options: OPFSOptions) {\n return this.#fs.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.#fs.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 // Same-path reads are serialized by the worker's exclusive path lock\n const buffer = await this.#fs.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 (encoding === 'binary') ? buffer : decodeBuffer(buffer, encoding);\n }\n\n /**\n * Normalize writable data into a Uint8Array.\n *\n * Accepts strings (encoded via `encoding`, auto-detected from the file\n * extension when omitted), raw binary (`Uint8Array` / `ArrayBuffer`), and\n * `Blob`/`File` sources (read via `arrayBuffer()`).\n */\n async #toBuffer(\n path: string,\n data: string | Uint8Array | ArrayBuffer | Blob,\n encoding?: Encoding\n ): Promise<Uint8Array> {\n if (data instanceof Blob) {\n return new Uint8Array(await data.arrayBuffer());\n }\n\n // If no encoding specified, auto-detect based on file extension\n if (!encoding) {\n encoding = (typeof data !== 'string' || isBinaryFileExtension(path)) ? 'binary' : 'utf-8';\n }\n\n if (typeof data === 'string') {\n return encodeString(data, encoding);\n }\n\n return data instanceof Uint8Array ? data : new Uint8Array(data);\n }\n\n /**\n * Write data to a file\n */\n async writeFile(\n path: PathLike,\n data: string | Uint8Array | ArrayBuffer | Blob,\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 const buffer = await this.#toBuffer(normalizedPath, data, encoding);\n\n return this.#fs.writeFile(normalizedPath, buffer);\n }\n\n /**\n * Append data to a file\n */\n async appendFile(\n path: PathLike,\n data: string | Uint8Array | ArrayBuffer | Blob,\n encoding?: Encoding\n ): Promise<void> {\n const normalizedPath = normalizePath(path);\n\n const buffer = await this.#toBuffer(normalizedPath, data, encoding);\n\n return this.#fs.appendFile(normalizedPath, buffer);\n }\n\n /**\n * Create or overwrite a file from a byte stream without buffering the\n * complete source in memory.\n *\n * Returns the total number of bytes written.\n */\n async importStream(\n path: PathLike,\n source: ReadableStream<Uint8Array> | Blob,\n options?: { onProgress?: (bytesWritten: number) => void }\n ): Promise<number> {\n const normalizedPath = normalizePath(path);\n const stream = source instanceof Blob ? source.stream() : source;\n const transferredStream = transfer(stream, [stream]) as unknown as ReadableStream<Uint8Array>;\n const onProgress = options?.onProgress\n ? proxy((bytesWritten: number) => options.onProgress!(bytesWritten))\n : undefined;\n\n return this.#fs.writeStream(normalizedPath, transferredStream, onProgress);\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.#fs.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.#fs.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.#fs.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.#fs.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.#fs.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.#fs.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.#fs.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.#fs.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.#fs.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.#fs.open(normalizedPath, options);\n }\n\n /**\n * Close a file descriptor\n */\n async close(fd: number): Promise<void> {\n return this.#fs.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.#fs.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.#fs.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.#fs.fstat(fd);\n }\n\n /**\n * Truncate file to specified size\n */\n async ftruncate(fd: number, size?: number): Promise<void> {\n return this.#fs.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.#fs.fsync(fd);\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.#fs.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.#fs.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.#fs.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.#fs.appendFile(normalizedPath, buffer);\n }\n\n /**\n * Dispose of resources, detach the backend and clean up the file system instance\n */\n dispose() {\n this.#dispose();\n }\n}\n"],"names":["normalizePath","path","OPFSFacade","#fs","#dispose","backend","options","normalizedPath","optionsOrEncoding","encoding","buffer","isBinaryFileExtension","decodeBuffer","#toBuffer","data","encodeString","source","stream","transferredStream","transfer","onProgress","proxy","bytesWritten","mode","_options","_path","_mode","oldPath","newPath","normalizedOldPath","normalizedNewPath","destination","normalizedSource","normalizedDestination","fd","offset","length","position","bytesRead","transferred","emitEvent","size","entries","normalizedEntries","text"],"mappings":";;AAsBA,SAASA,EAAcC,GAAwB;AAC3C,SAAIA,aAAgB,MACTA,EAAK,WAGTA;AACX;AAmBO,MAAMC,EAAW;AAAA,EACpBC;AAAA,EACAC;AAAA;AAAA,EAES;AAAA;AAAA,EAEA;AAAA,EACT,WAAuB;AAAA,EAEvB,YAAYC,GAAsB;AAC9B,SAAKF,KAAME,EAAQ,IACnB,KAAK,UAAUA,EAAQ,IACvB,KAAK,SAASA,EAAQ,QACtB,KAAKD,KAAWC,EAAQ;AAAA,EAC5B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAMJ,GAAgBK,GAAoC;AACtD,UAAMC,IAAiBP,EAAcC,CAAI;AAEzC,WAAK,KAAKE,GAAI,MAAMI,GAAgBD,CAAO,GAEpC,MAAM,KAAK,QAAQC,CAAc;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQN,GAAgB;AACpB,UAAMM,IAAiBP,EAAcC,CAAI;AAEzC,IAAK,KAAKE,GAAI,QAAQI,CAAc;AAAA,EACxC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,WAAWD,GAAsB;AACnC,WAAO,KAAKH,GAAI,WAAWG,CAAO;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAwC;AAC1C,WAAO,KAAKH,GAAI,MAAA;AAAA,EACpB;AAAA;AAAA,EAgBA,MAAM,SACFF,GACAO,GAC4B;AAC5B,UAAMD,IAAiBP,EAAcC,CAAI;AAGzC,QAAIQ;AAEJ,IAAI,OAAOD,KAAsB,WAC7BC,IAAWD,IAENA,KAA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