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 locally.

FileManager.download(src: string, dst: string): Promise<void>
NameTypeDefaultDescription
srcstringRequiredSource path.
dststringRequiredDestination path.
  • Promise<void>

Read a file from the runtime as bytes.

FileManager.read(path: string, maxBytes?: number | null): Promise<Uint8Array<ArrayBufferLike>>
NameTypeDefaultDescription
pathstringRequiredPath inside the runtime.
maxBytes?number | nullOptionalMaximum 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>
NameTypeDefaultDescription
pathstringRequiredAbsolute path inside the runtime.
maxBytes?number | nullOptionalOptional 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);

Upload a local file or directory to the runtime.

FileManager.upload(src: string, dst: string): Promise<void>
NameTypeDefaultDescription
srcstringRequiredLocal source path.
dststringRequiredDestination path inside the runtime.
  • Promise<void>
  • Error If the local source is not a file or directory.
await runtime.files.upload("./src", "/workspace/src");

Write bytes or text to a runtime file.

FileManager.write(
path: string,
content: string | Uint8Array<ArrayBufferLike>,
options: { executable?: boolean } = {},
): Promise<void>
NameTypeDefaultDescription
pathstringRequiredPath inside the runtime.
contentstring | Uint8Array<ArrayBufferLike>RequiredBytes or text to write.
options{ executable?: boolean }{}Options that control the operation.
  • Promise<void>