FileReaderSync

FileReaderSync interface allows to read File or Blob objects synchronously.

This interface is only available in workers as it enables synchronous I/O that could potentially block.

特性

This interface does not have any properties.

方法

FileReaderSync.readAsArrayBuffer()
This method converts a specified Blob File into an ArrayBuffer representing the input data as a binary string.
FileReaderSync.readAsBinaryString()
This method converts a specified Blob File into a DOMString representing the input data as a binary string. This method is deprecated, consider using readAsArrayBuffer() 代替。
FileReaderSync.readAsText()
This method converts a specified Blob File into a DOMString representing the input data as a text string. The optional encoding parameter indicates the encoding to be used (e.g., iso-8859-1 or UTF-8). If not present, the method will apply a detection algorithm for it.
FileReaderSync.readAsDataURL()
This method converts a specified Blob File into a DOMString representing the input data as a data URL.

规范

规范 状态 Comment
File API
The definition of 'FileReaderSync' in that specification.
工作草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
FileReaderSync Chrome Yes Edge 12 Firefox 8 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 8 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
readAsArrayBuffer Chrome Yes Edge 12 Firefox 8 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 8 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
readAsBinaryString Chrome Yes Edge 12 Firefox 8 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 8 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
readAsDataURL Chrome Yes Edge 12 Firefox 8 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 8 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
readAsText Chrome Yes Edge 12 Firefox 8 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 8 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
Service workers support
弃用 非标
Chrome 不支持 ? — 59 Edge ? Firefox 不支持 ? — 61 IE 不支持 No Opera 不支持 ? — 46 Safari 不支持 No WebView Android 不支持 ? — 59 Chrome Android 不支持 ? — 59 Firefox Android 不支持 ? — 61 Opera Android 不支持 ? — 43 Safari iOS 不支持 No Samsung Internet Android 不支持 ? — 7.0
Available in workers Chrome Yes Edge 12 Firefox 8 IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 8 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
兼容性未知
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
弃用。不要用于新网站。

另请参阅

  1. FileReaderSync
  2. Related pages for File API
    1. Blob
    2. File
    3. FileList
    4. FileReader