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
+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);