The FileReaderSync interface allows to read File or Blob objects in a synchronous way.
This interface is only available in workers as it enables synchronous I/O that could potentially block.
ArrayBuffer readAsArrayBuffer(Blob blob); |
DOMString readAsBinaryString(Blob blob); |
DOMStringreadAsText(Blob blob, optional DOMString encoding);
|
DOMString readAsDataURL(Blob blob); |
There aren't any property for this interface.
This method reads the contents of the specified Blob or File. When the read operation is finished, it returns an ArrayBuffer representing the file's data. If an error happened during the read, the adequate exception is sent.
ArrayBuffer readAsArrayBuffer( in Blob blob );
blobBlob or File to read into the ArrayBuffer.An ArrayBuffer representing the file's data.
The following exceptions can be raised by this method:
NotFoundErrorBlob or File cannot be found, e. g. because it has been erased.SecurityErrorNotReadableErrorEncodingErrorThis method reads the contents of the specified Blob, which may be a File. When the read operation is finished, it returns a DOMString containing the raw binary data from the file. If an error happened during the read, the adequate exception is sent.
readAsArrayBuffer() should be used instead.String readAsBinaryString( in Blob blob );
A DOMString containing the raw binary data from the resource
The following exceptions can be raised by this method:
NotFoundErrorBlob or File cannot be found, e. g. because it has been erased.SecurityErrorNotReadableErrorEncodingErrorThis methods reads the specified blob's contents. When the read operation is finished, it returns a DOMString containing the file represented as a text string. The optional encoding parameter indicates the encoding to be used. If not present, the method will apply a detection algorithm for it. If an error happened during the read, the adequate exception is sent.
String readAsText( in Blob blob, in DOMString encoding Optional );
blobBlob or File to read into the DOMString.encodingA DOMString containing the raw binary data from the resource
The following exceptions can be raised by this method:
NotFoundErrorBlob or File cannot be found, e. g. because it has been erased.SecurityErrorNotReadableErrorThis method reads the contents of the specified Blob or File. When the read operation is finished, it returns a data URL representing the file's data. If an error happened during the read, the adequate exception is sent.
String readAsDataURL( in Blob file );
An DOMString representing the file's data as a data URL.
The following exceptions can be raised by this method:
NotFoundErrorBlob or File cannot be found, e. g. because it has been erased.SecurityErrorNotReadableErrorEncodingError| Specification | Status | Comment |
|---|---|---|
| File API The definition of 'FileReaderSync' in that specification. | Working Draft | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Yes | 8 | Yes | Yes | Yes |
| Only available in workers | Yes | Yes | 8 | Yes | Yes | Yes |
readAsArrayBuffer |
Yes | Yes | 8 | Yes | Yes | Yes |
readAsBinaryString |
Yes | Yes | 8 | Yes | Yes | Yes |
readAsDataURL |
Yes | Yes | 8 | Yes | Yes | Yes |
readAsText |
Yes | Yes | 8 | Yes | Yes | Yes |
| Service workers support | ? — 59 | ? | ? — 61 | No | ? — 46 | No |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | 8 | Yes | Yes | ? |
| Only available in workers | Yes | Yes | Yes | 8 | Yes | Yes | ? |
readAsArrayBuffer |
Yes | Yes | Yes | 8 | Yes | Yes | ? |
readAsBinaryString |
Yes | Yes | Yes | 8 | Yes | Yes | ? |
readAsDataURL |
Yes | Yes | Yes | 8 | Yes | Yes | ? |
readAsText |
Yes | Yes | Yes | 8 | Yes | Yes | ? |
| Service workers support | ? — 59 | ? — 59 | ? | ? — 61 | ? — 46 | No | ? |
FileReader, BlobBuilder, File, Blob
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FileReaderSync