FileReader.readAsBinaryString()

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

O método readAsBinaryString é usado para iniciar a leitura do conteúdo de um Blob especificado, ou File. Quando a operação de leitura é finalizada, o readyState (en-US) se torna "DONE", e o evento loadend (en-US) é acionado. Neste momento, o atributo result (en-US) contém o dado binário bruto do arquivo.

Note que este método se tornou obsoleto desde 12 de Julho de 2012 Working Draft do W3C.

Sintaxe

instanciaDeFileReader.readAsBinaryString(blob);

Parametros

blob

O Blob ou File que deseja ler.

Exemplo

js
var canvas = document.createElement("canvas");
var height = 200;
var width = 200;

canvas.width = width;
canvas.height = height;

var ctx = canvas.getContext("2d");

ctx.strokeStyle = "#090";
ctx.beginPath();
ctx.arc(width / 2, height / 2, width / 2 - width / 10, 0, Math.PI * 2);
ctx.stroke();

canvas.toBlob(function (blob) {
  var reader = new FileReader();

  reader.onloadend = function () {
    console.log(reader.result);
  };

  reader.readAsBinaryString(blob);
});

Especificações

Specification
File API
# readAsBinaryString

Compatibilidade com navegadores

BCD tables only load in the browser

Veja Também