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 locally.
FileManager.download(src: string, dst: string): Promise<void>Parameters
Section titled “Parameters”| Name | Type | Default | Description |
|---|---|---|---|
src | string | Required | Source path. |
dst | string | Required | Destination path. |
Returns
Section titled “Returns”Promise<void>
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()”Upload a local file or directory to the runtime.
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");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>