Node fs API to File System Access API
February 17, 2024 ยท View on GitHub
memfs implements the web File System Access (FSA) API (formerly known as
Native File System API) on top of Node's fs-like filesystem API. This means you
can instantiate an FSA-compatible API on top of Node.js fs module,
or on top of memfs in-memory filesystem, or on top of any
other filesystem that implements Node's fs API.
Usage
Crate a FileSystemDirectoryHandle out
of any folder on your filesystem:
import { nodeToFsa } from 'memfs/lib/node-to-fsa';
const dir = nodeToFsa(fs, '/path/to/folder', { mode: 'readwrite' });
The fs Node filesystem API can be the real fs module or any fs like object, for example,
an in-memory one provided by memfs.
Now you can use the dir handle to execute all the File System Access API
methods, for example, create a new file:
const file = await dir.getFileHandle('foo.txt', { create: true });