Skip to content

bareutils.streaming

module bareutils.streaming

Summary

Streaming

async function bareutils.streaming.bytes_reader

Summary

Extracts the body body as bytes.

async bareutils.streaming.bytes_reader(
body: AsyncIterable[bytes]
) -> bytes

Parameters

body: AsyncIterable[bytes]

The body argument of the request.

Returns

bytes: The body as bytes.

async generator function bareutils.streaming.bytes_writer

Summary

Creates an asynchronous iterator from the supplied response body.

async bareutils.streaming.bytes_writer(
buf: bytes,
chunk_size: int
) -> AsyncIterable[bytes]

Parameters

buf: bytes

The response body to return.

chunk_size: int

The size of each chunk to send or -1 to send as a single chunk.. Defaults to -1.

Yields

AsyncIterable[bytes]: The body bytes

async function bareutils.streaming.text_reader

Summary

Extracts the body contents as text.

async bareutils.streaming.text_reader(
body: AsyncIterable[bytes],
encoding: str
) -> str

Parameters

body: AsyncIterable[bytes]

The body of the request.

encoding: str (optional)

The encoding of the text. Defaults to 'utf-8'.

Returns

str: The body contents as a string.

async generator function bareutils.streaming.text_writer

Summary

Creates an asynchronous iterator from the supplied response body.

async bareutils.streaming.text_writer(
text: str,
encoding: str,
chunk_size: int
) -> AsyncIterable[bytes]

Parameters

text: str

The response body.

encoding: str

The encoding to apply when transforming the text into bytes. Defaults to 'utf-8'.

chunk_size: int

The size of each chunk to send or -1 to send as a single chunk.. Defaults to -1.

Yields

AsyncIterable[bytes]: The body bytes