关于用JS解码Base64或二进制流8位制的编码方法之一

const blob = window.atob(value) // Base64 string converted to a char array
const fLen = blob.length / Float32Array.BYTES_PER_ELEMENT // How many floats can be made, but be even
const dView = new DataView(
new ArrayBuffer(Float32Array.BYTES_PER_ELEMENT)
) // ArrayBuffer/DataView to convert 4 bytes into 1 float.
let fAry = new Float32Array(fLen) // Final Output at the correct size
let p = 0 // Position
 
for (let j = 0; j < fLen; j++) {
p = j * 4
dView.setUint8(0, blob.charCodeAt(p))
dView.setUint8(1, blob.charCodeAt(p + 1))
dView.setUint8(2, blob.charCodeAt(p + 2))
dView.setUint8(3, blob.charCodeAt(p + 3))
fAry[j] = dView.getFloat32(0, true)
}
console.log(fAry) 

value = "AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA"

value = 'AAAAAA==' 

posted @ 2019-08-20 16:44  爱上大树的小猪  阅读(1871)  评论(0编辑  收藏  举报