forked from TrueCloudLab/frostfs-node
[#1198] neofs-cli: Use io.Copy
instead of io.CopyBuffer
The buffer size value is somewhat arbitrary and making in configurable doesn't make much sense, given that we can't really restrict total resource consumption in other places. `Copy` uses 32 KiB buffer by default, which is not big. This approach is also more flexible as we can get rid of buffer completely by implementing `ReaderFrom`, `WriterTo` interfaces. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
cbe07120da
commit
571ae843ad
1 changed files with 2 additions and 21 deletions
|
@ -483,11 +483,6 @@ func (x GetObjectRes) Header() *object.Object {
|
||||||
return x.hdr
|
return x.hdr
|
||||||
}
|
}
|
||||||
|
|
||||||
// maximum size of the buffer use for io.Copy*.
|
|
||||||
// Chosen small due to the expected low volume of NeoFS CLI process resources.
|
|
||||||
// TODO: (neofs-node#1198) explore better values or configure it
|
|
||||||
const maxPayloadBufferSize = 1024
|
|
||||||
|
|
||||||
// GetObject reads the object by address.
|
// GetObject reads the object by address.
|
||||||
//
|
//
|
||||||
// Interrupts on any writer error. If successful, payload is written to writer.
|
// Interrupts on any writer error. If successful, payload is written to writer.
|
||||||
|
@ -538,14 +533,7 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
||||||
prm.headerCallback(&hdr)
|
prm.headerCallback(&hdr)
|
||||||
}
|
}
|
||||||
|
|
||||||
sz := hdr.PayloadSize()
|
_, err = io.Copy(prm.wrt, rdr)
|
||||||
if sz > maxPayloadBufferSize {
|
|
||||||
sz = maxPayloadBufferSize
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := make([]byte, sz)
|
|
||||||
|
|
||||||
_, err = io.CopyBuffer(prm.wrt, rdr, buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("copy payload: %w", err)
|
return nil, fmt.Errorf("copy payload: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -860,14 +848,7 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
||||||
return nil, fmt.Errorf("init payload reading: %w", err)
|
return nil, fmt.Errorf("init payload reading: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sz := prm.rng.GetLength()
|
_, err = io.Copy(prm.wrt, rdr)
|
||||||
if sz > maxPayloadBufferSize {
|
|
||||||
sz = maxPayloadBufferSize
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := make([]byte, sz)
|
|
||||||
|
|
||||||
_, err = io.CopyBuffer(prm.wrt, rdr, buf)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("copy payload: %w", err)
|
return nil, fmt.Errorf("copy payload: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue