The Bun.file() function accepts a path and returns a BunFile instance. The BunFile class extends Blob and allows you to lazily read the file in a variety of formats. Use .text() to read the contents as a string.
1---2name: bun-read-a-file-as-a-string3description: Read a file as a string4---56# Read a file as a string78The `Bun.file()` function accepts a path and returns a `BunFile` instance. The `BunFile` class extends `Blob` and allows you to lazily read the file in a variety of formats. Use `.text()` to read the contents as a string.910```ts theme={"theme":{"light":"github-light","dark":"dracula"}}11const path = "/path/to/file.txt";12const file = Bun.file(path);1314const text = await file.text();15// string16```1718***1920Any relative paths will be resolved relative to the project root (the nearest directory containing a `package.json` file).2122```ts theme={"theme":{"light":"github-light","dark":"dracula"}}23const path = "./file.txt";24const file = Bun.file(path);25```
Run npx skillmds@latest add jarle/bun-read-a-file-as-a-string in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Read a file as a string It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
jarle (@jarle) published this skill. Their other Agent Skills are listed on their SkillMD profile.