FileReader.readAsBinaryString()
readAsBinaryString
メソッドは、 指定された Blob
または File
オブジェクトを読み込むために使用します。 読込処理が終了すると readyState
は DONE
に変わり、loadend
イベントが生じます。それと同時に result
プロパティには生のバイナリーデータを文字列で解釈したものが格納されます。
このメソッドは、ファイル API の仕様から一度削除されましたが、後方互換のために再導入されました。
FileReader.readAsArrayBuffer()
の使用が推奨されています。
構文
js
readAsBinaryString(blob)
引数
返値
なし (undefined
)。
例
js
const canvas = document.createElement("canvas");
const height = 200;
const width = 200;
canvas.width = width;
canvas.height = height;
const 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((blob) => {
const reader = new FileReader();
reader.onload = () => {
console.log(reader.result);
};
reader.readAsBinaryString(blob);
});
仕様書
Specification |
---|
File API # readAsBinaryString |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
readAsBinaryString |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Deprecated. Not for use in new websites.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.