Typorithm · easy

Bun.file & write

bun-file-iobunfileblobio
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Bun.file & write

0%

Bun APIs

Bun.file returns a lazy BunFile (a Web-standard Blob) that reads on demand with .text(), .json(), or .arrayBuffer(). Bun.write writes data to a path with optimized system calls.

Bun.file(path) returns a lazy BunFile that is also a Web-standard Blob — creating it touches no disk; the read happens only when you call .text(), .json(), or .arrayBuffer().

Because reads are asynchronous, you await the Blob method: const text = await Bun.file("data.json").text() resolves to the file's contents as a string.

Bun.write(path, data) writes strings, Blobs, or other BunFiles to disk, choosing the fastest underlying system call for the source.

01

Bun.file is lazy — no read until you ask.

02

BunFile is a Web-standard Blob with .text()/.json().

03

Bun.write writes data with optimized syscalls.

const text = await Bun.file("data.json").text();
await Bun.write("out.txt", "hi");

Read the implementation

Connect each part of the code to the concept before you type.

1. Lazy file handle

Bun.file returns a lazy BunFile (a Blob) — no disk read happens until you ask for its contents.

Bun.file("data.json")

2. Read as text

text() is the Web-standard Blob method that reads the file and resolves to a string.

.text()

3. Await the read

Reading is asynchronous, so you await the promise that text() returns.

await Bun.file("data.json").text()

4. Fast write

Bun.write writes data to a path using the fastest system call available.

await Bun.write("out.txt", "hi");

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Bun.file & write: Lesson & Practice · Typorithm | ApplyDjinn