# read()

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

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

Il testo torna come una string, qualsiasi altra cosa come un Buffer — e il tipo è decisa dalla extensión.

Status: free · whole file · string or Buffer

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `file` | string | obrigatório | Il file da lere, in parentesc al l'espazio de lavoro. |

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

## Quale ovedes {#content}

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

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

## Lee l'intera cosa {#whole}

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

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

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

- [L'agente let](/pt/sdk/agent/tools/read): Ce vee un agent — PDFs, immagini, audio e video attachòs al turn.
- [Fichîes Locales](/pt/sdk/ref/local-files): L'espazio di lavoro, le regole del percorso, e la forma ogni metodo retorna.

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