Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

Commit

Permalink
Support offset and size for read (#157)
Browse files Browse the repository at this point in the history
* Support offset and size for read

* Check the size and correct range end for read

* Use HasOffset and HasSize to check offset and size

* Compatible with only size or offset
  • Loading branch information
zhaohuxing authored Jul 22, 2021
1 parent 3e09333 commit 8fb8864
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ func (s *Storage) read(ctx context.Context, path string, w io.Writer, opt pairSt
Bucket: aws.String(s.name),
Key: aws.String(rp),
}
if opt.HasOffset && opt.HasSize {
input.Range = aws.String(fmt.Sprintf("bytes=%d-%d", opt.Offset, opt.Offset+opt.Size-1))
} else if opt.HasOffset && !opt.HasSize {
input.Range = aws.String(fmt.Sprintf("bytes=%d-", opt.Offset))
} else if !opt.HasOffset && opt.HasSize {
input.Range = aws.String(fmt.Sprintf("bytes=0-%d", opt.Size-1))
}

if opt.HasExceptedBucketOwner {
input.ExpectedBucketOwner = &opt.ExceptedBucketOwner
}
Expand Down

0 comments on commit 8fb8864

Please sign in to comment.