JavaScripture
Contribute via GitHub Feedback

Blob : Object

Blobs are immutable objects that represent raw data. File is a derivation of Blob that represents data from the file system. Use FileReader to read data from a Blob or File. Blobs allow you to construct file like objects on the client that you can pass to apis that expect urls instead of requiring the server provides the file. For example, you can construct a blob containing the data for an image, use URL.createObjectURL() to generate a url, and pass that url to HTMLImageElement.src to display the image you created without talking to a server.

Constructors

new Blob() : Blob

Creates a new Blob with size set to 0.

Example:

Run

Results:

 

new Blob(blobParts : Array, [blobPropertyBag : Object]) : Blob
blobPropertyBag : {
type :StringA valid mime type such as 'text/plain'
endings :StringMust be either 'transparent' or 'native'
}

Creates a new Blob. The elements of blobParts must be of the types ArrayBuffer, ArrayBufferView, Blob, or String. If ending is set to 'native', the line endings in the blob will be converted to the system line endings, such as '\r\n' for Windows or '\n' for Mac.

Example:

Run

Results:

 

Instance Properties

size : Number  

The size of the blob in bytes.

Example:

Run

Results:

 

type : String  

The type of the blob.

Example:

Run

Results:

 

Instance Methods

arrayBuffer() : Promise<ArrayBuffer>

Asynchronously returns an ArrayBuffer for the data in this. See also FileReader.readAsArrayBuffer().

Example:

Run

Results:

 

slice([start = 0 : Number, [end : Number, [contentType = '' : String]]]) : Blob

Returns a new blob that contains the bytes start to end - 1 from this. If start or end is negative, the value is added to this.size before performing the slice. If end is not specified, this.size is used. The returned blob's type will be contentType if specified, otherwise it will be ''.

Example:

Run

Results:

 

stream() : ReadableStream

Returns a stream of the data in this. The values of the stream will be Uint8Arrays.

Example:

Run

Results:

 

text() : Promise<String>

Asynchronously returns a String for the data in this. See also FileReader.readAsText().

Example:

Run

Results: