UCD.js Docs
FS Bridge

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

Installation

Install the bridge using your preferred package manager.

npm install @ucdjs/fs-bridge

Initialization

Import the specific bridge you want to use. The Node.js bridge is full-featured and requires a basePath.

bridge.ts
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.

bridge.ts
// 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:

Documentation

On this page