Paramètres
filestringobligatoireLe fichier à lire, relatif à l'espace de travail.
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
# }Lequel tu as
| Type de mime | le contenu est |
|---|---|
text/* | une chaîne de caractères (UTF-8) |
application/json · application/xml · application/yaml | une chaîne |
text/javascript · text/typescript | une chaîne |
| Tout le reste — images, PDF, audio, archives | a Bouffer |
A JSON charge utile enregistrée sous .dat revient sous forme de tampon, et un binaire sauvegardé sous .txt revient sous forme de chaîne manglée. Nommer les fichiers pour ce qu'ils sont, ou tester Buffer.isBuffer(content) avant d'utiliser le résultat.
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"]Ça lit tout.
Il n'y a pas de décalage, pas de longueur et pas de flux : le fichier est chargé en mémoire. Pour un grand, lisez-le avec le propre système de fichiers de Node API et utilisation list() pour trouver son chemin size vous dit à l'avance ce que vous allez charger.
Erreurs
| Code | Statut | Quand |
|---|---|---|
| path_not_found | 404 | Pas de fichier sur ce chemin. |
| not_a_file | 400 | Le chemin nomme un dossier — utiliser list(). |
| invalid_path | 400 | Absolue, hors de l'espace de travail, ou la racine de l'espace de travail. |
| local_files_require_node | 400 | L’environnement d’exécution ne dispose pas de système de fichiers. |
| storage_not_on_this_machine | 409 | Un autre ordinateur est stocké. |
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