js arraybuffer转string

1,819 阅读1分钟

ab2str(buf) {

    const bytes = new Uint8Array(buf)

   let text = ''

   for (let i = 0; i < bytes.length; i++) {

   text += '%' + bytes[i].toString(16)

   }

     return decodeURIComponent(text)

},