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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[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 forworkersonly"
For Web Workers, there also exists a synchronous variant of`FileReader`, called [FileReaderSync](https://www.w3.org/TR/FileAPI/#FileReaderSync).
```smart header="`FileReaderSync`只适用于workers "
对于 Web Workers,还有一种同步的`FileReader` 变体,称为 [FileReaderSync](https://www.w3.org/TR/FileAPI/#FileReaderSync)。
Its reading methods`read*`do not generate events, but rather return a result, as regular functions do.
FileReader 的读取方法`read*`并不生成事件,而是会和普通函数一样返回一个结果。
That's only inside aWeb Workerthough, because delays in synchronous calls, that are possible while reading from files, inWeb Workersare less important. They do not affect the page.
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>`ordrag'n'drop.
`FileReader`objects can read from a file or ablob, in one of three formats:
-String (`readAsText`).
- `ArrayBuffer` (`readAsArrayBuffer`).
-Data url,base-64encoded (`readAsDataURL`).
`FileReader`对象可以从文件或blob 读取以下三种格式:
-字符串 (`readAsText`)。
- `ArrayBuffer` (`readAsArrayBuffer`)。
-数据 url,base-64编码(`readAsDataURL`)。
In many cases though, we don't have to read the file contents. Just as we did withblobs, 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 ofcanvas etc.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.