@zenfs/dom 0.0.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/dist/backends/FileSystemAccess.d.ts +45 -0
- package/dist/backends/FileSystemAccess.js +263 -0
- package/dist/backends/HTTPRequest.d.ts +88 -0
- package/dist/backends/HTTPRequest.js +223 -0
- package/dist/backends/IndexedDB.d.ts +64 -0
- package/dist/backends/IndexedDB.js +234 -0
- package/dist/backends/Storage.d.ts +40 -0
- package/dist/backends/Storage.js +75 -0
- package/dist/backends/Worker.d.ts +79 -0
- package/dist/backends/Worker.js +169 -0
- package/dist/browser.min.js +9 -0
- package/dist/browser.min.js.map +7 -0
- package/dist/fetch.d.ts +17 -0
- package/dist/fetch.js +52 -0
- package/dist/file_index.d.ts +154 -0
- package/dist/file_index.js +342 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/license.md +19 -0
- package/package.json +60 -0
- package/readme.md +52 -0
package/readme.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# ZenFS DOM Backends
|
|
2
|
+
|
|
3
|
+
[ZenFS](https://github.com/zen-fs/core) backends for DOM APIs. DOM APIs are *only* available natively in browsers.
|
|
4
|
+
|
|
5
|
+
Please read the ZenFS documentation!
|
|
6
|
+
|
|
7
|
+
## Backends
|
|
8
|
+
|
|
9
|
+
- `HTTPRequest`: Downloads files on-demand from a webserver using `fetch`.
|
|
10
|
+
- `Storage`: Stores files in a `Storage` object, like `localStorage` and `seesionStorage`.
|
|
11
|
+
- `IndexedDB`: Stores files into an `IndexedDB` object database.
|
|
12
|
+
- `WorkerFS`: Lets you mount the ZenFS file system configured in the main thread in a WebWorker, or the other way around!
|
|
13
|
+
|
|
14
|
+
For more information, see the [API documentation](https://zen-fs.github.io/fs-dom).
|
|
15
|
+
|
|
16
|
+
## Installing
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install @zenfs/fs-dom
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Building
|
|
23
|
+
|
|
24
|
+
- Make sure you have Node and NPM installed. You must have Node v18 or newer.
|
|
25
|
+
- Install dependencies with `npm install`
|
|
26
|
+
- Build using `npm run build`
|
|
27
|
+
- You can find the built code in `dist`.
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
> 🛈 The examples are written in ESM. If you are using CJS, you can `require` the package. If running in a borwser you can add a script tag to your HTML pointing to the `browser.min.js` and use ZenFS DOM via the global `ZenFS_DOM` object.
|
|
32
|
+
|
|
33
|
+
You can use DOM backends, though you must register them if you plan on using `configure`:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import { configure, fs } from '@zenfs/core';
|
|
37
|
+
import { Storage } '@zenfs/fs-dom';
|
|
38
|
+
|
|
39
|
+
// you can also add a callback as the last parameter instead of using promises
|
|
40
|
+
await configure({ fs: 'Storage' });
|
|
41
|
+
|
|
42
|
+
if (!fs.existsSync('/test.txt')) {
|
|
43
|
+
fs.writeFileSync('/test.txt', 'This will persist across reloads!');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const contents = fs.readFileSync('/test.txt', 'utf-8');
|
|
47
|
+
console.log(contents);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Testing
|
|
51
|
+
|
|
52
|
+
Run unit tests with `npm test`.
|