Skip to content

TomokiMiyauci/file-system-access

Repository files navigation

file-system-access

🚧 WIP at beta branch

File System Access ponyfill for server side runtime.

This allows the native file dialog and the file system handle API to be used on the server side.

Complies with WICG, File System Access and File System Standard.

Usage

FileSystemAccess binds the File System Access API. The constructor requires adaptor.

import { type Adaptor, FileSystemAccess } from "@miyauci/file-system-access";

declare const adaptor: Adaptor;
const { showOpenFilePicker, showDirectoryPicker } = new FileSystemAccess(
  adaptor,
);

const [handle] = await showOpenFilePicker();
const writable = await handle.createWritable();
await writable.write("hello");
await writable.write("world");
await writable.close();

const file = await handle.getFile();
await file.text(); // helloworld;

Adaptors

Adaptor is an abstraction that absorbs runtime differences.

Deno

Adaptor for deno runtime with asynchronous BLOB.

import { DenoAdaptor } from "@miyauci/file-system-access/deno";
import { FileSystemAccess } from "@miyauci/file-system-access";

const adaptor = new DenoAdaptor();
const { showOpenFilePicker } = new FileSystemAccess(adaptor);

When using DenoAdaptor, the following flags are required.

  • --unstable-ffi

It also requires the following permission.

  • --allow-ffi
  • --allow-read(When read directory or file)
  • --allow-write(When write file)

Node

// TODO

Bun

// TODO

Contributing

See CONTRIBUTING.md

License

MIT © 2024 Tomoki Miyauchi