UNPKG

@ethersphere/bee-js

Version:
18 lines 547 B
function isBufferArray(buffer) { return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer); } export async function prepareWebsocketData(data) { if (typeof data === 'string') { return new TextEncoder().encode(data); } if (data instanceof Buffer) { return new Uint8Array(data); } if (data instanceof ArrayBuffer) { return new Uint8Array(data); } if (isBufferArray(data)) { return new Uint8Array(Buffer.concat(data)); } throw new TypeError('unknown websocket data type'); }