Skip to content
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
32 changes: 28 additions & 4 deletions google/resumable_media/requests/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,17 +667,29 @@ def __init__(self, checksum):
super().__init__()
self._checksum = checksum

def decompress(self, data):
def decompress(self, data, max_length=-1):
"""Decompress the bytes.

Args:
data (bytes): The compressed bytes to be decompressed.
max_length (optional[int]): The maximum number of bytes to decompress.
This parameter is required for compatibility with urllib3>=2.6.0
and is passed to the underlying urllib3 decoder.

Returns:
bytes: The decompressed bytes from ``data``.
"""
self._checksum.update(data)
return super().decompress(data)
try:
return super().decompress(data, max_length=max_length)
except TypeError:
# FB for urllib3 <2.6.0
return super().decompress(data)

@property
def has_unconsumed_tail(self) -> bool:
# Checks for buffered, unread bytes
return self._decoder.has_unconsumed_tail
Comment on lines +689 to +692

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this property is not required for _GzipDecoder . It's needed only for _BrotliDecoder.

Please remove these lines.



# urllib3.response.BrotliDecoder might not exist depending on whether brotli is
Expand All @@ -703,20 +715,32 @@ def __init__(self, checksum):
self._decoder = urllib3.response.BrotliDecoder()
self._checksum = checksum

def decompress(self, data):
def decompress(self, data, max_length=-1):
"""Decompress the bytes.

Args:
data (bytes): The compressed bytes to be decompressed.
max_length (optional[int]): The maximum number of bytes to decompress.
This parameter is required for compatibility with urllib3>=2.6.0
and is passed to the underlying urllib3 decoder.

Returns:
bytes: The decompressed bytes from ``data``.
"""
self._checksum.update(data)
return self._decoder.decompress(data)
try:
return self._decoder.decompress(data, max_length=max_length)
except TypeError:
# FB for urllib3 <2.6.0
return self._decoder.decompress(data)

def flush(self):
return self._decoder.flush()

@property
def has_unconsumed_tail(self) -> bool:
# Checks for buffered, unread bytes
return self._decoder.has_unconsumed_tail

else: # pragma: NO COVER
_BrotliDecoder = None # type: ignore # pragma: NO COVER
Loading