@themartiancompany/opfs 1.8.11

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 (114) hide show
  1. package/COPYING +674 -0
  2. package/README.cn.md +301 -0
  3. package/README.md +241 -0
  4. package/dist/main.cjs +1840 -0
  5. package/dist/main.cjs.map +1 -0
  6. package/dist/main.mjs +1751 -0
  7. package/dist/main.mjs.map +1 -0
  8. package/dist/types.d.ts +920 -0
  9. package/dist/types.d.ts.map +1 -0
  10. package/docs/README.md +115 -0
  11. package/docs/classes/SyncMessenger.md +42 -0
  12. package/docs/functions/appendFile.md +29 -0
  13. package/docs/functions/appendFileSync.md +26 -0
  14. package/docs/functions/assertAbsolutePath.md +29 -0
  15. package/docs/functions/assertFileUrl.md +29 -0
  16. package/docs/functions/connectSyncAgent.md +25 -0
  17. package/docs/functions/copy.md +35 -0
  18. package/docs/functions/copySync.md +30 -0
  19. package/docs/functions/createFile.md +27 -0
  20. package/docs/functions/createFileSync.md +25 -0
  21. package/docs/functions/deleteTemp.md +23 -0
  22. package/docs/functions/deleteTempSync.md +19 -0
  23. package/docs/functions/downloadFile.md +58 -0
  24. package/docs/functions/emptyDir.md +28 -0
  25. package/docs/functions/emptyDirSync.md +25 -0
  26. package/docs/functions/exists.md +29 -0
  27. package/docs/functions/existsSync.md +26 -0
  28. package/docs/functions/generateTempPath.md +27 -0
  29. package/docs/functions/getFileDataByHandle.md +27 -0
  30. package/docs/functions/getSyncMessenger.md +22 -0
  31. package/docs/functions/isDirectoryHandle.md +27 -0
  32. package/docs/functions/isFileHandle.md +27 -0
  33. package/docs/functions/isFileHandleLike.md +27 -0
  34. package/docs/functions/isOPFSSupported.md +21 -0
  35. package/docs/functions/isTempPath.md +27 -0
  36. package/docs/functions/mkTemp.md +28 -0
  37. package/docs/functions/mkTempSync.md +25 -0
  38. package/docs/functions/mkdir.md +27 -0
  39. package/docs/functions/mkdirSync.md +25 -0
  40. package/docs/functions/move.md +34 -0
  41. package/docs/functions/moveSync.md +30 -0
  42. package/docs/functions/pruneTemp.md +28 -0
  43. package/docs/functions/pruneTempSync.md +25 -0
  44. package/docs/functions/readBlobFile.md +28 -0
  45. package/docs/functions/readBlobFileSync.md +25 -0
  46. package/docs/functions/readDir.md +28 -0
  47. package/docs/functions/readDirSync.md +26 -0
  48. package/docs/functions/readFile.md +132 -0
  49. package/docs/functions/readFileSync.md +70 -0
  50. package/docs/functions/readJsonFile.md +35 -0
  51. package/docs/functions/readJsonFileSync.md +31 -0
  52. package/docs/functions/readTextFile.md +28 -0
  53. package/docs/functions/readTextFileSync.md +25 -0
  54. package/docs/functions/remove.md +27 -0
  55. package/docs/functions/removeSync.md +25 -0
  56. package/docs/functions/setSyncMessenger.md +26 -0
  57. package/docs/functions/startSyncAgent.md +21 -0
  58. package/docs/functions/stat.md +27 -0
  59. package/docs/functions/statSync.md +25 -0
  60. package/docs/functions/toFileSystemHandleLike.md +27 -0
  61. package/docs/functions/unzip.md +32 -0
  62. package/docs/functions/unzipFromUrl.md +36 -0
  63. package/docs/functions/unzipSync.md +26 -0
  64. package/docs/functions/uploadFile.md +33 -0
  65. package/docs/functions/writeFile.md +32 -0
  66. package/docs/functions/writeFileSync.md +30 -0
  67. package/docs/functions/zip.md +65 -0
  68. package/docs/functions/zipFromUrl.md +63 -0
  69. package/docs/functions/zipSync.md +55 -0
  70. package/docs/interfaces/CopyOptions.md +17 -0
  71. package/docs/interfaces/DownloadFileTempResponse.md +18 -0
  72. package/docs/interfaces/ErrorLike.md +18 -0
  73. package/docs/interfaces/ExistsOptions.md +18 -0
  74. package/docs/interfaces/FileLike.md +21 -0
  75. package/docs/interfaces/FileSystemFileHandleLike.md +25 -0
  76. package/docs/interfaces/FileSystemHandleLike.md +22 -0
  77. package/docs/interfaces/MoveOptions.md +17 -0
  78. package/docs/interfaces/ReadDirEntry.md +18 -0
  79. package/docs/interfaces/ReadDirEntrySync.md +18 -0
  80. package/docs/interfaces/ReadDirOptions.md +17 -0
  81. package/docs/interfaces/ReadOptions.md +17 -0
  82. package/docs/interfaces/SyncAgentOptions.md +19 -0
  83. package/docs/interfaces/TempOptions.md +19 -0
  84. package/docs/interfaces/UploadRequestInit.md +21 -0
  85. package/docs/interfaces/WriteOptions.md +19 -0
  86. package/docs/interfaces/ZipOptions.md +17 -0
  87. package/docs/type-aliases/FileEncoding.md +15 -0
  88. package/docs/type-aliases/FsRequestInit.md +15 -0
  89. package/docs/type-aliases/ReadFileContent.md +15 -0
  90. package/docs/type-aliases/WriteFileContent.md +15 -0
  91. package/docs/type-aliases/WriteSyncFileContent.md +16 -0
  92. package/docs/variables/CURRENT_DIR.md +15 -0
  93. package/docs/variables/NOT_FOUND_ERROR.md +18 -0
  94. package/docs/variables/ROOT_DIR.md +15 -0
  95. package/docs/variables/TMP_DIR.md +15 -0
  96. package/package.json +141 -0
  97. package/src/fs/assertions.ts +63 -0
  98. package/src/fs/constants.ts +63 -0
  99. package/src/fs/defines.ts +352 -0
  100. package/src/fs/helpers.ts +338 -0
  101. package/src/fs/opfs_core.ts +413 -0
  102. package/src/fs/opfs_download.ts +174 -0
  103. package/src/fs/opfs_ext.ts +504 -0
  104. package/src/fs/opfs_tmp.ts +131 -0
  105. package/src/fs/opfs_unzip.ts +168 -0
  106. package/src/fs/opfs_upload.ts +126 -0
  107. package/src/fs/opfs_zip.ts +314 -0
  108. package/src/fs/support.ts +36 -0
  109. package/src/fs/utils.ts +176 -0
  110. package/src/mod.ts +41 -0
  111. package/src/worker/helpers.ts +168 -0
  112. package/src/worker/opfs_worker.ts +298 -0
  113. package/src/worker/opfs_worker_adapter.ts +666 -0
  114. package/src/worker/shared.ts +400 -0
