Skip to content

Commit dd580e3

Browse files
committed
feat(typescript): handle binary responses with ArrayBuffer
Previously, binary responses were processed with response.text(), which corrupts bytes > 127 due to UTF-8 encoding issues. Now the SDK detects binary content types and uses response.arrayBuffer() to preserve byte integrity for: - application/octet-stream - image/* - audio/* - video/*
1 parent 169286f commit dd580e3

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

xdk-gen/templates/typescript/main_client.j2

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,14 @@ export class Client {
421421
const rawData = await response.json();
422422
// Transform snake_case keys to camelCase to match TypeScript conventions
423423
data = transformKeys<T>(rawData);
424+
} else if (contentType && (
425+
contentType.includes('application/octet-stream') ||
426+
contentType.includes('image/') ||
427+
contentType.includes('audio/') ||
428+
contentType.includes('video/')
429+
)) {
430+
// Return ArrayBuffer for binary content types to preserve byte integrity
431+
data = await response.arrayBuffer() as T;
424432
} else {
425433
data = await response.text() as T;
426434
}

0 commit comments

Comments
 (0)