Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
File System Standard, based on WHATWG spec reference implementation
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
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";