# Write a ReadableStream to a file (/guides/write-file/stream)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 180 · updated: 2026-09-23 -->
Related: [Append content to a file](/guides/write-file/append.md), [Write a string to a file](/guides/write-file/basic.md), [Write a Blob to a file](/guides/write-file/blob.md), [Write a file to stdout](/guides/write-file/cat.md), [Copy a file to another location](/guides/write-file/file-cp.md), [Write a file incrementally](/guides/write-file/filesink.md)

To write a `ReadableStream` to disk, call `.writer()` on a `BunFile` to get a [`FileSink`](/runtime/file-io#incremental-writing-with-filesink). The stream is an async iterable, so write each of its chunks to the `FileSink` with `for await`. Then call `.end()` to flush the buffer and close the file.

```ts
const stream: ReadableStream = ...;
const path = "./file.txt";
const writer = Bun.file(path).writer();

for await (const chunk of stream) {
  writer.write(chunk);
}

await writer.end();
```

***

`.writer()` creates the file if it doesn't exist, but does not truncate an existing file. If the file may already exist, delete it first.

***

See [`FileSink`](/runtime/file-io#incremental-writing-with-filesink).
