2026-10-10 04:14:28 +08:00
|
|
|
import { openRegularFile } from "../filesystem/RegularFile.js";
|
2026-10-09 13:49:54 -04:00
|
|
|
|
|
|
|
|
/** Admit a regular file without waiting for a pipe, then read its verified handle. */
|
|
|
|
|
export const readRegularFile = async (
|
|
|
|
|
path: string,
|
|
|
|
|
signal?: AbortSignal,
|
|
|
|
|
): Promise<Buffer> => {
|
2026-10-10 04:14:28 +08:00
|
|
|
const handle = await openRegularFile(path, { symlinks: "follow", signal });
|
2026-10-09 13:49:54 -04:00
|
|
|
try {
|
|
|
|
|
const bytes = await handle.readFile({ signal });
|
|
|
|
|
signal?.throwIfAborted();
|
|
|
|
|
return bytes;
|
|
|
|
|
} finally {
|
|
|
|
|
await handle.close();
|
|
|
|
|
}
|
|
|
|
|
};
|