Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/handle chunked data #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions remotezip.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ def _request(self, kwargs):
res.raise_for_status()
if 'Content-Range' not in res.headers:
raise RangeNotSupported("The server doesn't support range requests")
return res.raw, res.headers['Content-Range']
buffer = res.raw
if hasattr(buffer, 'decode_content'):
# Special case for urllib3
buffer.decode_content = True
return buffer, res.headers['Content-Range']

def prepare_request(self, data_range=None):
kwargs = dict(self._kwargs)
Expand Down Expand Up @@ -243,15 +247,6 @@ def __init__(self, url, initial_buffer_size=64*1024, session=None, fetcher=Remot
fetcher = fetcher(url, session, support_suffix_range=support_suffix_range, **kwargs)
rio = RemoteIO(fetcher.fetch, initial_buffer_size)
super(RemoteZip, self).__init__(rio)
rio.set_position_to_size(self._get_position_to_size())

def _get_position_to_size(self):
ilist = [info.header_offset for info in self.infolist()]
if len(ilist) == 0:
return {}
ilist.sort()
ilist.append(self.start_dir)
return {a: b-a for a, b in pairwise(ilist)}

def size(self):
return self.fp._file_size if self.fp else 0
Expand Down