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

Function read_bytes8

Lib/pickletools.py:534–556  ·  view source on GitHub ↗

r""" >>> import io, struct, sys >>> read_bytes8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc")) b'' >>> read_bytes8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef")) b'abc' >>> bigsize8 = struct.pack(" >> read_bytes8(io.BytesIO(bigsize8 + b"a

(f)

Source from the content-addressed store, hash-verified

532
533
534def read_bytes8(f):
535 r"""
536 >>> import io, struct, sys
537 >>> read_bytes8(io.BytesIO(b"\x00\x00\x00\x00\x00\x00\x00\x00abc"))
538 b''
539 >>> read_bytes8(io.BytesIO(b"\x03\x00\x00\x00\x00\x00\x00\x00abcdef"))
540 b'abc'
541 >>> bigsize8 = struct.pack("<Q", sys.maxsize//3)
542 >>> read_bytes8(io.BytesIO(bigsize8 + b"abcdef")) #doctest: +ELLIPSIS
543 Traceback (most recent call last):
544 ...
545 ValueError: expected ... bytes in a bytes8, but only 6 remain
546 """
547
548 n = read_uint8(f)
549 assert n >= 0
550 if n > sys.maxsize:
551 raise ValueError("bytes8 byte count > sys.maxsize: %d" % n)
552 data = f.read(n)
553 if len(data) == n:
554 return data
555 raise ValueError("expected %d bytes in a bytes8, but only %d remain" %
556 (n, len(data)))
557
558bytes8 = ArgumentDescriptor(
559 name="bytes8",

Callers

nothing calls this directly

Calls 3

read_uint8Function · 0.85
lenFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected