npm.io
4.68.1 • Published 3d ago

@jsonjoy.com/fs-node-to-fsa

Licence
Apache-2.0
Version
4.68.1
Deps
3
Size
123 kB
Vulns
0
Weekly
0
Stars
2.1K

@jsonjoy.com/fs-node-to-fsa

Adapter to convert Node.js fs API to File System Access API (FSA).

Installation

npm install @jsonjoy.com/fs-node-to-fsa

Usage

import { nodeToFsa } from '@jsonjoy.com/fs-node-to-fsa';
import * as fs from 'fs';

const dir = nodeToFsa(fs, '/path/to/directory', { mode: 'readwrite' });

// Now use the FSA API
for await (const [name, handle] of dir.entries()) {
  console.log(name, handle.kind);
}

FileSystemObserver

NodeFileSystemObserver implements the FileSystemObserver proposal on top of the Node.js fs.watch API. It is a best-effort implementation, per the proposal's allowance for local file systems: rename events are classified into "appeared"/"disappeared" records by stat-ing the path, and no "moved" records are ever produced.

import { nodeToFsa, NodeFileSystemObserver } from '@jsonjoy.com/fs-node-to-fsa';
import * as fs from 'fs';

const dir = nodeToFsa(fs, '/path/to/directory', { mode: 'readwrite' });
const observer = new NodeFileSystemObserver(fs, records => console.log(records));
await observer.observe(dir, { recursive: true });

Reference

Keywords