Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 1.08 KB

fs-to-fsa.md

File metadata and controls

30 lines (21 loc) · 1.08 KB

Node fs API to File System Access API

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 });