Skip to content

Files

Read, write, upload, and download runtime files.

class FileManager

This type is created by the SDK; do not construct it directly.

const manager = runtime.files;

Download a runtime file or directory without buffering it in memory.

FileManager.download(src: string, dst: string): Promise<void>
Name Type Default Description
src string Required Source path inside the runtime.
dst string Required Local destination path. A trailing slash or existing directory downloads beneath that directory using the source basename.
  • Promise<void>
await runtime.files.download("/workspace/results", "./artifacts/");

Read a file from the runtime as bytes.

FileManager.read(path: string, maxBytes?: number | null): Promise<Uint8Array<ArrayBufferLike>>
Name Type Default Description
path string Required Path inside the runtime.
maxBytes? number | null Optional Maximum number of bytes to return.
  • Promise<Uint8Array<ArrayBufferLike>>

Read a UTF-8 text file from the runtime.

FileManager.readText(path: string, maxBytes?: number | null): Promise<string>
Name Type Default Description
path string Required Absolute path inside the runtime.
maxBytes? number | null Optional Optional maximum number of bytes to read.
  • Promise<string> — Decoded UTF-8 text.
const packageJson = await runtime.files.readText("/workspace/package.json");
console.log(JSON.parse(packageJson).name);

Stream a local file or directory to the runtime without buffering it in memory.

Files are committed through a temporary sibling after their byte count is verified. Directories are extracted into a staging directory and moved into place only after the complete archive arrives.

FileManager.upload(src: string, dst: string): Promise<void>
Name Type Default Description
src string Required Local source path.
dst string Required Destination path inside the runtime.
  • Promise<void>
  • Error If the local source is not a file or directory.
await runtime.files.upload("./src", "/workspace/src");
await runtime.files.upload("./build.tar.zst", "/workspace/artifacts/");

Write bytes or text to a runtime file.

FileManager.write(
path: string,
content: string | Uint8Array<ArrayBufferLike>,
options: { executable?: boolean } = {},
): Promise<void>
Name Type Default Description
path string Required Path inside the runtime.
content string | Uint8Array<ArrayBufferLike> Required Bytes or text to write.
options { executable?: boolean } {} Options that control the operation.
  • Promise<void>