如何将ArrayBuffer保存在json文件中?我为此使用电子配置,但在 config.json 中我找到了“{}”。我尝试将(代码)ArrayBuffer 转换为字符串,但无法将字符串转换为ArrayBuffer。
put: function(key, value) {
//value = { prop1: <ArrayBuffer>, prop2: <ArrayBuffer> }
if (key === undefined || value === undefined || key === null || value === null)
return;
var prop1Str,prop2Str;
prop1Str = this.ab2str(value.prop1);
prop2Str = this.ab2str(value.prop2);
var chValue = {prop1:prop1Str, prop2:prop2Str};
config.set(key,chValue);
console.log(value.prop1 === this.str2ab(config.get(key).prop1)); //===> FALSE
},
ab2str: function(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
},
str2ab: function(str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; …
Run Code Online (Sandbox Code Playgroud)