Skip to main content

@miyauci/fs@1.0.0-beta.4
Built and signed on GitHub Actions

File System Standard, based on WHATWG spec reference implementation

This package works with Node.js, Deno, BrowsersIt is unknown whether this package works with Cloudflare Workers, Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
This package works with Browsers
Published
5 months ago (1.0.0-beta.4)

fs

🚧 WIP at beta branch

File System Standard, based on WHATWG spec reference implementation.

Usage

FileSystemHandle can be referenced as OPFS (Origin Private File System aka Bucket File System).

import { StorageManager } from "@miyauci/fs";
import { FileSystem } from "@miyauci/fs/deno";

const fileSystem = new FileSystem("path/to/dir"); // default is "."
const storage = new StorageManager(fileSystem);

const handle = await storage.getDirectory();
const fileHandle = await handle.getFileHandle("file.txt", { create: true });
const file = await fileHandle.getFile();
const contents = await file.text();

This allows operations to be performed on the File System using the File System API.

FileSystemObserver

FileSystemObserver monitors changes to the FileSystemHandle.

import {
  type FileSystemHandle,
  FileSystemObserver,
  type FileSystemObserverCallback,
} from "@miyauci/fs";

declare const handle: FileSystemHandle;
declare const callback: FileSystemObserverCallback;
const observer = new FileSystemObserver(callback);

await observer.observe(handle);

With Deno File System

To use FileSystemObserver with FileSystem, you must call FileSystem#watch.

This will internally call Deno.watchFs to monitor the file system. It is a deliberate decision not to do this automatically in the constructor.

import {
  FileSystemObserver,
  type FileSystemObserverCallback,
  StorageManager,
} from "@miyauci/fs";
import { FileSystem } from "@miyauci/fs/deno";

const fileSystem = new FileSystem();
const storage = new StorageManager(fileSystem);
const handle = await storage.getDirectory();
declare const callback: FileSystemObserverCallback;
const observer = new FileSystemObserver(callback);

fileSystem.watch();
await observer.observe(handle, { recursive: true });

await handle.getFileHandle("file.txt", { create: true });

fileSystem.unwatch();

Also, FileSystem#unwatch will stop the monitoring.

API

See jsr doc for all APIs.

Contributing

See CONTRIBUTING.md

License

MIT © 2024 Tomoki Miyauchi

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@miyauci/fs

Import symbol

import * as fs from "@miyauci/fs";

---- OR ----

Import directly with a jsr specifier

import * as fs from "jsr:@miyauci/fs";

Add Package

npx jsr add @miyauci/fs

Import symbol

import * as fs from "@miyauci/fs";

Add Package

yarn dlx jsr add @miyauci/fs

Import symbol

import * as fs from "@miyauci/fs";

Add Package

pnpm dlx jsr add @miyauci/fs

Import symbol

import * as fs from "@miyauci/fs";

Add Package

bunx jsr add @miyauci/fs

Import symbol

import * as fs from "@miyauci/fs";