The fs facade
One object, the whole filesystem. fs groups everything you reach for — reading, writing, editing, walking, hashing — into a small, discoverable surface. It’s the main way you use @warlock.js/fs; this page is the 60-second tour, with a link to go deep on each area.
import { fs } from "@warlock.js/fs";
await fs.files.putJson("config.json", { port: 3000 }); // filesawait fs.dirs.ensure("storage/uploads"); // directoriesconst pkg = fs.file("package.json"); // a lazy handleconst digest = await fs.hash.file("bundle.js"); // hashingFiles — fs.files.*
Section titled “Files — fs.files.*”Read, write, and edit in place. getJson can validate against a schema and fall back when a file is missing; edit / mergeJson patch a file without the read-then-write dance.
const cfg = await fs.files.getJson("config.json", { default: {} });await fs.files.editJson("package.json", (p) => ({ ...p, version: "4.7.0" }));Directories — fs.dirs.*
Section titled “Directories — fs.dirs.*”Ensure, empty, copy, and walk — recursively, with a constant-memory async iterator.
for await (const entry of fs.dirs.walk("src")) { // { path, name, type: "file" | "directory" }}Handles — fs.file() / fs.dir()
Section titled “Handles — fs.file() / fs.dir()”Prefer an object over a path string? fs.file(path) and fs.dir(path) are lazy, immutable handles with pure-path helpers and the same verbs.
const file = fs.file("src/app/user.model.ts");file.extension; // ".ts"await file.size(); // bytesHashing — fs.hash.*
Section titled “Hashing — fs.hash.*”SHA-256 by default. string / buffer are synchronous (in-memory); file / dir are async (they read from disk).
fs.hash.string("hello"); // syncawait fs.hash.dir("dist"); // async — a stable tree fingerprint