@@ -0,0 +1,17 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / ZipOptions
6
+
7
+ # Interface: ZipOptions
8
+
9
+ Defined in: fs/defines.ts:279
10
+
11
+ Options for `zip`.
12
+
13
+ ## Properties
14
+
15
+ | Property | Type | Default value | Description | Defined in |
16
+ | ------ | ------ | ------ | ------ | ------ |
17
+ | <a id="preserveroot"></a> `preserveRoot` | `boolean` | `true` | Whether to preserve the root directory in the zip file. | fs/defines.ts:284 |
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / FileEncoding
6
+
7
+ # Type Alias: FileEncoding
8
+
9
+ ```ts
10
+ type FileEncoding = "binary" | "utf8" | "blob";
11
+ ```
12
+
13
+ Defined in: fs/defines.ts:105
14
+
15
+ Supported file encodings for reading and writing files.
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / FsRequestInit
6
+
7
+ # Type Alias: FsRequestInit
8
+
9
+ ```ts
10
+ type FsRequestInit = Omit<FetchInit, "abortable" | "responseType">;
11
+ ```
12
+
13
+ Defined in: fs/defines.ts:113
14
+
15
+ fetch-t options for download and upload.
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / ReadFileContent
6
+
7
+ # Type Alias: ReadFileContent
8
+
9
+ ```ts
10
+ type ReadFileContent = ArrayBuffer | File | string;
11
+ ```
12
+
13
+ Defined in: fs/defines.ts:48
14
+
15
+ Represents the possible content types that can be read from a file.
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / WriteFileContent
6
+
7
+ # Type Alias: WriteFileContent
8
+
9
+ ```ts
10
+ type WriteFileContent = BufferSource | Blob | string;
11
+ ```
12
+
13
+ Defined in: fs/defines.ts:32
14
+
15
+ Represents the possible content types that can be written to a file.
@@ -0,0 +1,16 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / WriteSyncFileContent
6
+
7
+ # Type Alias: WriteSyncFileContent
8
+
9
+ ```ts
10
+ type WriteSyncFileContent = BufferSource | string;
11
+ ```
12
+
13
+ Defined in: fs/defines.ts:41
14
+
15
+ Represents the possible content types that can be
16
+ written synchronously to a file.
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / CURRENT\_DIR
6
+
7
+ # Variable: CURRENT\_DIR
8
+
9
+ ```ts
10
+ const CURRENT_DIR: ".";
11
+ ```
12
+
13
+ Defined in: fs/constants.ts:54
14
+
15
+ A constant representing the current directory path.
@@ -0,0 +1,18 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / NOT\_FOUND\_ERROR
6
+
7
+ # Variable: NOT\_FOUND\_ERROR
8
+
9
+ ```ts
10
+ const NOT_FOUND_ERROR: "NotFoundError";
11
+ ```
12
+
13
+ Defined in: fs/constants.ts:38
14
+
15
+ A constant representing the error thrown when a
16
+ file or directory is not found.
17
+
18
+ Name of DOMException.NOT_FOUND_ERR.
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / ROOT\_DIR
6
+
7
+ # Variable: ROOT\_DIR
8
+
9
+ ```ts
10
+ const ROOT_DIR: "/";
11
+ ```
12
+
13
+ Defined in: fs/constants.ts:46
14
+
15
+ A constant representing the root directory path.
@@ -0,0 +1,15 @@
1
+ [**@themartiancompany/opfs**](../README.md)
2
+
3
+ ***
4
+
5
+ [@themartiancompany/opfs](../README.md) / TMP\_DIR
6
+
7
+ # Variable: TMP\_DIR
8
+
9
+ ```ts
10
+ const TMP_DIR: "/tmp";
11
+ ```
12
+
13
+ Defined in: fs/constants.ts:62
14
+
15
+ A constant representing the temporary directory path.
package/package.json ADDED
@@ -0,0 +1,141 @@
1
+ {
2
+ "name":
3
+ "@themartiancompany/opfs",
4
+ "description":
5
+ "Browser-compatible (OPFS) Node/Deno 'fs' module.",
6
+ "version":
7
+ "1.8.11",
8
+ "homepage":
9
+ "https://github.com/themartiancompany/opfs",
10
+ "license":
11
+ "GPL-3.0",
12
+ "bugs": {
13
+ "url":
14
+ "https://github.com/themartiancompany/opfs/issues"
15
+ },
16
+ "author": {
17
+ "name":
18
+ "Jiang Jie",
19
+ "email":
20
+ "jiang115jie@gmail.com",
21
+ "url":
22
+ "https://github.com/JiangJie"
23
+ },
24
+ "contributors": [ {
25
+ "name":
26
+ "Pellegrino Prevete",
27
+ "email":
28
+ "pellegrinoprevete@gmail.com",
29
+ "url":
30
+ "https://github.com/tallero"
31
+ } ],
32
+ "keywords": [
33
+ "fs",
34
+ "system",
35
+ "file",
36
+ "directory",
37
+ "opfs",
38
+ "origin",
39
+ "private",
40
+ "worker",
41
+ "sync",
42
+ "async",
43
+ "upload",
44
+ "download",
45
+ "zip",
46
+ "unzip"
47
+ ],
48
+ "type":
49
+ "module",
50
+ "files": [
51
+ "COPYING",
52
+ "README.md",
53
+ "README.cn.md",
54
+ "package.json",
55
+ "docs",
56
+ "src",
57
+ "dist"
58
+ ],
59
+ "source":
60
+ "src/mod.ts",
61
+ "man":
62
+ "man/opfs.1",
63
+ "main":
64
+ "dist/main.cjs",
65
+ "module":
66
+ "dist/main.mjs",
67
+ "types":
68
+ "dist/types.d.ts",
69
+ "sideEffects":
70
+ false,
71
+ "scripts": {
72
+ "clean":
73
+ "npx dlx rimraf .parcel-cache dist",
74
+ "check":
75
+ "npx tsc --noEmit",
76
+ "lint":
77
+ "npx eslint .",
78
+ "prebuild":
79
+ "npx rimraf dist && npm run check && npm run lint",
80
+ "build":
81
+ "npm install --save-dev && npx rollup --config rollup.config.mjs",
82
+ "docs":
83
+ "typedoc",
84
+ "prepublishOnly":
85
+ "npx rollup --config rollup.config.mjs",
86
+ "start":
87
+ "npx parcel serve tests/index.html --dist-dir dist/dev --port 8443 --https --no-cache"
88
+ },
89
+ "repository": {
90
+ "type": "git",
91
+ "url": "git+https://github.com/themartiancompany/opfs.git"
92
+ },
93
+ "devDependencies": {
94
+ "@eslint/js":
95
+ "^9.32.0",
96
+ "@parcel/packager-ts":
97
+ "^2.16.0",
98
+ "@parcel/transformer-typescript-types":
99
+ "^2.16.0",
100
+ "dlx":
101
+ "^0.2.1",
102
+ "eslint":
103
+ "^9.32.0",
104
+ "parcel":
105
+ "^2.16.0",
106
+ "rimraf":
107
+ "^6.1.0",
108
+ "rollup":
109
+ "^4.52.5",
110
+ "rollup-plugin-dts":
111
+ "^6.2.1",
112
+ "rollup-plugin-esbuild":
113
+ "^6.2.1",
114
+ "typedoc":
115
+ "^0.27.9",
116
+ "typedoc-plugin-markdown":
117
+ "4.4.2",
118
+ "typescript":
119
+ "^5.8.3",
120
+ "typescript-eslint":
121
+ "^8.38.0"
122
+ },
123
+ "dependencies": {
124
+ "@happy-ts/fetch-t":
125
+ "^1.3.2",
126
+ "@std/path":
127
+ "npm:@themartiancompany/std__path@^1.1.1",
128
+ "fflate":
129
+ "^0.8.2",
130
+ "happy-rusty":
131
+ "^1.5.0",
132
+ "tiny-future":
133
+ "^1.1.0",
134
+ "tiny-invariant":
135
+ "^1.3.3"
136
+ },
137
+ "@parcel/resolver-default": {
138
+ "packageExports":
139
+ true
140
+ }
141
+ }
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+ /** ----------------------------------------------------------------------
4
+ * Copyright ©
5
+ * Jiang Jie
6
+ * 2024, 2025
7
+ * Pellegrino Prevete
8
+ * 2025
9
+ *
10
+ * All rights reserved
11
+ * ----------------------------------------------------------------------
12
+ *
13
+ * This program is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ */
26
+
27
+ import invariant from 'tiny-invariant';
28
+ import { ROOT_DIR } from './constants.ts';
29
+
30
+ /**
31
+ * Asserts that the provided path is an absolute path.
32
+ *
33
+ * @param path - The file path to validate.
34
+ * @throws Will throw an error if the path is not an absolute path.
35
+ */
36
+ export function
37
+ assertAbsolutePath(
38
+ path:
39
+ string): void {
40
+ invariant(
41
+ typeof path === 'string',
42
+ () => `Path must be a string but received ${ path }`);
43
+ invariant(
44
+ path[
45
+ 0] === ROOT_DIR,
46
+ () => `Path must start with / but received ${ path }`);
47
+ }
48
+
49
+ /**
50
+ * Asserts that the provided URL is a valid file URL.
51
+ *
52
+ * @param fileUrl - The file URL to validate.
53
+ * @throws Will throw an error if the URL is not a valid file URL.
54
+ */
55
+ export function
56
+ assertFileUrl(
57
+ fileUrl:
58
+ string): void {
59
+ invariant(
60
+ typeof fileUrl === 'string',
61
+ () => `File url must be a string ` +
62
+ `but received ${ fileUrl }`);
63
+ }
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+ /** ----------------------------------------------------------------------
4
+ * Copyright ©
5
+ * Jiang Jie
6
+ * 2024, 2025
7
+ * Pellegrino Prevete
8
+ * 2025
9
+ *
10
+ * All rights reserved
11
+ * ----------------------------------------------------------------------
12
+ *
13
+ * This program is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ */
26
+
27
+ export { ABORT_ERROR,
28
+ TIMEOUT_ERROR } from '@happy-ts/fetch-t';
29
+
30
+ /**
31
+ * A constant representing the error thrown when a
32
+ * file or directory is not found.
33
+ *
34
+ * Name of DOMException.NOT_FOUND_ERR.
35
+ */
36
+ export
37
+ const
38
+ NOT_FOUND_ERROR =
39
+ 'NotFoundError' as const;
40
+
41
+ /**
42
+ * A constant representing the root directory path.
43
+ */
44
+ export
45
+ const
46
+ ROOT_DIR =
47
+ '/' as const;
48
+
49
+ /**
50
+ * A constant representing the current directory path.
51
+ */
52
+ export
53
+ const
54
+ CURRENT_DIR =
55
+ '.' as const;
56
+
57
+ /**
58
+ * A constant representing the temporary directory path.
59
+ */
60
+ export
61
+ const
62
+ TMP_DIR =
63
+ '/tmp' as const;