Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 33x 2x 2x 2x | import type { Data } from 'ws' function isBufferArray(buffer: unknown): buffer is Buffer[] { return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer) } export async function prepareWebsocketData(data: Data | Blob): Promise<Uint8Array> | never { Iif (typeof data === 'string') { return new TextEncoder().encode(data) } if (data instanceof Buffer) { return new Uint8Array(data) } Iif (data instanceof ArrayBuffer) { return new Uint8Array(data) } Iif (isBufferArray(data)) { return new Uint8Array(Buffer.concat(data)) } throw new TypeError('unknown websocket data type') } |