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

feat: optional --range argument for cp to download single part of object #772

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mackenzie-grimes-noaa
Copy link

@mackenzie-grimes-noaa mackenzie-grimes-noaa commented Nov 13, 2024

Adds an optional string argument --range to cp command, which exposes the existing AWS GetObject Range header to provide a specific byterange of the object to be copied.

Now s5cmd users can optionally set this header manually and only download a specific part of their src object.

Example:

s5cmd cp --range bytes=500-999 's3://mybucket/foo/bar/file.txt' my_partial_file.txt

Obviously makes any --concurrency or --part_size arguments redundant when --range is specified, since only 1 part will be downloaded, using only 1 thread.

Note: AWS GetObject only supports specifying a single byte range, so we are also constrained by this limitation. An s5cmd user would have to run multiple cp commands to download, for example, bytes ranging from 100-199 (bytes=100-199) and from 300-399 (bytes=300-399).

Solves this Issue: #756

@mackenzie-grimes-noaa mackenzie-grimes-noaa marked this pull request as ready for review November 13, 2024 19:02
@mackenzie-grimes-noaa mackenzie-grimes-noaa requested a review from a team as a code owner November 13, 2024 19:03
@mackenzie-grimes-noaa mackenzie-grimes-noaa requested review from seruman and sonmezonur and removed request for a team November 13, 2024 19:03
@@ -620,6 +621,9 @@ func (s *S3) Get(
if from.VersionID != "" {
input.VersionId = aws.String(from.VersionID)
}
if contentRange != nil {
input.Range = aws.String(*contentRange)
}

return s.downloader.DownloadWithContext(ctx, to, input, func(u *s3manager.Downloader) {
Copy link

Choose a reason for hiding this comment

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

image

Choose a reason for hiding this comment

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

Do you think I should use the Download() function from your screenshot instead of s.downloader.DownloadWithContext(...)? Since it does the same thing as the code in line 624 of s3.go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants