Skip to content

Download files

Request bytes from files.read and save them with the filesystem API of your application:

mjs
import { writeFile } from "node:fs/promises";
import { URL } from "node:url";
import { Sandbox } from "@abox-dev/sdk";

const sandbox = await Sandbox.create();

try {
  await sandbox.files.write("/tmp/report.txt", "Report is ready");
  const report = await sandbox.files.read("/tmp/report.txt", {
    format: "bytes",
  });
  await writeFile(new URL("./report.txt", import.meta.url), report);
  console.log("Downloaded report.txt");
} finally {
  await sandbox.kill();
}

Use the streamed read format for files that should not be buffered entirely in memory.