Make range requests closer to chunk size

This commit is contained in:
Nguyễn Gia Phong 2020-08-04 16:42:38 +07:00
parent a9ebcd79a0
commit 608ec9a6c3
1 changed files with 3 additions and 0 deletions

View File

@ -229,6 +229,9 @@ class Filazy(ReadOnlyBinaryIOWrapper):
def ensure(self, start: int, end: int) -> None:
"""Download bytes from start to end inclusively."""
offset = self.chunk_size - 1
start = max(0, min(start, end-offset))
end = min(self.length-1, max(end, start+offset))
with self.stay():
i, j = bisect_left(self.right, start), bisect_right(self.left, end)
for start, end in self.merge(start, end, i, j):