原文博客
{
var buffer = new ArrayBuffer(2)
var bytes = new Uint16Array(buffer)
bytes[0] = (65 << 8) + 66
var blob = new Blob([buffer], {
type: 'text/plain'
})
var dataUri = window.URL.createObjectURL(blob)
open(dataUri) // BA 受系统的字节序影响,小端法
}
{
let buffer = new ArrayBuffer(2)
let view = new DataView(buffer)
let value = (65 << 8) + 66
view.setUint16(0, value, /*true*/) // 或许默认使用大端法,true设置为小端法
var blob = new Blob([buffer], {
type: 'text/plain'
})
var dataUri = window.URL.createObjectURL(blob)
open(dataUri) // AB DataView不用考虑平台字节序问题
}