gpt4 book ai didi

javascript - Base 64 字符串有时会神奇地变大......

转载 作者:行者123 更新时间:2023-12-03 06:49:17 25 4
gpt4 key购买 nike

我正在处理最奇怪的问题。我有一个大字符串(大约 500 万字节),我正在尝试缩小它。在缩小它之前,我尝试像这样“重建”它:

  for(var i = 0; i < data.length; i++){
var bb64 = "";
var sb64 = "";

//the big-ass string (~5 million bytes)
bb64 = data[i];
//initially one sixth of the big-ass string
sb64 = bb64.substring(0, bb64.length/6);

var start = bb64.length/6;
var end = bb64.length;

//for testing, re-add the remaining 5/6 characters
for(var x = start; x < end; x++){
sb64 += bb64[x]
}

//theoretically, these should be the same for each iteration of i
console.log(bb64.length);
console.log(sb64.length);

/*actual results:
i = 0:
bb64:5458944
sb64:5458944

i = 1:
bb64:5563292
sb64:42651908

i = 2:
bb64:5555276
sb64:42590452
*/
}

然后我用其他大字符串(约 300 万字节)对其进行了测试,结果是:

i = 0:
bb64:3132968
sb64:24019424

i = 1:
bb64:3635916
sb64:3635916

i = 2:
bb64:3791560
sb64:29068632

有人知道到底发生了什么吗?

提前致谢!

最佳答案

“length/6”除法未进行舍入,使用非舍入值作为键会产生不可预测的结果。

关于javascript - Base 64 字符串有时会神奇地变大......,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37588143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com