-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Feature/range bytes #2890
Feature/range bytes #2890
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
@quasiben awesome! Thanks! I'll start a review on this right now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good!
@@ -370,18 +370,30 @@ def initialize_download(self, http_request, http): | |||
|
|||
:type http: :class:`httplib2.Http` (or workalike) | |||
:param http: Http instance for this request. | |||
|
|||
:type range_bytes: tuple | |||
:param range_bytes: Optional. Range of bytes to download. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
self._set_range_header(http_request, 0, end_byte) | ||
if range_bytes: | ||
start_byte, end_byte = range_bytes | ||
end_byte = end_byte - 1 |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
response = make_api_request( | ||
self.bytes_http or http, http_request) | ||
if response.status_code not in self._ACCEPTABLE_STATUSES: | ||
raise HttpError.from_response(response) | ||
self._initial_response = response | ||
self._set_total(response.info) | ||
# when using `range_bytes` we need to reset total_size |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -319,6 +319,9 @@ def download_to_file(self, file_obj, client=None): | |||
:param client: Optional. The client to use. If not passed, falls back | |||
to the ``client`` stored on the blob's bucket. | |||
|
|||
:type range_bytes: tuple | |||
:param range_bytes: Optional. Range of bytes to download. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"""Download the contents of this blob as a string. | ||
|
||
:type client: :class:`~google.cloud.storage.client.Client` or | ||
``NoneType`` | ||
:param client: Optional. The client to use. If not passed, falls back | ||
to the ``client`` stored on the blob's bucket. | ||
|
||
:type range_bytes: tuple | ||
:param range_bytes: Optional. Range of bytes to download. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Aside from my little nitpicks, if you want to know how to run the tests locally, I recommend running a few things and making sure they pass before pushing up. tox -e py27 -- core storage
tox -e py35 -- core storage
tox -e cover -- core storage
tox -e lint A guide to setting up |
Thanks for the review @daspecster |
I'll have to get another setup to properly use |
09002c4
to
d2b790b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I get deeper in this review, I want to point something out.
As part of "divorcing" httplib2
we (@jonparrott and I) plan on greatly re-factoring google.cloud.streaming
.
:param range_bytes: (Optional). Range of bytes to download. | ||
|
||
For more info on Range Bytes: | ||
https://cloud.google.com/storage/docs/xml-api/reference-headers#range |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
""" | ||
self._ensure_uninitialized() | ||
url = http_request.url | ||
if self.auto_transfer: | ||
end_byte = self._compute_end_byte(0) | ||
self._set_range_header(http_request, 0, end_byte) | ||
if range_bytes: |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
if range_bytes: | ||
start_byte, end_byte = range_bytes | ||
start_byte = int(start_byte) | ||
end_byte = int(end_byte) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
# when using `range_bytes` we need to reset total_size, | ||
# otherwise we get the total of the file and the entire contents | ||
# are downloaded | ||
if range_bytes: self._total_size = abs(end_byte - start_byte) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dhermes happy to wait on this work if the "divorce" is imminent |
I signed it! |
CLAs look good, thanks! |
anything else that needs doing here? |
Sounds good |
@dhermes did you have any other feedback for this? |
@dhermes just a reminder about this. |
Ok, any ideas on a timeline for #1998 ? |
PR attempts to resolve #2888. Users should be able to easily download a range of bytes when working with storage blobs. This PR tries to minimally inject a new kwarg:
range_bytes
indownload_as_string
and related downloading functions:cc @daspecster