Buffer

class websocket.stream.buffer.Buffer(limit, loop)[source]
at_eof()[source]
Returns:True iff there is no more data to read AND we have been fed end of file.
empty()[source]
Returns:True iff there is no more data to read.
feed_eof()[source]

Feed the buffer with end of file

read(n=-1, chunksize=None)[source]

Read data from the buffer. Reads until eof or n bytes.

Parameters:n – The amount of data to read.
Returns:A bytearray with the data
read_into(buffer, n, offset=0)[source]

Read data from the buffer into a bytearray. Reads until eof or n bytes.

n must not exceed the buffer limit, or else it will block forever.

Parameters:
  • buffer – The bytearray to write the data into.
  • n – The amount of data to read.
  • offset – The index into buffer to write to.
read_into_exactly(buffer, n, offset=0)[source]

Read data from the buffer into a bytearray. Reads n bytes or throws an exception if reading eof.

n must not exceed the buffer limit, or else it will block forever.

Parameters:
  • buffer – The bytearray to write the data into.
  • n – The amount of data to read.
set_exception(exc)[source]

Set an exception to raise at next read.

write(data)[source]

Write some data to the buffer, length must not exceed the buffer limit, or else it will block forever.

Parameters:data (iterable of bytes) – The data to write