MCPcopy
hub / github.com/quodlibet/mutagen / bits

Method bits

mutagen/_util.py:971–994  ·  view source on GitHub ↗

Reads `count` bits and returns an uint, MSB read first. May raise BitReaderError if not enough data could be read or IOError by the underlying file object.

(self, count: int)

Source from the content-addressed store, hash-verified

969 self._pos = fileobj.tell()
970
971 def bits(self, count: int) -> int:
972 """Reads `count` bits and returns an uint, MSB read first.
973
974 May raise BitReaderError if not enough data could be read or
975 IOError by the underlying file object.
976 """
977
978 if count < 0:
979 raise ValueError
980
981 if count > self._bits:
982 n_bytes = (count - self._bits + 7) // 8
983 data = self._fileobj.read(n_bytes)
984 if len(data) != n_bytes:
985 raise BitReaderError("not enough data")
986 for b in bytearray(data):
987 self._buffer = (self._buffer << 8) | b
988 self._bits += n_bytes * 8
989
990 self._bits -= count
991 value = self._buffer >> self._bits
992 self._buffer &= (1 << self._bits) - 1
993 assert self._bits < 8
994 return value
995
996 def bytes(self, count: int) -> bytes:
997 """Returns a bytearray of length `count`. Works unaligned."""

Callers 15

test_bitsMethod · 0.95
test_bits_nullMethod · 0.95
test_read_too_muchMethod · 0.95
test_skipMethod · 0.95
test_skip_moreMethod · 0.95
test_get_positionMethod · 0.95
test_is_alignedMethod · 0.95
_parse_adifMethod · 0.95
bytesMethod · 0.95
skipMethod · 0.95
__init__Method · 0.95
__init__Method · 0.95

Calls 2

BitReaderErrorClass · 0.85
readMethod · 0.45

Tested by 7

test_bitsMethod · 0.76
test_bits_nullMethod · 0.76
test_read_too_muchMethod · 0.76
test_skipMethod · 0.76
test_skip_moreMethod · 0.76
test_get_positionMethod · 0.76
test_is_alignedMethod · 0.76