I defined a simple Uint8Array with values [0,1,2,3]. Then I made a Blob object with this binary data, and read from fileReader with readAsArrayBuffer method. But when I got the values from blob, it contains [48, 49, 50, 51], not [0,1,2,3]!
This is the source code:
var bin = new Uint8Array(4);
bin[0] = 0;
bin[1] = 1;
bin[2] = 2;
bin[3] = 3;
console.log(bin); // [0,1,2,3]
var blob = new Blob(bin);
var fileReader = new FileReader();
fileReader.onload = function() {
var buffer = fileReader.result;
var dv = new DataView(buffer);
console.log(new Uint8Array(buffer)); // [49,50,51,52]
var dv = new DataView(buffer);
console.log([
dv.getUint8(0),
dv.getUint8(1),
dv.getUint8(2),
dv.getUint8(3)
]); // it also prints [49,50,51,52]
};
};
fileReader.readAsArrayBuffer(blob);
Why this is happening? I wrote 0,1,2,3 but every value were added 48 more. Is there a something that I missed?