Parameter
filestringerforderlichDie zu lesende Datei, bezogen auf den Arbeitsbereich.
const file = await pc.files.read("Launch plan/brief.md");
// {
// name: "brief.md",
// path: "Launch plan/brief.md",
// type: "file",
// size: 1284,
// mimeType: "text/markdown",
// modifiedAt: "2026-10-07T09:12:44.000Z",
// content: "# Brief\n\nShip in March." // a string
// }file = pc.files.read("Launch plan/brief.md")
# {
# "name": "brief.md",
# "path": "Launch plan/brief.md",
# "size": 1284,
# "content": "# Brief\n\nShip in March." # a str
# }Welche du bekommst
| mimeType | Inhalt |
|---|---|
text/* | eine Zeichenkette (UTF-8) |
application/json · application/xml · application/yaml | eine Zeichenkette |
text/javascript · text/typescript | eine Zeichenkette |
| Alles andere — Bilder, PDFs, Audio, Archive | ein Puffer |
A JSON payload gespeichert als .dat kommt als Puffer zurück, und eine binäre gespeichert als .txt kommt als chaotischer String zurück. Buffer.isBuffer(content) vor der Verwendung des Ergebnisses.
const file = await pc.files.read(path);
const text = Buffer.isBuffer(file.content) ? file.content.toString("utf8") : file.content;file = pc.files.read(path)
text = file["content"].decode("utf-8") if isinstance(file["content"], bytes) else file["content"]Es liest die ganze Sache
Es gibt keinen Offset, keine Länge und keinen Stream: die Datei wird in den Speicher geladen. Für einen großen, lesen Sie es mit NodeDas eigene Dateisystem API und Verwendung list() seinen Weg zu finden — size sagt Ihnen im Voraus, was Sie zu laden sind.
Fehler
| Code | Status | Wann |
|---|---|---|
| path_not_found | 404 | Keine Akte auf diesem Pfad. |
| not_a_file | 400 | Der Pfad nennt einen Ordner — verwenden list(). |
| invalid_path | 400 | Absolut, außerhalb des Arbeitsbereichs oder der Workspace-Root. |
| local_files_require_node | 400 | Die Laufzeitumgebung hat kein Dateisystem. |
| storage_not_on_this_machine | 409 | Ein weiterer Computerspeicher. |
import { IaGenifyError } from "iagenify";
async function readOrNull(files, path) {
try {
return await files.read(path);
} catch (err) {
if (err instanceof IaGenifyError && (err.code === "path_not_found" || err.code === "not_a_file")) return null;
throw err;
}
}from iagenify import IaGenifyError
def read_or_none(files, path):
try:
return files.read(path)
except IaGenifyError as error:
if error.code in ("path_not_found", "not_a_file"):
return None
raise