Files
scriptc/tests/fixtures/self-hosting/unicode-host-filesystem.ts
Chris Tate 98dd1b3f0f Optimize native file processing (#688)
- Read binary and text files into owned storage across filesystem entry points.
- Extend integer inference through module initialization and filtered processing loops.
- Preserve shared bindings, byte views, and filesystem error behavior.
2026-10-05 12:59:31 -05:00

21 lines
1.1 KiB
TypeScript

import { appendFileSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
import { join } from "node:path";
const directory = process.argv[2]!;
process.chdir(directory);
console.log("cwd", process.cwd() === realpathSync.native(directory));
const name = "源-🌍.ts";
const file = join(directory, name);
writeFileSync(file, "héllo");
appendFileSync(file, " 世界");
console.log("read", readFileSync(file, "utf8"));
console.log("bytes", readFileSync(file).toString("utf8"));
console.log("stat", statSync(file).isFile(), statSync(directory).isDirectory());
console.log("names", readdirSync(directory).includes(name));
const entries = readdirSync(directory, { withFileTypes: true });
console.log("dirent", entries.some((entry) => entry.name === name && entry.isFile()));
console.log("realpath", realpathSync.native(file).endsWith(name));
for (const target of [file, join(directory, "missing")]) {
try { readdirSync(target); console.log("unexpected"); }
catch (error) { console.log("scan error", (error as NodeJS.ErrnoException).code); }
}