Skip to content

Commit 599757c

Browse files
committed
docs: ✏️ add FSA readme
1 parent 5b5431b commit 599757c

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# memfs
22

3-
[![][chat-badge]][chat] [![][npm-badge]][npm-url]
3+
[![][npm-badge]][npm-url]
44

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
75
[npm-url]: https://www.npmjs.com/package/memfs
86
[npm-badge]: https://img.shields.io/npm/v/memfs.svg
97

@@ -19,8 +17,9 @@ npm i memfs
1917

2018
- Documentation
2119
- [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)
2423
- `experimental` [`crudfs` a CRUD-like file system abstraction](./docs/crudfs/index.md)
2524
- `experimental` [`casfs` Content Addressable Storage file system abstraction](./docs/casfs/index.md)
2625
- [Directory `snapshot` utility](./docs/snapshot/index.md)

docs/fsa/fsa.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
```

docs/node/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ In-memory file-system with [Node's `fs` API](https://nodejs.org/api/fs.html).
1717
- [Relative paths](./relative-paths.md)
1818
- [Dependencies](./dependencies.md)
1919

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
2220
[npm-url]: https://www.npmjs.com/package/memfs
2321
[npm-badge]: https://img.shields.io/npm/v/memfs.svg
2422
[travis-url]: https://travis-ci.org/streamich/memfs

0 commit comments

Comments
 (0)