fix(virtualstream): support reconstituting smartjson encoded binary stream chunks

This commit is contained in:
2026-05-08 10:38:15 +00:00
parent 057085b17b
commit 51f54601f1
5 changed files with 43 additions and 2 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@api.global/typedrequest',
version: '3.3.0',
version: '3.3.1',
description: 'A TypeScript library for making typed requests towards APIs, including facilities for handling requests, routing, and virtual stream handling.'
}
+9
View File
@@ -168,6 +168,15 @@ export class VirtualStream<T = Uint8Array> implements plugins.typedRequestInterf
return data;
}
if (typeof data === 'object') {
// Handle @push.rocks/smartjson encoded binary data.
if (data.type === 'EncodedBuffer' && typeof data.data === 'string' && data.data.startsWith('base64:')) {
const base64Data = data.data.slice('base64:'.length);
if (typeof Buffer !== 'undefined') {
const buffer = Buffer.from(base64Data, 'base64');
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
}
return new Uint8Array(Array.from(atob(base64Data)).map((char) => char.charCodeAt(0)));
}
// Handle JSON-serialized Node.js Buffer: {type: "Buffer", data: [...]}
if (data.type === 'Buffer' && Array.isArray(data.data)) {
return new Uint8Array(data.data);