(data: object, blob?: Blob)
| 380 | const JSON_AND_BINARY_DELIMITER = 0xFF |
| 381 | |
| 382 | async function encodeRawMessage(data: object, blob?: Blob): Promise<EncodedMessage> { |
| 383 | const json = stringifyJSON(data) |
| 384 | |
| 385 | if (blob === undefined || blob.size === 0) { |
| 386 | return json |
| 387 | } |
| 388 | |
| 389 | return readAsBuffer(new Blob([ |
| 390 | new TextEncoder().encode(json), |
| 391 | new Uint8Array([JSON_AND_BINARY_DELIMITER]), |
| 392 | blob, |
| 393 | ])) |
| 394 | } |
| 395 | |
| 396 | async function decodeRawMessage(raw: EncodedMessage): Promise<{ json: any, buffer?: Uint8Array }> { |
| 397 | if (typeof raw === 'string') { |
no test coverage detected