mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-05 05:37:09 +00:00
* fix(cli): read Studio bundle files through checked descriptors * fix(cli): pin Studio signature and runtime artifact reads
27 lines
853 B
TypeScript
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);
|
|
}
|
|
}
|