基础64弦神奇地变得更大..有时

时间:2016-06-02 09:42:05

标签: javascript loops base64

我正在处理最奇怪的问题。我有一个大字符串(大约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

任何人任何线索到底是什么......?

提前致谢!

1 个答案:

答案 0 :(得分:1)

&#34;长度/ 6&#34;除非舍入,使用非舍入值作为键具有不可预测的结果。