Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/chunked_reader.py
Show All 23 Lines | def __init__(self, file, size_unpack_fmt='>I'): | ||||
self._chunk_bytes_left = self._bytes_per_chunk | self._chunk_bytes_left = self._bytes_per_chunk | ||||
self._offset = self._file.tell() | self._offset = self._file.tell() | ||||
# find the file size | # find the file size | ||||
self._file.seek(0, 2) # seek to end | self._file.seek(0, 2) # seek to end | ||||
self._size = self._file.tell() | self._size = self._file.tell() | ||||
self._file.seek(self._offset, 0) # seek back to original position | self._file.seek(self._offset, 0) # seek back to original position | ||||
def _chunk_size(self, first_time=False): | def _chunk_size(self, first_time=False): | ||||
"""Unpack the next <determined_by_'size_unpack_fmt'> bytes from the | """Unpack the next bytes from the file to get the next file chunk size. | ||||
file to get the next file chunk size. | |||||
""" | """ | ||||
size = struct.unpack(self._size_pattern, | size = struct.unpack(self._size_pattern, | ||||
self._file.read(self._size_bytes))[0] | self._file.read(self._size_bytes))[0] | ||||
return size | return size | ||||
def size(self): | def size(self): | ||||
"""Returns the file size in bytes. | """Returns the file size in bytes. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |