From e1556f2f68d0522d5a311299f00e64e7fc1bfeaf Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 25 Jan 2024 09:50:17 -0500 Subject: [PATCH] feat: add support for ranges in tus s3 store --- storage/storage.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/storage/storage.go b/storage/storage.go index 9a419fa..a4aea20 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -5,6 +5,7 @@ import ( "context" "encoding/hex" "errors" + "fmt" "git.lumeweb.com/LumeWeb/libs5-go/encoding" "git.lumeweb.com/LumeWeb/libs5-go/types" "git.lumeweb.com/LumeWeb/portal/api/middleware" @@ -592,7 +593,16 @@ func (s *StorageServiceImpl) GetFile(hash []byte, start int64) (io.ReadCloser, i } info, _ := upload.GetInfo(context.Background()) - reader, err := upload.GetReader(context.Background()) + + ctx := context.Background() + + if start > 0 { + endPosition := start + info.Size - 1 + rangeHeader := fmt.Sprintf("bytes=%d-%d", start, endPosition) + ctx = context.WithValue(ctx, "range", rangeHeader) + } + + reader, err := upload.GetReader(ctx) return reader, info.Size, err }