Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 1.86 KB

File metadata and controls

76 lines (52 loc) · 1.86 KB

File System

Perry implements Node.js file system APIs for reading, writing, and managing files.

Reading Files

{{#include ../../examples/stdlib/fs/snippets.ts:read-text}}

Binary File Reading

{{#include ../../examples/stdlib/fs/snippets.ts:read-binary}}

readFileBuffer reads files as binary data (uses fs::read() internally, not read_to_string()).

Writing Files

{{#include ../../examples/stdlib/fs/snippets.ts:write-text}}

File Information

{{#include ../../examples/stdlib/fs/snippets.ts:stat}}

Directory Operations

{{#include ../../examples/stdlib/fs/snippets.ts:dirs}}

For recursive removal Perry exposes rmRecursive (a thin wrapper around std::fs::remove_dir_all). Wired via #193 through js_fs_rm_recursive in the LLVM backend.

import { rmRecursive } from "fs";
rmRecursive("output"); // Recursive remove; returns 1 on success, 0 on failure.

Path Utilities

{{#include ../../examples/stdlib/fs/snippets.ts:path-utils}}

For import.meta.url → filesystem path conversion, use fileURLToPath from the url module:

import { fileURLToPath } from "url";
import { dirname } from "path";

const dir = dirname(fileURLToPath(import.meta.url));

Threading

fs numeric file descriptors and fs.promises.FileHandle objects are thread-affine across perry/thread. Passing a numeric fd into spawn or parallelMap copies only the number; the receiving thread has its own fd registry, so operations fail with EBADF. Passing a FileHandle produces a detached handle with fd === -1.

Pass file paths across thread boundaries and reopen files inside the worker.

Next Steps