(f)
r"""
    >>> import io, struct, sys
    >>> read_bytearray8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc"))
    bytearray(b'')
    >>> read_bytearray8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef"))
    bytearray(b'abc')
    >>> bigsize8 = struct.pack("<Q", sys.maxsize//3)
    >>> read_bytearray8(io.BytesIO(bigsize8 + b"abcdef"))  #doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: expected ... bytes in a bytearray8, but only 6 remain
r"""
    >>> import io, struct, sys
    >>> read_bytearray8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc"))
    bytearray(b'')
    >>> read_bytearray8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef"))
    bytearray(b'abc')
    >>> bigsize8 = struct.pack("<Q", sys.maxsize//3)
    >>> read_bytearray8(io.BytesIO(bigsize8 + b"abcdef"))  #doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: expected ... bytes in a bytearray8, but only 6 remain
r >>> import io struct sys >>> read_bytearray8 ( io . BytesIO ( b \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00abc )) bytearray ( b ) >>> read_bytearray8 ( io . BytesIO ( b \ x03 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00abcdef )) bytearray ( b abc ) >>> bigsize8 = struct . pack ( <Q sys . maxsize // 3 ) >>> read_bytearray8 ( io . BytesIO ( bigsize8 + b abcdef )) #doctest : + ELLIPSIS Traceback ( most recent call last ) : ... ValueError : expected ... bytes in a bytearray8 but only 6 remain
def read_bytearray8(f):
    r"""
    >>> import io, struct, sys
    >>> read_bytearray8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc"))
    bytearray(b'')
    >>> read_bytearray8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef"))
    bytearray(b'abc')
    >>> bigsize8 = struct.pack("<Q", sys.maxsize//3)
    >>> read_bytearray8(io.BytesIO(bigsize8 + b"abcdef"))  #doctest: +ELLIPSIS
    Traceback (most recent call last):
    ...
    ValueError: expected ... bytes in a bytearray8, but only 6 remain
    """

    n = read_uint8(f)
    assert n >= 0
    if n > sys.maxsize:
        raise ValueError("bytearray8 byte count > sys.maxsize: %d" % n)
    data = f.read(n)
    if len(data) == n:
        return bytearray(data)
    raise ValueError("expected %d bytes in a bytearray8, but only %d remain" %
                     (n, len(data)))
def read_bytearray8 ( f ) : n = read_uint8 ( f ) assert n >= 0 if n > sys . maxsize : raise ValueError ( "bytearray8 byte count > sys.maxsize: %d" % n ) data = f . read ( n ) if len ( data ) == n : return bytearray ( data ) raise ValueError ( "expected %d bytes in a bytearray8, but only %d remain" % ( n , len ( data ) ) )