From e70a598e946e560b89bc20a25bd3805f30abeef0 Mon Sep 17 00:00:00 2001 From: zhijian Date: Thu, 13 Oct 2022 00:09:28 +0800 Subject: [PATCH] supports get range offset with unkown length (#58) https://www.rfc-editor.org/rfc/rfc9110.html#name-byte-ranges --- client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 4b3bc80..d918c18 100644 --- a/client.go +++ b/client.go @@ -367,7 +367,11 @@ func (c *Client) ReadStream(path string) (io.ReadCloser, error) { // to `length`. func (c *Client) ReadStreamRange(path string, offset, length int64) (io.ReadCloser, error) { 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 { return nil, newPathErrorErr("ReadStreamRange", path, err)