fix(virtualstream): support reconstituting smartjson encoded binary stream chunks
This commit is contained in:
+15
-1
@@ -68,6 +68,21 @@ tap.test('should fire a request', async () => {
|
||||
expect(response.surname).toEqual('wow');
|
||||
});
|
||||
|
||||
tap.test('should reconstitute serialized stream chunks', async () => {
|
||||
const reconstituteBinaryData = (typedrequest.VirtualStream as any).reconstituteBinaryData as (dataArg: any) => Uint8Array;
|
||||
const encodedBuffer = reconstituteBinaryData({
|
||||
type: 'EncodedBuffer',
|
||||
data: `base64:${Buffer.from('hello').toString('base64')}`,
|
||||
});
|
||||
const serializedBuffer = reconstituteBinaryData({
|
||||
type: 'Buffer',
|
||||
data: [104, 101, 108, 108, 111],
|
||||
});
|
||||
|
||||
expect(new TextDecoder().decode(encodedBuffer)).toEqual('hello');
|
||||
expect(new TextDecoder().decode(serializedBuffer)).toEqual('hello');
|
||||
});
|
||||
|
||||
tap.test('should allow VirtualStreams', async () => {
|
||||
const newRequestingVS = new typedrequest.VirtualStream();
|
||||
const newRespondingVS = new typedrequest.VirtualStream();
|
||||
@@ -92,7 +107,6 @@ tap.test('should allow VirtualStreams', async () => {
|
||||
|
||||
newRequestingVS.sendData(Buffer.from('hello'));
|
||||
const data: any = await generatedRequestingVS.fetchData();
|
||||
// Data may arrive as Uint8Array or as JSON-serialized Buffer {type: "Buffer", data: [...]}
|
||||
const resolvedData = data instanceof Uint8Array || Buffer.isBuffer(data)
|
||||
? data
|
||||
: data?.type === 'Buffer' && Array.isArray(data.data)
|
||||
|
||||
Reference in New Issue
Block a user