fix(virtualstream): support reconstituting smartjson encoded binary stream chunks
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user