Push a new value to the stream. This will immediately write as many uint8 as possible to the underlying file-object.
(self, value: int)
| 68 | self.fo = fo |
| 69 | |
| 70 | def push(self, value: int): |
| 71 | """Push a new value to the stream. This will immediately |
| 72 | write as many uint8 as possible to the underlying file-object.""" |
| 73 | self._current_value += (value << self._current_bits) |
| 74 | self._current_bits += self.bits |
| 75 | while self._current_bits >= 8: |
| 76 | lower_8bits = self._current_value & 0xff |
| 77 | self._current_bits -= 8 |
| 78 | self._current_value >>= 8 |
| 79 | self.fo.write(bytes([lower_8bits])) |
| 80 | |
| 81 | def flush(self): |
| 82 | """Flushes the remaining partial uint8, call this at the end |