File tree Expand file tree Collapse file tree 3 files changed +47
-7
lines changed Expand file tree Collapse file tree 3 files changed +47
-7
lines changed Original file line number Diff line number Diff line change 1
1
# memfs
2
2
3
- [ ![ ] [ chat-badge ]] [ chat ] [ ![ ] [ npm-badge ]] [ npm-url ]
3
+ [ ![ ] [ npm-badge ]] [ npm-url ]
4
4
5
- [ chat ] : https://onp4.com/@vadim/~memfs
6
- [ chat-badge ] : https://img.shields.io/badge/Chat-%F0%9F%92%AC-green?style=flat&logo=chat&link=https://onp4.com/@vadim/~memfs
7
5
[ npm-url ] : https://www.npmjs.com/package/memfs
8
6
[ npm-badge ] : https://img.shields.io/npm/v/memfs.svg
9
7
@@ -19,8 +17,9 @@ npm i memfs
19
17
20
18
- Documentation
21
19
- [ In-memory Node.js ` fs ` API] ( ./docs/node/index.md )
22
- - ` experimental ` [ ` fs ` to File System Access API adapter] ( ./docs/fsa/fs-to-fsa.md )
23
- - ` experimental ` [ File System Access API to ` fs ` adapter] ( ./docs/fsa/fsa-to-fs.md )
20
+ - [ In-memory browser FSA (File System Access) API] ( ./docs/fsa/fsa.md )
21
+ - [ ` fs ` to File System Access API adapter] ( ./docs/fsa/fs-to-fsa.md )
22
+ - [ File System Access API to ` fs ` adapter] ( ./docs/fsa/fsa-to-fs.md )
24
23
- ` experimental ` [ ` crudfs ` a CRUD-like file system abstraction] ( ./docs/crudfs/index.md )
25
24
- ` experimental ` [ ` casfs ` Content Addressable Storage file system abstraction] ( ./docs/casfs/index.md )
26
25
- [ Directory ` snapshot ` utility] ( ./docs/snapshot/index.md )
Original file line number Diff line number Diff line change
1
+ # In-memory File System Access (FSA) API implementation
2
+
3
+ In-memory file-system with browser FSA API. Construct a new instance:
4
+
5
+
6
+ ## Quick Start
7
+
8
+ Create a new instance of FSA filesystem:
9
+
10
+ ``` ts
11
+ import {fsa } from ' memfs/lib/fsa' ;
12
+
13
+ // Create a new filesystem.
14
+ const {dir, core} = fsa ({ mode: ' readwrite' });
15
+
16
+ // Create a folder and a file.
17
+ const dir2 = await dir .getDirectoryHandle (' new-folder' , { create: true });
18
+ const file = await dir2 .getFileHandle (' file.txt' , { create: true });
19
+ await (await file .createWritable ()).write (' Hello, world!' );
20
+
21
+ // Export whole filesystem to JSON.
22
+ console .log (core .toJSON ());
23
+ // { '/new-folder/file.txt': 'Hello, world!' }
24
+ ```
25
+
26
+ Create a new FSA filesystem from JSON:
27
+
28
+ ``` ts
29
+ const {dir, core} = fsa ({ mode: ' readwrite' });
30
+
31
+ // Import JSON.
32
+ core .fromJSON ({
33
+ ' documents/readme.txt' : ' Welcome!' ,
34
+ ' photos/vacation.jpg' : Buffer .from (' fake-jpg-data' ),
35
+ ' empty-folder' : null ,
36
+ }, ' /' );
37
+
38
+ // Use FSA API.
39
+ const dir2 = await dir .getDirectoryHandle (' documents' );
40
+ const file = await dir2 .getFileHandle (' readme.txt' );
41
+ const fileContent = await file .getFile ();
42
+ console .log (await fileContent .text ()); // 'Welcome!'
43
+ ```
Original file line number Diff line number Diff line change @@ -17,8 +17,6 @@ In-memory file-system with [Node's `fs` API](https://nodejs.org/api/fs.html).
17
17
- [ Relative paths] ( ./relative-paths.md )
18
18
- [ Dependencies] ( ./dependencies.md )
19
19
20
- [ chat ] : https://onp4.com/@vadim/~memfs
21
- [ chat-badge ] : https://img.shields.io/badge/Chat-%F0%9F%92%AC-green?style=flat&logo=chat&link=https://onp4.com/@vadim/~memfs
22
20
[ npm-url ] : https://www.npmjs.com/package/memfs
23
21
[ npm-badge ] : https://img.shields.io/npm/v/memfs.svg
24
22
[ travis-url ] : https://travis-ci.org/streamich/memfs
You can’t perform that action at this time.
0 commit comments