Files
Read, write, upload, and download runtime files.
FileManager declaration
Section titled “FileManager declaration”class FileManagerFileManager access
Section titled “FileManager access”This type is created by the SDK; do not construct it directly.
const manager = runtime.files;FileManager methods
Section titled “FileManager methods”download()
Section titled “download()”Download a runtime file or directory without buffering it in memory.
FileManager.download(src: string, dst: string): Promise<void>Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”Promise<void>
Examples
Section titled “Examples”await runtime.files.download("/workspace/results", "./artifacts/");read()
Section titled “read()”Read a file from the runtime as bytes.
FileManager.read(path: string, maxBytes?: number | null): Promise<Uint8Array<ArrayBufferLike>>Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
path |
string |
Required |
Path inside the runtime. |
maxBytes? |
number | null |
Optional |
Maximum number of bytes to return. |
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBufferLike>>
readText()
Section titled “readText()”Read a UTF-8 text file from the runtime.
FileManager.readText(path: string, maxBytes?: number | null): Promise<string>Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
path |
string |
Required |
Absolute path inside the runtime. |
maxBytes? |
number | null |
Optional |
Optional maximum number of bytes to read. |
Returns
Section titled “Returns”Promise<string>— Decoded UTF-8 text.
Examples
Section titled “Examples”const packageJson = await runtime.files.readText("/workspace/package.json");console.log(JSON.parse(packageJson).name);upload()
Section titled “upload()”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>Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
src |
string |
Required |
Local source path. |
dst |
string |
Required |
Destination path inside the runtime. |
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”ErrorIf the local source is not a file or directory.
Examples
Section titled “Examples”await runtime.files.upload("./src", "/workspace/src");await runtime.files.upload("./build.tar.zst", "/workspace/artifacts/");write()
Section titled “write()”Write bytes or text to a runtime file.
FileManager.write( path: string, content: string | Uint8Array<ArrayBufferLike>, options: { executable?: boolean } = {},): Promise<void>Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”Promise<void>
