Skip to content

Commit

Permalink
client/object: Allow zero range in payload range and hash ops (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-khimov authored Feb 24, 2025
2 parents cff5633 + 3141d39 commit bf4a81e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion client/object_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ func (x *ObjectRangeReader) Read(p []byte) (int, error) {
// ObjectRangeInit initiates reading an object's payload range through a remote
// server using NeoFS API protocol.
//
// To get full payload, set both offset and length to zero. Otherwise, length
// must not be zero.
//
// The call only opens the transmission channel, explicit fetching is done using the ObjectRangeReader.
// Exactly one return value is non-nil. Resulting reader must be finally closed.
//
Expand All @@ -692,7 +695,7 @@ func (c *Client) ObjectRangeInit(ctx context.Context, containerID cid.ID, object
}()
}

if length == 0 {
if length == 0 && offset != 0 {
err = ErrZeroRangeLength
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion client/object_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (x *testGetObjectPayloadRangeServer) verifyRequest(req *protoobject.GetRang
if body.Range == nil {
return newErrMissingRequestBodyField("range")
}
if body.Range.Length == 0 {
if body.Range.Length == 0 && body.Range.Offset != 0 {
return newErrInvalidRequestField("range", errors.New("zero length"))
}
if x.reqRng != nil {
Expand Down
3 changes: 3 additions & 0 deletions client/object_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (x *PrmObjectHash) UseSalt(salt []byte) {
// ObjectHash requests checksum of the range list of the object payload using
// NeoFS API protocol.
//
// To hash full payload, set both offset and length to zero. Otherwise, length
// must not be zero.
//
// Returns a list of checksums in raw form: the format of hashes and their number
// is left for the caller to check. Client preserves the order of the server's response.
//
Expand Down

0 comments on commit bf4a81e

Please sign in to comment.