Parâmetros
filestringobrigatórioIl file da lere, in parentesc al l'espazio de lavoro.
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
# }Quale ovedes
| Tipomime | il contenuto è |
|---|---|
text/* | una stringa (UTF-8) |
application/json · application/xml · application/yaml | una corda |
text/javascript · text/typescript | una corda |
| Toto il resto — immagini, PDFs, audio, archivi | a a buf |
La prolunga decide, non i bytes
Un JSON carico utile salvat as .dat retorna come un Buffer, e un binario salvat as .txt retorna as una stringa distruse. Nome files per o che sono, o test Buffer.isBuffer(content) prima d'utilizare il risultato.
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"]Lee l'intera cosa
Non è offset, non lunghie e non fluente: il file è caricat in memoria. Per un file grande, legîlo con Node proprio sistema de file API e use list() per trovar il suo percorso — size dice antecipat lo che sta per caricare.
Erros
| Código | Status | Quando |
|---|---|---|
| path_not_found | 404 | Nessuna listina in quel sentier. |
| not_a_file | 400 | Il percorso nomi un dossier — use list(). |
| invalid_path | 400 | Absolute, fuori del luogo de lavoro, o la raiz del luogo de lavoro. |
| local_files_require_node | 400 | O ambiente de execução não tem sistema de arquivos. |
| storage_not_on_this_machine | 409 | Un altro computer's stoccage. |
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