Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/website/awaited-dom/Blob.md
1028 views

AwaitedDOM / Blob

The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream so its methods can be used for processing the data.
Blobs can represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.

Properties

.size
W3C {#size}

The size, in bytes, of the data contained in the Blob object.

Type: Promise<number>

.type
W3C {#type}

A string indicating the MIME type of the data contained in the Blob. If the type is unknown, this string is empty.

Type: Promise<string>

Methods

.arrayBuffer*()*
W3C {#arrayBuffer}

Returns a promise that resolves with an ArrayBuffer containing the entire contents of the Blob as binary data.

Returns: Promise<ArrayBuffer>

.slice*(start?, end?, contentType?)*
W3C {#slice}

Returns a new Blob object containing the data in the specified range of bytes of the blob on which it's called.

Arguments:

  • start number. An index into the Blob indicating the first byte to include in the new Blob. If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob. The default value is 0. If you specify a value for start that is larger than the size of the source Blob, the returned Blob has size 0 and contains no data.

  • end number. An index into the Blob indicating the first byte that will not be included in the new Blob (i.e. the byte exactly at this index is not included). If you specify a negative value, it's treated as an offset from the end of the Blob toward the beginning. For example, -10 would be the 10th from last byte in the Blob. The default value is size.

  • contentType string. The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string.

Returns: Promise<Blob>

.text*()*
W3C {#text}

Returns a promise that resolves with a string containing the entire contents of the Blob interpreted as UTF-8 text.

Returns: Promise<string>

Unimplemented Specs

Methods

stream()