opfs-worker 0.2.6 → 0.3.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.
- package/README.md +117 -47
- package/dist/assets/worker-DilNsKoO.js.map +1 -0
- package/dist/helpers-B87wz5kv.cjs +2 -0
- package/dist/helpers-B87wz5kv.cjs.map +1 -0
- package/dist/{helpers-C0nyU6hv.js → helpers-DxFcNkZe.js} +51 -51
- package/dist/helpers-DxFcNkZe.js.map +1 -0
- package/dist/index.cjs +255 -234
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +284 -266
- package/dist/index.js.map +1 -1
- package/dist/raw.cjs +1 -1
- package/dist/raw.cjs.map +1 -1
- package/dist/raw.js +143 -122
- package/dist/raw.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/helpers.d.ts +9 -0
- package/dist/utils/helpers.d.ts.map +1 -1
- package/dist/worker.d.ts +16 -27
- package/dist/worker.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/assets/worker-CHy3JxL1.js.map +0 -1
- package/dist/helpers-C0nyU6hv.js.map +0 -1
- package/dist/helpers-FvdHLObV.cjs +0 -2
- package/dist/helpers-FvdHLObV.cjs.map +0 -1
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
class
|
|
1
|
+
class s extends Error {
|
|
2
2
|
constructor(r, t, n) {
|
|
3
3
|
super(r), this.code = t, this.path = n, this.name = "OPFSError";
|
|
4
4
|
}
|
|
5
5
|
}
|
|
6
|
-
class l extends
|
|
6
|
+
class l extends s {
|
|
7
7
|
constructor() {
|
|
8
8
|
super("OPFS is not supported in this browser", "OPFS_NOT_SUPPORTED");
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
class
|
|
11
|
+
class p extends s {
|
|
12
12
|
constructor() {
|
|
13
13
|
super("OPFS is not mounted", "OPFS_NOT_MOUNTED");
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
class
|
|
16
|
+
class S extends s {
|
|
17
17
|
constructor(r, t) {
|
|
18
18
|
super(r, "INVALID_PATH", t);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
class
|
|
21
|
+
class E extends s {
|
|
22
22
|
constructor(r) {
|
|
23
23
|
super(`File not found: ${r}`, "FILE_NOT_FOUND", r);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
class
|
|
26
|
+
class O extends s {
|
|
27
27
|
constructor(r) {
|
|
28
28
|
super(`Directory not found: ${r}`, "DIRECTORY_NOT_FOUND", r);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
class
|
|
31
|
+
class F extends s {
|
|
32
32
|
constructor(r, t) {
|
|
33
33
|
super(`Permission denied for ${t} on: ${r}`, "PERMISSION_DENIED", r);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
class
|
|
36
|
+
class U extends s {
|
|
37
37
|
constructor(r, t) {
|
|
38
38
|
super(r, "STORAGE_ERROR", t);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
class
|
|
41
|
+
class P extends s {
|
|
42
42
|
constructor(r, t) {
|
|
43
43
|
super(`Operation timed out: ${r}`, "TIMEOUT_ERROR", t);
|
|
44
44
|
}
|
|
@@ -62,7 +62,7 @@ function f(e, r = "utf-8") {
|
|
|
62
62
|
return Uint8Array.from(atob(e), (t) => t.charCodeAt(0));
|
|
63
63
|
case "hex":
|
|
64
64
|
if (!/^[\da-f]+$/i.test(e) || e.length % 2 !== 0)
|
|
65
|
-
throw new
|
|
65
|
+
throw new s("Invalid hex string", "INVALID_HEX_FORMAT");
|
|
66
66
|
return Uint8Array.from(e.match(/.{1,2}/g).map((t) => parseInt(t, 16)));
|
|
67
67
|
default:
|
|
68
68
|
return console.warn("Encoding not supported, falling back to UTF-8"), new TextEncoder().encode(e);
|
|
@@ -121,39 +121,39 @@ function x() {
|
|
|
121
121
|
throw new l();
|
|
122
122
|
}
|
|
123
123
|
function i(e) {
|
|
124
|
-
return Array.isArray(e) ? e : e.split("/").filter(Boolean);
|
|
124
|
+
return Array.isArray(e) ? e : (e.startsWith("~/") ? e.slice(2) : e).split("/").filter(Boolean);
|
|
125
125
|
}
|
|
126
126
|
function u(e) {
|
|
127
127
|
return typeof e == "string" ? e ?? "/" : `/${e.join("/")}`;
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function w(e) {
|
|
130
130
|
const r = i(e);
|
|
131
131
|
return r[r.length - 1] || "";
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function D(e) {
|
|
134
134
|
const r = i(e);
|
|
135
135
|
return r.pop(), u(r);
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
return !e || e === "/" ? "/" : e.startsWith("/") ? e : `/${e}`;
|
|
137
|
+
function m(e) {
|
|
138
|
+
return !e || e === "/" ? "/" : e.startsWith("~/") ? `/${e.slice(2)}` : e.startsWith("/") ? e : `/${e}`;
|
|
139
139
|
}
|
|
140
140
|
function C(e) {
|
|
141
|
-
const r =
|
|
142
|
-
for (const
|
|
143
|
-
if (!(
|
|
144
|
-
if (
|
|
145
|
-
if (
|
|
141
|
+
const r = m(e), t = i(r), n = [];
|
|
142
|
+
for (const o of t)
|
|
143
|
+
if (!(o === "." || o === ""))
|
|
144
|
+
if (o === "..") {
|
|
145
|
+
if (n.length === 0)
|
|
146
146
|
continue;
|
|
147
|
-
|
|
147
|
+
n.pop();
|
|
148
148
|
} else
|
|
149
|
-
|
|
150
|
-
return u(
|
|
149
|
+
n.push(o);
|
|
150
|
+
return u(n);
|
|
151
151
|
}
|
|
152
152
|
function I(e) {
|
|
153
|
-
const r =
|
|
153
|
+
const r = w(e), t = r.lastIndexOf(".");
|
|
154
154
|
return t <= 0 || t === r.length - 1 ? "" : r.slice(t);
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function A(e, r = "utf-8") {
|
|
157
157
|
return typeof e == "string" ? f(e, r) : e instanceof Uint8Array ? e : new Uint8Array(e);
|
|
158
158
|
}
|
|
159
159
|
async function N(e) {
|
|
@@ -166,57 +166,57 @@ async function N(e) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
async function _(e, r, t, n = {}) {
|
|
169
|
-
let
|
|
169
|
+
let o = null;
|
|
170
170
|
try {
|
|
171
|
-
|
|
172
|
-
const a =
|
|
173
|
-
|
|
171
|
+
o = await e.createSyncAccessHandle();
|
|
172
|
+
const a = A(r, t), c = n.append ? o.getSize() : 0;
|
|
173
|
+
o.write(a, { at: c }), n.truncate && !n.append && o.truncate(a.byteLength), o.flush();
|
|
174
174
|
} catch (a) {
|
|
175
175
|
console.error(a);
|
|
176
176
|
const c = n.append ? "append" : "write";
|
|
177
|
-
throw new
|
|
177
|
+
throw new s(`Failed to ${c} file`, `${c.toUpperCase()}_FAILED`);
|
|
178
178
|
} finally {
|
|
179
|
-
if (
|
|
179
|
+
if (o)
|
|
180
180
|
try {
|
|
181
|
-
|
|
181
|
+
o.close();
|
|
182
182
|
} catch {
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
async function
|
|
186
|
+
async function $(e, r = "SHA-1", t = 50 * 1024 * 1024) {
|
|
187
187
|
if (e instanceof File && (e = await e.arrayBuffer()), e.byteLength > t)
|
|
188
188
|
throw new Error(`File size ${e.byteLength} bytes exceeds maximum allowed size ${t} bytes`);
|
|
189
|
-
const n = new Uint8Array(e),
|
|
190
|
-
return Array.from(new Uint8Array(
|
|
189
|
+
const n = new Uint8Array(e), o = await crypto.subtle.digest(r, n);
|
|
190
|
+
return Array.from(new Uint8Array(o)).map((c) => c.toString(16).padStart(2, "0")).join("");
|
|
191
191
|
}
|
|
192
|
-
async function
|
|
192
|
+
async function L(e) {
|
|
193
193
|
const r = await e.arrayBuffer();
|
|
194
194
|
return new Uint8Array(r);
|
|
195
195
|
}
|
|
196
196
|
export {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
197
|
+
O as D,
|
|
198
|
+
E as F,
|
|
199
|
+
s as O,
|
|
200
|
+
S as P,
|
|
201
|
+
U as S,
|
|
202
|
+
P as T,
|
|
203
203
|
l as a,
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
p as b,
|
|
205
|
+
F as c,
|
|
206
206
|
x as d,
|
|
207
|
-
|
|
208
|
-
|
|
207
|
+
w as e,
|
|
208
|
+
D as f,
|
|
209
209
|
I as g,
|
|
210
|
-
|
|
210
|
+
A as h,
|
|
211
211
|
N as i,
|
|
212
212
|
u as j,
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
$ as k,
|
|
214
|
+
L as l,
|
|
215
215
|
f as m,
|
|
216
|
-
|
|
216
|
+
m as n,
|
|
217
217
|
T as o,
|
|
218
218
|
C as r,
|
|
219
219
|
i as s,
|
|
220
220
|
_ as w
|
|
221
221
|
};
|
|
222
|
-
//# sourceMappingURL=helpers-
|
|
222
|
+
//# sourceMappingURL=helpers-DxFcNkZe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers-DxFcNkZe.js","sources":["../src/utils/errors.ts","../src/utils/encoder.ts","../src/utils/helpers.ts"],"sourcesContent":["/**\n * Base error class for all OPFS-related errors\n */\nexport class OPFSError extends Error {\n constructor(message: string, public readonly code: string, public readonly path?: string) {\n super(message);\n this.name = 'OPFSError';\n }\n}\n\n/**\n * Error thrown when OPFS is not supported in the current browser\n */\nexport class OPFSNotSupportedError extends OPFSError {\n constructor() {\n super('OPFS is not supported in this browser', 'OPFS_NOT_SUPPORTED');\n }\n}\n\n\n/**\n * Error thrown when OPFS is not mounted\n */\nexport class OPFSNotMountedError extends OPFSError {\n constructor() {\n super('OPFS is not mounted', 'OPFS_NOT_MOUNTED');\n }\n}\n\n/**\n * Error thrown for invalid paths or path traversal attempts\n */\nexport class PathError extends OPFSError {\n constructor(message: string, path: string) {\n super(message, 'INVALID_PATH', path);\n }\n}\n\n/**\n * Error thrown when a requested file doesn't exist\n */\nexport class FileNotFoundError extends OPFSError {\n constructor(path: string) {\n super(`File not found: ${ path }`, 'FILE_NOT_FOUND', path);\n }\n}\n\n/**\n * Error thrown when a requested directory doesn't exist\n */\nexport class DirectoryNotFoundError extends OPFSError {\n constructor(path: string) {\n super(`Directory not found: ${ path }`, 'DIRECTORY_NOT_FOUND', path);\n }\n}\n\n/**\n * Error thrown when permission is denied for an operation\n */\nexport class PermissionError extends OPFSError {\n constructor(path: string, operation: string) {\n super(`Permission denied for ${ operation } on: ${ path }`, 'PERMISSION_DENIED', path);\n }\n}\n\n/**\n * Error thrown when an operation fails due to insufficient storage\n */\nexport class StorageError extends OPFSError {\n constructor(message: string, path?: string) {\n super(message, 'STORAGE_ERROR', path);\n }\n}\n\n/**\n * Error thrown when an operation times out\n */\nexport class TimeoutError extends OPFSError {\n constructor(operation: string, path?: string) {\n super(`Operation timed out: ${ operation }`, 'TIMEOUT_ERROR', path);\n }\n}\n","import { OPFSError } from './errors';\n\nimport type { BufferEncoding } from 'typescript';\n\nexport function encodeString(data: string, encoding: BufferEncoding = 'utf-8'): Uint8Array {\n switch (encoding) {\n case 'utf8':\n case 'utf-8':\n return new TextEncoder().encode(data);\n\n case 'utf16le':\n case 'ucs2':\n case 'ucs-2':\n return encodeUtf16LE(data);\n\n case 'ascii':\n return encodeAscii(data);\n\n case 'latin1':\n return encodeLatin1(data);\n\n case 'binary':\n return Uint8Array.from(data, char => char.charCodeAt(0));\n\n case 'base64':\n return Uint8Array.from(atob(data), c => c.charCodeAt(0));\n\n case 'hex':\n if (!/^[\\da-f]+$/i.test(data) || data.length % 2 !== 0) {\n throw new OPFSError('Invalid hex string', 'INVALID_HEX_FORMAT');\n }\n\n return Uint8Array.from(data.match(/.{1,2}/g)!.map(b => parseInt(b, 16)));\n\n default:\n console.warn('Encoding not supported, falling back to UTF-8');\n\n return new TextEncoder().encode(data);\n }\n}\n\nexport function decodeBuffer(buffer: Uint8Array, encoding: BufferEncoding = 'utf-8'): string {\n switch (encoding) {\n case 'utf8':\n case 'utf-8':\n return new TextDecoder().decode(buffer);\n\n case 'utf16le':\n case 'ucs2':\n case 'ucs-2':\n return decodeUtf16LE(buffer);\n\n case 'latin1':\n return String.fromCharCode(...buffer);\n\n case 'binary':\n return String.fromCharCode(...buffer);\n\n case 'ascii':\n return String.fromCharCode(...buffer.map(b => b & 0x7F));\n\n case 'base64':\n return btoa(String.fromCharCode(...buffer));\n\n case 'hex':\n return Array.from(buffer).map(b => b.toString(16).padStart(2, '0')).join('');\n\n default:\n console.warn('Unsupported encoding, falling back to UTF-8');\n\n return new TextDecoder().decode(buffer);\n }\n}\n\nfunction encodeUtf16LE(str: string): Uint8Array {\n const buf = new Uint8Array(str.length * 2);\n\n for (let i = 0; i < str.length; i++) {\n const code = str.charCodeAt(i);\n\n buf[(i * 2)] = code & 0xFF;\n buf[(i * 2) + 1] = code >> 8;\n }\n\n return buf;\n}\n\nfunction decodeUtf16LE(buf: Uint8Array): string {\n if (buf.length % 2 !== 0) {\n console.warn('Invalid UTF-16LE buffer length, truncating last byte');\n buf = buf.slice(0, buf.length - 1);\n }\n\n const codeUnits = new Uint16Array(buf.buffer, buf.byteOffset, buf.byteLength / 2);\n\n return String.fromCharCode(...codeUnits);\n}\n\nfunction encodeLatin1(str: string): Uint8Array {\n const buf = new Uint8Array(str.length);\n\n for (let i = 0; i < str.length; i++) {\n buf[i] = str.charCodeAt(i) & 0xFF;\n }\n\n return buf;\n}\n\nfunction encodeAscii(str: string): Uint8Array {\n const buf = new Uint8Array(str.length);\n\n for (let i = 0; i < str.length; i++) {\n buf[i] = str.charCodeAt(i) & 0x7F;\n }\n\n return buf;\n}\n","import { encodeString } from './encoder';\nimport { OPFSError, OPFSNotSupportedError } from './errors';\n\nimport type { BufferEncoding } from 'typescript';\n\n/**\n * Check if the browser supports the OPFS API\n * \n * @throws {OPFSNotSupportedError} If the browser does not support the OPFS API\n */\nexport function checkOPFSSupport(): void {\n if (!('storage' in navigator) || !('getDirectory' in (navigator.storage as any))) {\n throw new OPFSNotSupportedError();\n }\n}\n\n/** \n * Split a path into an array of segments\n * \n * @param path - The path to split\n * @returns The array of segments\n * \n * @example\n * ```typescript\n * splitPath('/path/to/file'); // ['path', 'to', 'file']\n * splitPath('~/path/to/file'); // ['path', 'to', 'file'] (home dir handled)\n * splitPath('relative/path'); // ['relative', 'path']\n * ```\n */\nexport function splitPath(path: string | string[]): string[] {\n if (Array.isArray(path)) {\n return path;\n }\n\n const normalizedPath = path.startsWith('~/') ? path.slice(2) : path;\n\n return normalizedPath.split('/').filter(Boolean);\n}\n\n\n/**\n * Join an array of path segments into a single path\n * \n * @param segments - The array of path segments\n * @returns The joined path\n */\nexport function joinPath(segments: string[] | string): string {\n return typeof segments === 'string'\n ? (segments ?? '/')\n : `/${ segments.join('/') }`;\n}\n\n/**\n * Extract the filename from a path\n * \n * @param path - The file path\n * @returns The filename without the directory path\n * \n * @example\n * ```typescript\n * basename('/path/to/file.txt'); // 'file.txt'\n * basename('/path/to/directory/'); // ''\n * basename('file.txt'); // 'file.txt'\n * ```\n */\nexport function basename(path: string): string {\n const segments = splitPath(path);\n return segments[segments.length - 1] || '';\n}\n\n/**\n * Extract the directory path from a file path\n * \n * @param path - The file path\n * @returns The directory path without the filename\n * \n * @example\n * ```typescript\n * dirname('/path/to/file.txt'); // '/path/to'\n * dirname('/path/to/directory/'); // '/path/to/directory'\n * dirname('file.txt'); // '/'\n * ```\n */\nexport function dirname(path: string): string {\n const segments = splitPath(path);\n segments.pop();\n return joinPath(segments);\n}\n\n/**\n * Normalize a path to ensure it starts with '/'\n * \n * @param path - The path to normalize\n * @returns The normalized path\n * \n * @example\n * ```typescript\n * normalizePath('path/to/file'); // '/path/to/file'\n * normalizePath('/path/to/file'); // '/path/to/file'\n * normalizePath('~/path/to/file'); // '/path/to/file' (home dir normalized to root)\n * normalizePath(''); // '/'\n * ```\n */\nexport function normalizePath(path: string): string {\n if (!path || path === '/') {\n return '/';\n }\n \n if (path.startsWith('~/')) {\n return `/${path.slice(2)}`;\n }\n \n return path.startsWith('/') ? path : `/${path}`;\n}\n\n/**\n * Resolve a path to an absolute path, handling relative segments\n * \n * @param path - The path to resolve\n * @returns The resolved absolute path\n * \n * @example\n * ```typescript\n * resolvePath('./config/../data/file.txt'); // '/data/file.txt'\n * resolvePath('/path/to/../file.txt'); // '/path/file.txt'\n * resolvePath('../../file.txt'); // '/file.txt' (truncated to root)\n * resolvePath('~/config/../data/file.txt'); // '/data/file.txt' (home dir normalized to root)\n * ```\n */\nexport function resolvePath(path: string): string {\n // First normalize the path to handle home directory references\n const normalizedPath = normalizePath(path);\n const segments = splitPath(normalizedPath);\n const normalizedSegments: string[] = [];\n\n for (const segment of segments) {\n if (segment === '.' || segment === '') {\n // Skip current directory references and empty segments\n continue;\n }\n else if (segment === '..') {\n if (normalizedSegments.length === 0) {\n // Path escapes root, keep at root level\n continue;\n }\n // Go up one directory\n normalizedSegments.pop();\n }\n else {\n normalizedSegments.push(segment);\n }\n }\n\n return joinPath(normalizedSegments);\n}\n\n/**\n * Get the file extension from a path\n * \n * @param path - The file path\n * @returns The file extension including the dot, or empty string if no extension\n * \n * @example\n * ```typescript\n * extname('/path/to/file.txt'); // '.txt'\n * extname('/path/to/file'); // ''\n * extname('/path/to/file.name.ext'); // '.ext'\n * extname('/path/to/.hidden'); // ''\n * ```\n */\nexport function extname(path: string): string {\n const filename = basename(path);\n const lastDotIndex = filename.lastIndexOf('.');\n \n if (lastDotIndex <= 0 || lastDotIndex === filename.length - 1) {\n return '';\n }\n \n return filename.slice(lastDotIndex);\n}\n\nexport function createBuffer(data: string | Uint8Array | ArrayBuffer, encoding: BufferEncoding = 'utf-8'): Uint8Array {\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/**\n * Read raw binary data from a file using a file handle\n *\n * @param fileHandle - The file handle to read from\n * @returns The raw binary data as Uint8Array\n */\nexport async function readFileData(fileHandle: FileSystemFileHandle): Promise<Uint8Array> {\n const handle = await fileHandle.createSyncAccessHandle();\n\n try {\n const size = handle.getSize();\n const buffer = new Uint8Array(size);\n\n handle.read(buffer, { at: 0 });\n\n return buffer;\n }\n finally {\n handle.close();\n }\n}\n\n/**\n * Write data to a file using a file handle\n *\n * @param fileHandle - The file handle to write to\n * @param data - The data to write to the file\n * @param encoding - The encoding to use\n * @param options - Write options (truncate or append)\n */\nexport async function writeFileData(\n fileHandle: FileSystemFileHandle,\n data: string | Uint8Array | ArrayBuffer,\n encoding?: BufferEncoding,\n options: { truncate?: boolean; append?: boolean } = {}\n): Promise<void> {\n let handle: FileSystemSyncAccessHandle | null = null;\n\n try {\n handle = await fileHandle.createSyncAccessHandle();\n\n const buffer = createBuffer(data, encoding);\n const writeOffset = options.append ? handle.getSize() : 0;\n\n handle.write(buffer, { at: writeOffset });\n\n if (options.truncate && !options.append) {\n handle.truncate(buffer.byteLength);\n }\n\n handle.flush();\n }\n catch (error) {\n console.error(error);\n const operation = options.append ? 'append' : 'write';\n\n throw new OPFSError(`Failed to ${ operation } file`, `${ operation.toUpperCase() }_FAILED`);\n }\n finally {\n if (handle) {\n try {\n handle.close();\n }\n catch { /* ~ */ }\n }\n }\n}\n\n/**\n * Calculate file hash using Web Crypto API\n * \n * @param buffer - The file content as File, ArrayBuffer, or Uint8Array\n * @param algorithm - Hash algorithm to use (default: 'SHA-1')\n * @param maxSize - Maximum file size in bytes. If file is larger, throws error (default: 50MB)\n * @returns Promise that resolves to the hash string\n * @throws Error if file size exceeds maxSize\n */\nexport async function calculateFileHash(\n buffer: File | ArrayBuffer | Uint8Array, \n algorithm: string = 'SHA-1',\n maxSize: number = 50 * 1024 * 1024 // 50MB default\n): Promise<string> {\n if (buffer instanceof File) {\n buffer = await buffer.arrayBuffer();\n }\n \n // Check file size before processing\n if (buffer.byteLength > maxSize) {\n throw new Error(`File size ${buffer.byteLength} bytes exceeds maximum allowed size ${maxSize} bytes`);\n }\n\n const bufferSource = new Uint8Array(buffer);\n const hashBuffer = await crypto.subtle.digest(algorithm, bufferSource);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n}\n\n/**\n * Convert a Blob to Uint8Array\n * \n * This function converts a Blob object to a Uint8Array for use with file operations.\n * It's useful when working with file uploads or other Blob data sources.\n * \n * @param blob - The Blob to convert\n * @returns Promise that resolves to the Uint8Array representation of the Blob\n * \n * @example\n * ```typescript\n * const fileInput = document.getElementById('file') as HTMLInputElement;\n * const file = fileInput.files?.[0];\n * if (file) {\n * const data = await convertBlobToUint8Array(file);\n * await fs.writeFile('/uploaded-file', data);\n * }\n * ```\n */\nexport async function convertBlobToUint8Array(blob: Blob): Promise<Uint8Array> {\n const arrayBuffer = await blob.arrayBuffer();\n return new Uint8Array(arrayBuffer);\n}\n"],"names":["OPFSError","message","code","path","OPFSNotSupportedError","OPFSNotMountedError","PathError","FileNotFoundError","DirectoryNotFoundError","PermissionError","operation","StorageError","TimeoutError","encodeString","data","encoding","encodeUtf16LE","encodeAscii","encodeLatin1","char","c","b","decodeBuffer","buffer","decodeUtf16LE","str","buf","i","codeUnits","checkOPFSSupport","splitPath","joinPath","segments","basename","dirname","normalizePath","resolvePath","normalizedPath","normalizedSegments","segment","extname","filename","lastDotIndex","createBuffer","readFileData","fileHandle","handle","size","writeFileData","options","writeOffset","error","calculateFileHash","algorithm","maxSize","bufferSource","hashBuffer","convertBlobToUint8Array","blob","arrayBuffer"],"mappings":"AAGO,MAAMA,UAAkB,MAAM;AAAA,EACjC,YAAYC,GAAiCC,GAA8BC,GAAe;AACtF,UAAMF,CAAO,GAD4B,KAAA,OAAAC,GAA8B,KAAA,OAAAC,GAEvE,KAAK,OAAO;AAAA,EAChB;AACJ;AAKO,MAAMC,UAA8BJ,EAAU;AAAA,EACjD,cAAc;AACV,UAAM,yCAAyC,oBAAoB;AAAA,EACvE;AACJ;AAM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