# Blob

Immutable bytes with a MIME type.

A data channel delivers binary messages as blobs when its binary type is `'blob'`.

### webrtc.models.blob.BlobPart

A part of a new [`Blob`](#webrtc.models.blob.Blob). It can be a [`str`](https://docs.python.org/3/builtins/stdtypes.html#str), a bytes-like object or another [`Blob`](#webrtc.models.blob.Blob).

alias of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes) | [`bytearray`](https://docs.python.org/3/builtins/stdtypes.html#bytearray) | [`memoryview`](https://docs.python.org/3/builtins/stdtypes.html#memoryview) | [`Blob`](#webrtc.models.blob.Blob)

### *class* webrtc.models.blob.BlobPropertyBag(type='', endings=EndingType.transparent)

The options of a new [`Blob`](#webrtc.models.blob.Blob).

See [MDN: Blob/Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob).

* **Parameters:**
  * **type** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – The MIME type. The blob lowercases it, or leaves it empty if it has characters
    outside of U+0020 to U+007E.
  * **endings** ([`webrtc.EndingType`](../enums.md#webrtc.enums.EndingType), optional) – How the line endings of the [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) parts are written.
    The default is `'transparent'`, which keeps them as they are.

### *class* webrtc.models.blob.Blob(blob_parts=None, options=None)

Immutable bytes with a MIME type.

The bytes are held in memory. `bytes(blob)` and `len(blob)` give the bytes and their number, and blobs with
the same bytes and type are equal. The reading methods return futures that are already done, so they must be
called while an event loop runs.

See [MDN: Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).

* **Parameters:**
  * **blob_parts** (iterable of [`BlobPart`](#webrtc.models.blob.BlobPart), optional) – The parts, concatenated. A [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) is encoded as UTF-8,
    with lone surrogates replaced by U+FFFD.
  * **options** ([`BlobPropertyBag`](#webrtc.models.blob.BlobPropertyBag), optional) – The MIME type, and how the line endings of strings are written.

#### *property* size *: [int](https://docs.python.org/3/builtins/functions.html#int)*

The number of bytes.

See [MDN: Blob/size](https://developer.mozilla.org/en-US/docs/Web/API/Blob/size).

* **Type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)

#### *property* type *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

The MIME type in lowercase, empty if unknown.

See [MDN: Blob/type](https://developer.mozilla.org/en-US/docs/Web/API/Blob/type).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### slice(start=0, end=None, content_type='')

Returns a new blob with a range of the bytes. Indices out of range are clamped.

See [MDN: Blob/slice](https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice).

* **Parameters:**
  * **start** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The index of the first byte, counted from the end if negative.
  * **end** ([`int`](https://docs.python.org/3/builtins/functions.html#int), optional) – The index after the last byte, counted from the end if negative. The end of
    the blob by default.
  * **content_type** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str), optional) – The MIME type of the new blob, empty by default.
* **Returns:**
  [`Blob`](#webrtc.models.blob.Blob) – The new blob.
* **Return type:**
  [*Blob*](#webrtc.models.blob.Blob)

#### array_buffer()

Reads the bytes. They come as [`bytes`](#webrtc.models.blob.Blob.bytes), where the specification gives an array buffer.

See [MDN: Blob/arrayBuffer](https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer).

* **Returns:**
  [`asyncio.Future`](https://docs.python.org/3/library/asyncio-future.html#asyncio.Future) of [`bytes`](#webrtc.models.blob.Blob.bytes) – The bytes, already done.
* **Return type:**
  *Future*[[bytes](https://docs.python.org/3/builtins/stdtypes.html#bytes)]

#### bytes()

Reads the bytes. They come as [`bytes`](#webrtc.models.blob.Blob.bytes), where the specification gives a byte array.

See [MDN: Blob/bytes](https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes).

* **Returns:**
  [`asyncio.Future`](https://docs.python.org/3/library/asyncio-future.html#asyncio.Future) of [`bytes`](#webrtc.models.blob.Blob.bytes) – The bytes, already done.
* **Return type:**
  *Future*[[bytes](https://docs.python.org/3/builtins/stdtypes.html#bytes)]

#### text()

Reads the bytes decoded as UTF-8. A leading BOM is dropped, and invalid bytes become U+FFFD.

See [MDN: Blob/text](https://developer.mozilla.org/en-US/docs/Web/API/Blob/text).

* **Returns:**
  [`asyncio.Future`](https://docs.python.org/3/library/asyncio-future.html#asyncio.Future) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) – The text, already done.
* **Return type:**
  *Future*[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### stream()

Returns a stream of the bytes, in [`bytes`](#webrtc.models.blob.Blob.bytes) chunks of up to 64 KiB.

See [MDN: Blob/stream](https://developer.mozilla.org/en-US/docs/Web/API/Blob/stream).

* **Returns:**
  [`webrtc.ReadableStream`](../streams.md#webrtc.streams.ReadableStream) of [`bytes`](#webrtc.models.blob.Blob.bytes) – The stream.
* **Return type:**
  [ReadableStream](../streams.md#webrtc.streams.ReadableStream)[builtins.bytes]

#### text_stream()

Returns a stream of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) chunks, decoded from the bytes the same way [`text()`](#webrtc.models.blob.Blob.text) does.

See [MDN: Blob/textStream](https://developer.mozilla.org/en-US/docs/Web/API/Blob/textStream).

* **Returns:**
  [`webrtc.ReadableStream`](../streams.md#webrtc.streams.ReadableStream) of [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) – The stream.
* **Return type:**
  [ReadableStream](../streams.md#webrtc.streams.ReadableStream)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]
