Bun Write a ReadableStream to a file

Write a ReadableStream to a file

jarle Updated

File contents

Write a ReadableStream to a file

To write a ReadableStream to disk, first create a Response instance from the stream. This Response can then be written to disk using Bun.write().

const stream: ReadableStream = ...;
const path = "./file.txt";
const response = new Response(stream);

await Bun.write(path, response);

See Docs > API > File I/O for complete documentation of Bun.write().

jarle/bun-skills/tree/main/skills/bun-guides-write-file-stream commit 663e6cc86d

Frequently asked questions

npx skillmds@latest add jarle/bun-write-a-readablestream-to-a-file