# read()

Canonical URL: https://developers.iagenify.com/de/sdk/ref/local-files/read/
Language: de

`files.read(file) → Promise<Item & { content }>`

Liest eine Datei-Gesamt. Text kommt als String zurück, alles andere als Puffer — und der Typ wird durch die Erweiterung entschieden.

Status: free · whole file · string or Buffer

## Parameter {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `file` | string | erforderlich | Die zu lesende Datei, bezogen auf den Arbeitsbereich. |

```javascript
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
// }
```

## Welche du bekommst {#content}

| 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 |

> **Die Verlängerung entscheidet, nicht die Bytes**
>
> 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.

```javascript
const file = await pc.files.read(path);
const text = Buffer.isBuffer(file.content) ? file.content.toString("utf8") : file.content;
```

## Es liest die ganze Sache {#whole}

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 {#errors}

| 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. |

```javascript
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;
  }
}
```

- [Der Agent hat gelesen.](/de/sdk/agent/tools/read): Was ein Agent sieht – PDFs, Bilder, Audio und Video, die an der Drehung befestigt sind.
- [Lokale Dateien](/de/sdk/ref/local-files): Der Workspace, der Pfad und die Form, die jede Methode zurückgibt.

```python
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
# }
```

```python
file = pc.files.read(path)
text = file["content"].decode("utf-8") if isinstance(file["content"], bytes) else file["content"]
```

```python
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
```
