FileReader: readyState 属性
注意:此功能在 Web Workers 中可用。
FileReader 接口的readyState 只读属性提供了读取操作的当前状态。它将是以下状态之一:EMPTY、LOADING 或 DONE。
值
一个数字,它是 FileReader 接口上定义的三个可能状态常量之一
FileReader.EMPTY(0)-
Reader 已创建,但尚未调用任何读取方法。
FileReader.LOADING(1)-
已调用读取方法。正在读取
File或Blob,且尚未发生错误。 FileReader.DONE(2)-
读取操作已完成。这可能意味着:整个
File或Blob已被读取到内存中,发生了文件读取错误,或者调用了abort()并且读取被取消。
示例
js
const reader = new FileReader();
console.log("EMPTY", reader.readyState); // readyState will be 0
reader.readAsText(blob);
console.log("LOADING", reader.readyState); // readyState will be 1
reader.onloadend = () => {
console.log("DONE", reader.readyState); // readyState will be 2
};
规范
| 规范 |
|---|
| File API # dom-filereader-readystate |
浏览器兼容性
加载中…