Z ZPI 文档 v0.3.8
介绍页

源码

packages/coding-agent/src/core/tools/pi/utils/read-file.ts

typescript14 行查看原文
import { constants } from "node:fs";
import { open } from "node:fs/promises";

/** Inspect the opened handle without waiting for a FIFO writer, including through symlinks. */
export async function readRegularFile(path: string): Promise<Buffer> {
  const file = await open(path, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
  try {
    if (!(await file.stat()).isFile()) throw new Error("File mutation requires a regular file");
    return await file.readFile();
  } finally {
    await file.close();
  }
}