bbbot
bbbot

Reputation: 23

Javascript html5 how to convert binary data into string

    var reader = new FileReader();
    var rawData = new ArrayBuffer();            
    //console.log(1);

    reader.onload = function(e) {


        var rawData = e.target.result; //binary data
        console.log(rawData);


    }

I want to see explicitly the binary raw data as a text string, is that possible?, cause the only thing i see when logging is:

ArrayBuffer {} 

Upvotes: 1

Views: 4834

Answers (2)

Rickard Staaf
Rickard Staaf

Reputation: 2740

You can try

console.log(String.fromCharCode.apply(null, new Uint16Array(rawData)));

Upvotes: 3

bbbot
bbbot

Reputation: 23

This is what'I've needed:

reader.readAsBinaryString(file);

then the data is available raw

Upvotes: 0

Related Questions