const rankSize = 16

function blobLength(b) {
  if (typeof b.byteLength !== 'undefined') return b.byteLength
  if (typeof b.size !== 'undefined') return b.size
  return b.length
}

export default class ChunkedBlob {

  constructor() {
    this.size = 0
    this.ranks = [[]]
  }

  add(b) {
    this.size += blobLength(b)
    this.ranks[0].push(b)

    for (let i = 0; i < this.ranks.length; i++) {
      let rank = this.ranks[i]
      if (rank.length === rankSize) {
        this.ranks[i + 1] = this.ranks[i + 1] || []
        this.ranks[i + 1].push(new Blob(rank))
        this.ranks[i] = []
      }
    }
  }

  toBlob() {
    let allRanks = [].concat(...this.ranks)
    return new Blob(allRanks)
  }

}

@@ -264,18 +264,16 @@
 anks = %5B
-%5B%5D
 %5D%0A  %7D%0A%0A 
@@ -331,11 +331,8 @@
 anks
-%5B0%5D
 .pus
@@ -340,329 +340,25 @@
 (b)%0A
-%0A    for (let i = 0; i %3C this.ranks.length; i++) %7B%0A      let rank = this.ranks%5Bi%5D%0A      if (rank.length === rankSize) %7B%0A        this.ranks%5Bi + 1%5D = this.ranks%5Bi + 1%5D %7C%7C %5B%5D%0A        this.ranks%5Bi + 1%5D.push(new Blob(rank))%0A        this.ranks%5Bi%5D = %5B%5D%0A      %7D%0A    %7D%0A  %7D%0A%0A  toBlob() %7B%0A    let allRanks = %5B%5D.concat(...this.ranks)
+  %7D%0A%0A  toBlob() %7B
 %0A   
@@ -378,12 +378,14 @@
 lob(
-allR
+this.r
 anks
@@ -392,9 +392,8 @@
 )%0A  %7D%0A%0A%7D
-%0A

Use one big array for all blobs instead of ranks.