MCPcopy Index your code
hub / github.com/RustPython/RustPython / read_bytearray8

Function read_bytearray8

Lib/pickletools.py:569–591  ·  view source on GitHub ↗

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(" >> read_by

(f)

Source from the content-addressed store, hash-verified

567
568
569def read_bytearray8(f):
570 r"""
571 >>> import io, struct, sys
572 >>> read_bytearray8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc"))
573 bytearray(b'')
574 >>> read_bytearray8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef"))
575 bytearray(b'abc')
576 >>> bigsize8 = struct.pack("<Q", sys.maxsize//3)
577 >>> read_bytearray8(io.BytesIO(bigsize8 + b"abcdef")) #doctest: +ELLIPSIS
578 Traceback (most recent call last):
579 ...
580 ValueError: expected ... bytes in a bytearray8, but only 6 remain
581 """
582
583 n = read_uint8(f)
584 assert n >= 0
585 if n > sys.maxsize:
586 raise ValueError("bytearray8 byte count > sys.maxsize: %d" % n)
587 data = f.read(n)
588 if len(data) == n:
589 return bytearray(data)
590 raise ValueError("expected %d bytes in a bytearray8, but only %d remain" %
591 (n, len(data)))
592
593bytearray8 = ArgumentDescriptor(
594 name="bytearray8",

Callers

nothing calls this directly

Calls 3

read_uint8Function · 0.85
lenFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected