JavaScript/ETC

protobuf arrayBuffer 우회하기

beforesol 2019. 10. 2. 15:44

ios safari에서 protobuf를 사용하면 arrayBuffer가 존재하지 않는다는 오류가 뜬다.

.then(blob => {
  	if (blob.arrayBuffer) {
        return blob.arrayBuffer();
      } else {
      return new Promise((resolve, reject) => {
        const fileReader = new FileReader();

        fileReader.onload = function() {
          resolve(fileReader.result);
        };
        fileReader.readAsArrayBuffer(blob);
      });
    }
  })

fileReader로 우회하면 된다.

 

참고: https://developer.mozilla.org/ko/docs/Web/API/FileReader/readAsArrayBuffer

 

FileReader.readAsArrayBuffer()

The FileReader interface's readAsArrayBuffer() method is used to start reading the contents of a specified Blob or File. When the read operation is finished, the readyState becomes DONE, and the loadend is triggered. At that time, the result attribute cont

developer.mozilla.org

도움: 우창님