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

Download an object's last n bytes #2030

Closed
frcroth opened this issue May 23, 2023 · 2 comments
Closed

Download an object's last n bytes #2030

frcroth opened this issue May 23, 2023 · 2 comments
Labels
api: storage Issues related to the googleapis/java-storage API. type: question Request for information or clarification. Not an issue.

Comments

@frcroth
Copy link

frcroth commented May 23, 2023

Downloading objects via byte ranges is supported (https://cloud.google.com/storage/docs/samples/storage-download-byte-range). However, seeking the channel does not work when I need to download the last n bytes of an object.
This is supported in the HTTP Range header with a negative value, describing the suffix length. (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range).

Ideally I would like to give another parameter to download, an option object describing that or a new RangeReader.

Is this feature already implemented?

Describe alternatives you've considered
A possible workaround could be to first get the size and use this to get the start position. This is not ideal, as it would require two HTTP requests.

Additional context
In Go this was already discussed and implemented (googleapis/google-cloud-go#1540). However, I am not sure, if the seekable channel would support something like this.

@meltsufin meltsufin transferred this issue from googleapis/google-cloud-java May 23, 2023
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage API. label May 23, 2023
@BenWhitehead BenWhitehead added the type: question Request for information or clarification. Not an issue. label May 23, 2023
@BenWhitehead
Copy link
Collaborator

This was implemented[1] back in March, and is available from version 2.20.0 onward.

We have a test[3] which verifies this behavior. In order to read of a negative offset, a limit must not be set. If a limit is set, the negative offset will be ignored.

[1] #1916
[2] https://github.com/googleapis/java-storage/releases/tag/v2.20.0
[3] https://github.com/googleapis/java-storage/blame/260b6e52b379b80a1e31a32231a708556a62a75e/google-cloud-storage/src/test/java/com/google/cloud/storage/it/ITBlobReadChannelTest.java#L462-L481

@frcroth
Copy link
Author

frcroth commented May 26, 2023

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants