# read()

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

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

يقرأ ملفّ كامل. النص يعود كسلسلة، أي شيء آخر كـ baver -- والنوع هو الذي يقرره التمديد.

Status: free · whole file · string or Buffer

## المعاملات {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `file` | string | مطلوب | الملف المراد قراءته، نسبي إلى مساحة العمل. |

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

## و التي ستحصل على {#content}

| مُمType | كان المُكون |
| --- | --- |
| `text/*` | :UTF-8) |
| `application/json` · `application/xml` · `application/yaml` | هذا |
| `text/javascript` · `text/typescript` | هذا |
| كل شيء آخر - الصور، وأجهزة الدفاع الشعبي، والصوت، والمحفوظات | )أ( |

> **يقرر التمديد، لا يقرر**
>
> 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;
```

## انه يقرأ كل شيء {#whole}

لا يوجد مقابلة ، لا طول ولا جدول: الملف هو مُحمّل إلى ذاكرة. لكبير ، اقرأه مع Nodeland fi API استخدام `list()` - - - - - - - - - - - - - - - - - - `size` تخبرك مسبقاً بما أنت على وشك تحميله

## الأخطاء {#errors}

| الرمز | الحالة | متى |
| --- | --- | --- |
| path_not_found | 404 | لا ملف في ذلك المسار. |
| not_a_file | 400 | ملف مجلد `list()`. |
| invalid_path | 400 | مُطلقة، خارج مساحة العمل، أو جذر مكان العمل. |
| local_files_require_node | 400 | لا تتوفر في بيئة التشغيل منظومة ملفات. |
| storage_not_on_this_machine | 409 | حاسوب آخر يخزن |

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

- [قراءة الوكيل](/ar/sdk/agent/tools/read): وما يراه الوكيل — ادوات الدفاع الشعبي ، الصور ، الصوت والفيديو المرتبطة بالدور .
- [محارف محلية](/ar/sdk/ref/local-files): مساحة العمل، قواعد المسار، والشكل كل طريقة ترجع.

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