Files
hyperframes/packages/cli/src/server/readBundleFile.ts
T
James Russo 97fde27df7 fix(cli): pin Studio bundle, signature and runtime file reads (#3728)
* fix(cli): read Studio bundle files through checked descriptors

* fix(cli): pin Studio signature and runtime artifact reads
2026-09-05 22:23:15 -04:00

27 lines
853 B
TypeScript

import { openSync, fstatSync, closeSync, statSync, readFileSync, constants } from "node:fs";
export function readBundleFile(filePath: string): Buffer<ArrayBuffer> | null {
let fd: number;
try {
// Check named pipes without waiting for a writer to connect.
fd = openSync(filePath, constants.O_RDONLY | constants.O_NONBLOCK);
} catch (error) {
if (
error instanceof Error &&
"code" in error &&
(error.code === "ENOENT" || error.code === "ENOTDIR")
)
return null;
// Classify platform-specific directory/socket errors after a failed open.
// No pathname read follows this check.
if (!statSync(filePath, { throwIfNoEntry: false })?.isFile()) return null;
throw error;
}
try {
if (!fstatSync(fd).isFile()) return null;
return readFileSync(fd);
} finally {
closeSync(fd);
}
}