バイナリ メッセージを受信する WebSocket があり、バイトを反復処理したい。
次の変換関数を思いつきました...
// 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);
}
これは機能しますが、パフォーマンスはひどいものです。バイトの読み取りを許可するより良い方法はありますか?