supports get range offset with unkown length (#58)

https://www.rfc-editor.org/rfc/rfc9110.html#name-byte-ranges
This commit is contained in:
zhijian 2022-10-13 00:09:28 +08:00 committed by GitHub
parent c7b1ff8a5e
commit e70a598e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -367,7 +367,11 @@ func (c *Client) ReadStream(path string) (io.ReadCloser, error) {
// to `length`. // to `length`.
func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) { func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) {
rs, err := c.req("GET", path, nil, func(r *http.Request) { rs, err := c.req("GET", path, nil, func(r *http.Request) {
r.Header.Add("Range", fmt.Sprintf("bytes=%v-%v", offset, offset+length-1)) if length > 0 {
r.Header.Add("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1))
} else {
r.Header.Add("Range", fmt.Sprintf("bytes=%d-", offset))
}
}) })
if err != nil { if err != nil {
return nil, newPathErrorErr("ReadStreamRange", path, err) return nil, newPathErrorErr("ReadStreamRange", path, err)