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. It can be a str, a bytes-like object or another Blob.

alias of str | bytes | bytearray | memoryview | Blob

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

The options of a new Blob.

See MDN: Blob/Blob.

Parameters:
  • type (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, optional) – How the line endings of the 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.

Parameters:
  • blob_parts (iterable of BlobPart, optional) – The parts, concatenated. A str is encoded as UTF-8, with lone surrogates replaced by U+FFFD.

  • options (BlobPropertyBag, optional) – The MIME type, and how the line endings of strings are written.

property size: int

The number of bytes.

See MDN: Blob/size.

Type:

int

property type: str

The MIME type in lowercase, empty if unknown.

See MDN: Blob/type.

Type:

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.

Parameters:
  • start (int, optional) – The index of the first byte, counted from the end if negative.

  • end (int, optional) – The index after the last byte, counted from the end if negative. The end of the blob by default.

  • content_type (str, optional) – The MIME type of the new blob, empty by default.

Returns:

Blob – The new blob.

Return type:

Blob

array_buffer()

Reads the bytes. They come as bytes, where the specification gives an array buffer.

See MDN: Blob/arrayBuffer.

Returns:

asyncio.Future of bytes – The bytes, already done.

Return type:

Future[bytes]

bytes()

Reads the bytes. They come as bytes, where the specification gives a byte array.

See MDN: Blob/bytes.

Returns:

asyncio.Future of bytes – The bytes, already done.

Return type:

Future[bytes]

text()

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

See MDN: Blob/text.

Returns:

asyncio.Future of str – The text, already done.

Return type:

Future[str]

stream()

Returns a stream of the bytes, in bytes chunks of up to 64 KiB.

See MDN: Blob/stream.

Returns:

webrtc.ReadableStream of bytes – The stream.

Return type:

ReadableStream[builtins.bytes]

text_stream()

Returns a stream of str chunks, decoded from the bytes the same way text() does.

See MDN: Blob/textStream.

Returns:

webrtc.ReadableStream of str – The stream.

Return type:

ReadableStream[str]