artamonovdev artamonovdev - 1 month ago 28
Javascript Question

How to save arrayBuffer to file

I created arrayBuffer [0011110111000001001001110000111110111010]. I want to save this array to file.
I make:

var blob = new Blob([binaryArray.buffer], {type: "octet/stream"});
saveAs(blob, 'encode_file');


When I saved a file, file contains an array of bits => [00111101 11000001 00100111 00001111 10111010 00000000
00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000]
[enter image description here]1

How to remove nulls??? Where are they?

Answer

I thought that in new ArrayBuffer(length) length is bits, not bytes.

developer.mozilla.org new ArrayBuffer(length)

Parameters

length

The size, in bytes, of the array buffer to create.