Mam WebSocket, który odbiera wiadomości binarne i chcę iterować po bajtach.Czytanie bajtów z blobu JavaScript otrzymanego przez WebSocket
wymyśliłem następującą funkcją konwersji ...
// Convert the buffer to a byte array.
function convert(data, cb) {
// Initialize a new instance of the FileReader class.
var fileReader = new FileReader();
// Called when the read operation is successfully completed.
fileReader.onload = function() {
// Invoke the callback.
cb(new Uint8Array(this.result));
};
// Starts reading the contents of the specified blob.
fileReader.readAsArrayBuffer(data);
}
To działa, ale wydajność jest straszna. Czy istnieje lepszy sposób na zezwolenie na czytanie bajtów?
Jakiej przeglądarki używasz? – karthick
Google Chrome to przeglądarka, której używam. –
co to jest "dane" – Esailija