text()
方法在
Blob
interface returns a
Promise
that resolves with a string containing the contents of the blob, interpreted as UTF-8.
var textPromise = blob.text(); blob.text().then(text => /* do something with the text */); var text = await blob.text();
None.
A promise that resolves with a
USVString
which contains the blob's data as a text string. The data is
always
presumed to be in UTF-8 format.
FileReader
方法
readAsText()
is an older method that performs a similar function. It works on both
Blob
and
File
objects. There are two key differences:
Blob.text()
returns a promise, whereas
FileReader.readAsText()
is an event based API.
Blob.text()
always uses UTF-8 as encoding, while
FileReader.readAsText()
can use a different encoding depending on the blob's type and a specified encoding name.
| 规范 | 状态 | 注释 |
|---|---|---|
|
文件 API
The definition of 'Blob.text()' in that specification. |
工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
text()
|
Chrome 76 | Edge 79 | Firefox 69 | IE No | Opera No | Safari No | WebView Android 76 | Chrome Android 76 | Firefox Android No | Opera Android 54 | Safari iOS No | Samsung Internet Android 12.0 |
完整支持
不支持
Blob
arrayBuffer()
slice()
stream()
text()