10LOC

#file-io

Bunintermediate

Use Bun.write for zero-dependency file output

import { write } from "bun";

export const saveJsonReport = (path: string, report: Record<string, unknown>) =>
  write(path, JSON.stringify(report, null, 2) + "\n");

Write files in Bun without extra dependencies or shelling out.

Bunintermediate

Streaming a file response with Bun.file(), no extra deps

import { serve, file } from "bun";

const server = serve({
  async fetch(req) {
    const pathname = new URL(req.url).pathname;

Bun.file() returns a lazy file handle that streams straight into a Response, so serving a large file never buffers it fully in memory.