diff --git a/objstore.go b/objstore.go index d05bc01..33c6e5e 100644 --- a/objstore.go +++ b/objstore.go @@ -280,6 +280,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) } 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) +}