From 608ec9a6c3a06c05c174f19c24709b80121b955c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Tue, 4 Aug 2020 16:42:38 +0700 Subject: [PATCH] Make range requests closer to chunk size --- lazip.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lazip.py b/lazip.py index 7cd1eda..e7940ec 100644 --- a/lazip.py +++ b/lazip.py @@ -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):