FS-Bridge
File system abstraction layer
FS-Bridge
The @ucdjs/fs-bridge package provides an abstraction layer for file system operations, allowing different storage backends to be used interchangeably. This enables your code to work seamlessly across different environments—from Node.js file systems to HTTP-based remote storage.
The fs-bridge is used internally by the @ucdjs/client and @ucdjs/cli to seamlessly switch between fetching UCD files locally or over the network without changing the core application logic.
Getting Started
Initialization
Import the specific bridge you want to use. The Node.js bridge is full-featured and requires a basePath.
import { createNodeFileSystemBridge } from "@ucdjs/fs-bridge/bridges/node";
const bridge = createNodeFileSystemBridge({
basePath: "/path/to/directory"
});Usage
The bridge exposes standard file system operations that are completely agnostic to the underlying storage mechanism.
// Read a file (returns a Buffer/Uint8Array or string)
const content = await bridge.read("file.txt", "utf8");
// Check if a file exists
const exists = await bridge.exists("file.txt");
// List directory contents
const entries = await bridge.listdir("subdirectory");Available Bridges
The package includes ready-to-use bridge implementations:
Node.js Bridge
Full-featured bridge for local file system access.
HTTP Bridge
Read-only bridge for accessing files over HTTP/HTTPS.
Documentation
- Specification - Complete FileSystemBridge interface specification
- Capabilities - Understanding and working with bridge capabilities
- Errors - Error types and error handling patterns
- Hooks - Monitor and debug operations with hooks
- Creating Custom Bridges - Build your own bridge implementations