此代码将数组缓冲区转换为字符串,反之亦然
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint16Array(buf));
}
function str2ab(str) {
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
答案 0 :(得分:0)
我认为 Python bytearray()
可以胜任。
您可以参考此页面了解更多信息:https://www.programiz.com/python-programming/methods/built-in/bytearray