@ethersphere/bee-js
Version:
Javascript client for Bee
23 lines (22 loc) • 746 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareWebsocketData = void 0;
function isBufferArray(buffer) {
return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
}
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');
}
exports.prepareWebsocketData = prepareWebsocketData;