Skip to content

Commit

Permalink
Support io.LimitedReader in object size check (#152)
Browse files Browse the repository at this point in the history
* Support io.LimitedReader in object size check

Signed-off-by: thorfour <[email protected]>

* unit test

Signed-off-by: thorfour <[email protected]>

---------

Signed-off-by: thorfour <[email protected]>
  • Loading branch information
thorfour authored Oct 31, 2024
1 parent cfdd0e5 commit 8648e8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 8 additions & 0 deletions objstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 8648e8e

Please sign in to comment.