diff --git a/news/b7b40802-1aae-4295-99f4-a0dd48c96e69.trivial b/news/b7b40802-1aae-4295-99f4-a0dd48c96e69.trivial new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/pip/_internal/network/lazy_wheel.py b/src/pip/_internal/network/lazy_wheel.py index c2371bf5cd3..16be0d2972a 100644 --- a/src/pip/_internal/network/lazy_wheel.py +++ b/src/pip/_internal/network/lazy_wheel.py @@ -109,8 +109,10 @@ def read(self, size=-1): all bytes until EOF are returned. Fewer than size bytes may be returned if EOF is reached. """ + download_size = max(size, self._chunk_size) start, length = self.tell(), self._length - stop = start + size if 0 <= size <= length-start else length + stop = length if size < 0 else min(start+download_size, length) + start = max(0, stop-download_size) self._download(start, stop-1) return self._file.read(size)