FileReader: phương thức readAsBinaryString()
Note: This feature is available in Web Workers.
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note:
Phương thức này đã lỗi thời, nên dùng readAsArrayBuffer() thay thế.
Phương thức readAsBinaryString() của giao diện FileReader được dùng để bắt đầu đọc nội dung của Blob hoặc File được chỉ định. Khi thao tác đọc hoàn tất, thuộc tính readyState trở thành DONE và sự kiện loadend được kích hoạt. Lúc đó, thuộc tính result chứa dữ liệu nhị phân thô từ tệp.
Lưu ý rằng phương thức này đã từng bị xóa khỏi đặc tả File API, nhưng được đưa lại để đảm bảo tương thích ngược. Nên dùng FileReader.readAsArrayBuffer() thay thế.
Cú pháp
readAsBinaryString(blob)
Tham số
Giá trị trả về
Không có (undefined).
Ví dụ
const canvas = document.createElement("canvas");
const height = 200;
const width = 200;
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.strokeStyle = "#009900";
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);
});
Thông số kỹ thuật
| Specification |
|---|
| File API> # readAsBinaryString> |