You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[FileReader](https://www.w3.org/TR/FileAPI/#dfn-filereader)is an object with the sole purpose of reading data from `Blob` (and hence `File`too) objects.
```smart header="`FileReaderSync` is available for workers only"
108
-
For Web Workers, there also exists a synchronous variant of `FileReader`, called [FileReaderSync](https://www.w3.org/TR/FileAPI/#FileReaderSync).
107
+
```smart header="`FileReaderSync` 只适用于 workers "
108
+
对于 Web Workers,还有一种同步的 `FileReader` 变体,称为 [FileReaderSync](https://www.w3.org/TR/FileAPI/#FileReaderSync)。
109
109
110
-
Its reading methods `read*` do not generate events, but rather return a result, as regular functions do.
110
+
FileReader 的读取方法 `read*` 并不生成事件,而是会和普通函数一样返回一个结果。
111
111
112
-
That's only inside a Web Worker though, because delays in synchronous calls, that are possible while reading from files, in Web Workers are less important. They do not affect the page.
112
+
不过,那只是在 Web Worker 内部,因为在读取文件的时候,同步调用会有延迟,而在 Web Workers 则不是很重要,并不会影响页面。
113
113
```
114
114
115
-
## Summary
115
+
## 总结
116
116
117
-
`File`objects inherit from `Blob`.
117
+
`File`对象继承自 `Blob`。
118
118
119
-
In addition to `Blob`methods and properties, `File`objects also have `fileName`and`lastModified`properties, plus the internal ability to read from filesystem. We usually get `File` objects from user input, like `<input>`or drag'n'drop.
`FileReader`objects can read from a file or a blob, in one of three formats:
122
-
-String (`readAsText`).
123
-
-`ArrayBuffer` (`readAsArrayBuffer`).
124
-
-Data url, base-64 encoded (`readAsDataURL`).
121
+
`FileReader`对象可以从文件或 blob 读取以下三种格式:
122
+
-字符串 (`readAsText`)。
123
+
-`ArrayBuffer` (`readAsArrayBuffer`)。
124
+
-数据 url,base-64 编码(`readAsDataURL`)。
125
125
126
-
In many cases though, we don't have to read the file contents. Just as we did with blobs, we can create a short url with `URL.createObjectURL(file)`and assign it to `<a>`or`<img>`. This way the file can be downloaded or shown up as an image, as a part of canvas etc.
0 commit comments