module documentation

Various I/O related utility functions.

Function read_n_bytes Read n bytes in total from f.
Function read_until_zero Read a zero-terminated bytestring from a file.
def read_n_bytes(f, n, raise_on_incomplete=False):

Read n bytes in total from f.

If raise_on_incomplete is zero, this may return less bytes on EOF. Otherwise, an exception is raised.

Parameters
f:file-likefile-like object to read from
n:intnumber of bytes to read
raise_on_incomplete:boolif nonzero, raise an Exception if unable to read full n bytes
Returns
bytesthe content read
Raises
IOErrorwhen raise_in_incomplete is nonzero and unable to read full n bytes.
def read_until_zero(f, encoding=None, strip_zero=True):

Read a zero-terminated bytestring from a file.

Parameters
f:file-like objectfile-like object to read from
encoding:str or Noneif specified, decode the string using this encoding
strip_zero:boolif nonzero (default), do not add the zero to the result string
Returns
bytes or str if an encoding was specifiedthe parsed string.