
flysystem, sandboxed filesystem for Carne
Local driver with atomic writes, visibility, policies and multi-disk facade on top of std/os.
carne install flysystem
- Sandboxed to one root folder, escapes are blocked
- Safe writes (temp file + rename), works with text and binary
- Files and folders: read, write, append, copy, move, delete, list
- Recursive listing and glob search (
*.txt,**/*.js) - Public / private visibility (
0o644/0o600) - Safe symlinks that stay inside the root
- File info: size, dates, checksums, mime types, read by lines
- Multiple disks behind one facade (
local,cache, ...) - Optional policy guard: read-only, size limits, allowed types
- Clear errors (
StorageError,FilesystemPolicyError)
const { newLocalDriver } = require("pkg/flysystem");
const d = newLocalDriver("/tmp/uploads");
d.write("hello.txt", "hi");
console.log(d.read("hello.txt")); // "hi"
console.log(d.exists("hello.txt")); // trueLocal driver (newLocalDriver(root)):
write(path, content[, visibility])— atomic tmp + rename writeread(path)/readBytes(path)— string /Uint8Arrayappend(path, content),delete(path),exists(path)list(path[, recursive])—[{path, size, lastModified, isDir}]move(src, dest),copy(src, dest)makeDir(path),deleteDir(path[, force]),touch(path)copyDir(src, dest),moveDir(src, dest),search("*.txt")metadata(path),size(path),lastModified(path)checksum(path)— MD5 hex viastd/cryptohash.md5mimeType(path)— viastd/mimetype,application/octet-streamfallbacksetVisibility(path, v)/visibility(path)—public(0o644) /private(0o600)createSymlink(path, target)/isSymlink(path)/readLink(path)— targets must stay inside the rootreadLines(path)—string[]split on newlines
All paths are sandboxed to the root. Escapes throw StorageError
with Path traversal detected.
Multi-disk facade:
const { newFilesystem, newLocalDriver } = require("pkg/flysystem");
const fs = newFilesystem();
fs.addDisk("local", newLocalDriver("/tmp/local"));
fs.addDisk("cache", newLocalDriver("/tmp/cache"));
fs.write("hello.txt", "hi");
fs.disk("cache").write("cached.json", "{}");Policies:
const { newFilesystemPolicy } = require("pkg/flysystem");
const secure = newFilesystemPolicy(driver, {
readOnly: false,
maxFileSize: 10 * 1024 * 1024,
maxPathLength: 255,
maxDepth: 8,
denyHiddenFiles: true,
allowedExtensions: ["txt"],
allowedMimeTypes: ["text/plain"],
});carne test
carne test localMIT.