← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/read-file.ts
29 lines · 709 B · TypeScriptimport { assertBoxId, boxRequest, failure, type Result } from './client.ts'
export type ReadFileInput = {
boxId: string
/** Path to read inside the box. */
path: string
encoding?: 'utf8' | 'base64'
}
export type ReadFileOutput = {
success: boolean
path: string
encoding: 'utf8' | 'base64'
size: number
content: string
}
/** Read one file out of a box. */
export default async function readFile(
input: ReadFileInput,
): Promise<Result<ReadFileOutput>> {
const invalid = assertBoxId(input?.boxId)
if (invalid) return failure<ReadFileOutput>(invalid)
return boxRequest<ReadFileOutput>({
path: '/boxes/' + input.boxId + '/files',
query: { path: input.path, encoding: input.encoding },
})
}