Skip to content

Commit

Permalink
feat(storage): expose StreamResponse content length
Browse files Browse the repository at this point in the history
It can be particularly useful to know the length of the returned stream
for eg. users who want to have a progress bar for their download. Expose
it directly to avoid users needing to reach into the protected
implementation details of `self._response`.
  • Loading branch information
TheKevJames committed Apr 28, 2022
1 parent 4c8457a commit 09eafe3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions storage/gcloud/aio/storage/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def __init__(self, response: Any) -> None:
self._response = response
self._iter: Optional[Iterator[bytes]] = None

@property
def content_length(self) -> int:
return int(self._response.headers.get('content-length', 0))

async def read(self, size: int = -1) -> bytes:
chunk: bytes
if BUILD_GCLOUD_REST:
Expand Down

0 comments on commit 09eafe3

Please sign in to comment.