# read()

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

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

Reads a file whole. Text comes back as a string, anything else as a Buffer — and the type is decided by the extension.

Status: free · whole file · string or Buffer

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `file` | string | required | The file to read, relative to the workspace. |

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

## Which one you get {#content}

| mimeType | content is |
| --- | --- |
| `text/*` | a string (UTF-8) |
| `application/json` · `application/xml` · `application/yaml` | a string |
| `text/javascript` · `text/typescript` | a string |
| Everything else — images, PDFs, audio, archives | a Buffer |

> **The extension decides, not the bytes**
>
> A JSON payload saved as .dat comes back as a Buffer, and a binary saved as .txt comes back as a mangled string. Name files for what they are, or test Buffer.isBuffer(content) before using the result.

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

## It reads the whole thing {#whole}

There is no offset, no length and no stream: the file is loaded into memory. For a large one, read it with Node's own filesystem API and use `list()` to find its path — `size` tells you in advance what you are about to load.

## Errors {#errors}

| Code | Status | When |
| --- | --- | --- |
| path_not_found | 404 | No file at that path. |
| not_a_file | 400 | The path names a folder — use `list()`. |
| invalid_path | 400 | Absolute, outside the workspace, or the workspace root. |
| local_files_require_node | 400 | The runtime has no filesystem. |
| storage_not_on_this_machine | 409 | Another computer's storage. |

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

- [The agent's read](/sdk/agent/tools/read): What an agent sees — PDFs, images, audio and video attached to the turn.
- [LocalFiles](/sdk/ref/local-files): The workspace, the path rules, and the shape every method returns.

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