0

So I was wondering why this Blob object has a size of 5:

var x = new Uint8Array(2);
x[0] = 255;
x[1] = 10;
console.log("Typed array length is " + x.length + ".")
console.log("Typed array byte length is " + x.byteLength + ".")
console.log("Blob size is " + new Blob(x).size + ' "bytes".')

For me it makes no sense, because an Uint8Array element can be stored inside a byte. (Uint8Array items can handle a value from 0 to 255.)

Also, changing x[0] or x[1] seems to change new Blob(x).size. x.byteLength, however, gives the expected result to me.

I can't find any explanation for this, even though I've searched everywhere.

isherwood
  • 58,414
  • 16
  • 114
  • 157
D. Pardal
  • 6,173
  • 1
  • 17
  • 37

1 Answers1

2

The Blob constructor takes an array of buffers, not a single buffer. Your current code works the same as

new Blob(["255", "10"])

which is why you get a size of 5. You would need to write

var x = new Uint8Array([255, 10]);
new Blob([x])
//       ^ ^
Bergi
  • 630,263
  • 148
  • 957
  • 1,375