Name

FileReaderSync — synchronously read a File or Blob

Synopsis

FileReaderSync is a synchronous version of the FileReader API, available only to Worker threads. The synchronous API is easier to use than the asynchronous one: simply create a FileReaderSync() object and then call one of its read methods, which will either return the contents of the File or Blob or throw a FileError object instead.

Constructor

new FileReaderSync()

Create a new FileReaderSync object with the FileReaderSync() constructor, which expects no arguments.

Methods

These methods throw a FileError object if the read fails for any reason.

ArrayBuffer readAsArrayBuffer(Blob blob)

Read the bytes of blob and return them as an ArrayBuffer.

string readAsBinaryString(Blob blob)

Read the bytes of blob, encode them as a JavaScript binary string (see String.fromCharCode()), and return that binary string.

string readAsDataURL(Blob blob)

Read the bytes of blob, and encode those bytes, along with the type property of blob into a data:// URL, and then return that URL.

string readAsText(Blob blob, [string encoding])

Read the bytes of blob, decode them into text using the specified encoding (or using UTF-8 or UTF-16 if no encoding is specified), and return the resulting string.

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.