← Public packages
@cameronpak/box
Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.
src/get-snapshot-file.ts
25 lines · 892 B · TypeScriptimport { assertSnapshotId, boxRequest, failure, type BinaryPayload, type Result } from './client.ts'
export type GetSnapshotFileInput = {
snapshotId: string
/** File or folder path inside the snapshot. Empty or omit for the whole snapshot as tar. */
path?: string
}
/**
* Stream a single file's bytes, or a folder subtree as a tar archive, out of a
* snapshot. The box can be stopped; the machine is never contacted.
* The API returns application/octet-stream or application/x-tar; this export
* base64-encodes the body.
*/
export default async function getSnapshotFile(
input: GetSnapshotFileInput,
): Promise<Result<BinaryPayload>> {
const invalid = assertSnapshotId(input?.snapshotId)
if (invalid) return failure<BinaryPayload>(invalid)
return boxRequest<BinaryPayload>({
path: '/snapshots/' + input.snapshotId + '/files',
query: { path: input.path },
raw: true,
})
}