bite.io module

class bite.io.BytesBuffer(data: bytes)[source]

Implements the ParserBuffer protocol for a bytes object.

The buffer is static, i.e. all bytes are already provided.

Parameters:

data – Data for the buffer.

at_eof() bool[source]

Always returns True as the complete buffer is provided at construction time.

async get(key: int | slice) bytes[source]

Get a range from from the buffer.

Blocks if the requested range is not available yet. If the requested range will never become available (e.g. because it would go past the end of file), as much as possible is returned.

Parameters:

key – Range to return. An integer i is treated as a single byte range slice(i, i + 1).

Returns:

  • A bytes object containing the requested range from the buffer. This should always be a bytes objects even if a single integer index was provided (this is in contrast to how indexing works on bytes objects). A smaller range than requested may be returned if the buffer is unable to provide that range (however, the method must block if that range may become available).

  • # noqa (DAR202)

get_current() bytes[source]

Get all bytes currently stored in the buffer.

class bite.io.ParserBuffer(*args, **kwargs)[source]

Protocol used by parsers to read from a bytes buffer.

at_eof() bool[source]

Whether the end of file has been found.

If the end of file has been found, all possible bytes have been read into the buffer and no new bytes will be added.

async get(key: int | slice) bytes[source]

Get a range from from the buffer.

Blocks if the requested range is not available yet. If the requested range will never become available (e.g. because it would go past the end of file), as much as possible is returned.

Parameters:

key – Range to return. An integer i is treated as a single byte range slice(i, i + 1).

Returns:

  • A bytes object containing the requested range from the buffer. This should always be a bytes objects even if a single integer index was provided (this is in contrast to how indexing works on bytes objects). A smaller range than requested may be returned if the buffer is unable to provide that range (however, the method must block if that range may become available).

  • # noqa (DAR202)

get_current() bytes[source]

Get all bytes currently stored in the buffer.

class bite.io.StreamReaderBuffer(reader: StreamReader)[source]

Implements the ParserBuffer protocol for a asyncio.StreamReader.

Parameters:

reader – Reader providing the bytes to be read into the buffer.

at_eof() bool[source]

Whether the end of file has been found.

If the end of file has been found, all possible bytes have been read into the buffer and no new bytes will be added.

async drop_prefix(n: int)[source]

Drop the first n bytes in the buffer.

async get(key: int | slice) bytes[source]

Get a range from from the buffer.

Blocks if the requested range is not available yet. If the requested range will never become available (e.g. because it would go past the end of file), as much as possible is returned.

Parameters:

key – Range to return. An integer i is treated as a single byte range slice(i, i + 1).

Returns:

  • A bytes object containing the requested range from the buffer. This should always be a bytes objects even if a single integer index was provided (this is in contrast to how indexing works on bytes objects). A smaller range than requested may be returned if the buffer is unable to provide that range (however, the method must block if that range may become available).

  • # noqa (DAR202)

get_current() bytes[source]

Get all bytes currently stored in the buffer.