LocalAdapter

The built-in adapter that uses Node.js fs APIs to interact with the local filesystem. This is the default adapter used when no adapter is specified in createLayer.

Import

import { LocalAdapter } from "@catmint-fs/core";

Signature

class LocalAdapter implements FsAdapter {
  constructor();
  capabilities(): AdapterCapabilities;
  // ...all FsAdapter methods
}

Constructor

The LocalAdapter constructor takes no arguments:

const adapter = new LocalAdapter();

Capabilities

adapter.capabilities();
// {
//   permissions: true,
//   symlinks: true,
//   caseSensitive: boolean  // Detected from host filesystem
// }
CapabilityValueNotes
permissionstrueFull chmod/chown/lchown support via Node.js fs
symlinkstrueFull symlink support via Node.js fs
caseSensitiveDetectedtrue on Linux (ext4), false on macOS (HFS+) and Windows (NTFS)

Environment

LocalAdapter requires Node.js. It uses the node:fs/promises API internally. It is not compatible with:

  • Browsers
  • Deno
  • Cloudflare Workers
  • Bun (may work but is not officially supported)

For non-Node.js environments, use a custom adapter or the SqliteAdapter.

Examples

Explicit usage

import { createLayer, LocalAdapter } from "@catmint-fs/core";

const adapter = new LocalAdapter();
const layer = createLayer({ root: "/path/to/project", adapter });

const data = await layer.readFile("/package.json");
console.log(new TextDecoder().decode(data));

layer.dispose();

Implicit usage (default)

When no adapter is provided, createLayer uses LocalAdapter automatically:

import { createLayer } from "@catmint-fs/core";

// This uses LocalAdapter under the hood
const layer = createLayer({ root: "/path/to/project" });

Reading and writing

import { createLayer, LocalAdapter } from "@catmint-fs/core";

const layer = createLayer({
  root: "/tmp/sandbox",
  adapter: new LocalAdapter(),
});

// Read from disk
const entries = await layer.readdir("/");
console.log(entries);

// Write through the layer (held in overlay)
await layer.writeFile("/hello.txt", new TextEncoder().encode("Hello!"));

// Apply to disk
await layer.apply();

layer.dispose();

Permission operations

import { createLayer } from "@catmint-fs/core";

const layer = createLayer({ root: "/tmp/sandbox" });

await layer.writeFile("/script.sh", new TextEncoder().encode("#!/bin/sh\necho hi"));
await layer.chmod("/script.sh", 0o755);

await layer.apply();
layer.dispose();

Methods

LocalAdapter implements all methods of the FsAdapter interface. Each method maps directly to the corresponding node:fs/promises function:

Adapter MethodNode.js API
readFilefs.readFile
createReadStreamfs.createReadStream (wrapped in ReadableStream)
readdirfs.readdir with { withFileTypes: true }
statfs.stat
lstatfs.lstat
readlinkfs.readlink
existsfs.access
writeFilefs.writeFile
mkdirfs.mkdir
rmfs.rm
rmdirfs.rmdir
renamefs.rename
symlinkfs.symlink
chmodfs.chmod
chownfs.chown
lchownfs.lchown
checkPermissionfs.access with mode flags

See Also