From 88a1fdc840f33c880f6a35f022fb78f0e78b9959 Mon Sep 17 00:00:00 2001 From: thorfour Date: Mon, 28 Oct 2024 08:22:28 -0500 Subject: [PATCH 1/2] Support io.LimitedReader in object size check Signed-off-by: thorfour --- objstore.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/objstore.go b/objstore.go index 62f1c65..ab663ef 100644 --- a/objstore.go +++ b/objstore.go @@ -211,6 +211,8 @@ func TryToGetSize(r io.Reader) (int64, error) { return f.Size(), nil case ObjectSizer: return f.ObjectSize() + case *io.LimitedReader: + return f.N, nil } return 0, errors.Errorf("unsupported type of io.Reader: %T", r) } From fe7aa2db1fb6b4ae057b5e2b40a8f27e0efd1116 Mon Sep 17 00:00:00 2001 From: thorfour Date: Mon, 28 Oct 2024 08:28:42 -0500 Subject: [PATCH 2/2] unit test Signed-off-by: thorfour --- objstore_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/objstore_test.go b/objstore_test.go index 51486d2..b1f8292 100644 --- a/objstore_test.go +++ b/objstore_test.go @@ -595,3 +595,11 @@ func (b *mockBucket) GetRange(ctx context.Context, name string, off, length int6 } return nil, errors.New("GetRange has not been mocked") } + +func Test_TryToGetSizeLimitedReader(t *testing.T) { + b := &bytes.Buffer{} + r := io.LimitReader(b, 1024) + size, err := TryToGetSize(r) + testutil.Ok(t, err) + testutil.Equals(t, int64(1024), size) +}