Prefer Blob#arrayBuffer()
over FileReader#readAsArrayBuffer(…)
and Blob#text()
over FileReader#readAsText(…)
💼 This rule is enabled in the ✅ recommended
config.
FileReader
predates promises, and the newer Blob#arrayBuffer()
and Blob#text()
methods are much cleaner and easier to use.
const arrayBuffer = await new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.addEventListener('load', () => {
resolve(fileReader.result);
});
fileReader.addEventListener('error', () => {
reject(fileReader.error);
});
fileReader.readAsArrayBuffer(blob);
});
fileReader.readAsText(blob);
const arrayBuffer = await blob.arrayBuffer();
const text = await blob.text();
fileReader.readAsText(blob, 'ascii');
fileReader.readAsDataURL(blob);