@petroglyph/fs
v0.2.0
Published
File system adapters for Petroglyph. Provides LocalFileSystem and VirtualFileSystem implementations.
Maintainers
Readme
@petroglyph/fs
File system adapters for Petroglyph. Provides LocalFileSystem and VirtualFileSystem implementations.
Installation
bun add @petroglyph/fs
# or
npm install @petroglyph/fs
# or
pnpm add @petroglyph/fsUsage
LocalFileSystem
import { LocalFileSystem } from '@petroglyph/fs';
const fs = new LocalFileSystem('/path/to/your/vault');
// Read a file
const content = await fs.readFile('note.md');
// Write a file
await fs.writeFile('note.md', '# My Note\n\nContent here');
// List directory
const entries = await fs.readdir('/path/to/directory');
// Watch for changes
const watcher = await fs.watch('/path/to/directory', (event) => {
console.log('File changed:', event.path, event.type);
});VirtualFileSystem
import { VirtualFileSystem } from '@petroglyph/fs';
const fs = new VirtualFileSystem({
'note.md': '# My Note\n\nContent',
'folder/another.md': '# Another Note',
});
// Same API as LocalFileSystem
const content = await fs.readFile('note.md');Exports
This package provides multiple entry points:
@petroglyph/fs- Main exports (types, errors, utilities)@petroglyph/fs/local- LocalFileSystem adapter@petroglyph/fs/virtual- VirtualFileSystem adapter
API Reference
IFileSystem
The base interface that all file system adapters implement:
interface IFileSystem {
readFile(path: string): Promise<Uint8Array>;
writeFile(path: string, content: Uint8Array): Promise<void>;
readdir(path: string): Promise<DirEntry[]>;
stat(path: string): Promise<FileStat>;
mkdir(path: string, options?: MkdirOptions): Promise<void>;
rmdir(path: string, options?: RmdirOptions): Promise<void>;
unlink(path: string): Promise<void>;
watch(path: string, callback: WatchCallback): Promise<Watcher>;
}License
MIT
