forked from TrueCloudLab/rclone
cat: don't allocate buffers if not needed to reduce memory usage
This commit is contained in:
parent
dd20a297d6
commit
50e190ff54
1 changed files with 9 additions and 2 deletions
|
@ -1262,10 +1262,13 @@ func Cat(f Fs, w io.Writer, offset, count int64) error {
|
||||||
defer func() {
|
defer func() {
|
||||||
Stats.DoneTransferring(o.Remote(), err == nil)
|
Stats.DoneTransferring(o.Remote(), err == nil)
|
||||||
}()
|
}()
|
||||||
|
size := o.Size()
|
||||||
thisOffset := offset
|
thisOffset := offset
|
||||||
if thisOffset < 0 {
|
if thisOffset < 0 {
|
||||||
thisOffset += o.Size()
|
thisOffset += size
|
||||||
}
|
}
|
||||||
|
// size remaining is now reduced by thisOffset
|
||||||
|
size -= thisOffset
|
||||||
var options []OpenOption
|
var options []OpenOption
|
||||||
if thisOffset > 0 {
|
if thisOffset > 0 {
|
||||||
options = append(options, &SeekOption{Offset: thisOffset})
|
options = append(options, &SeekOption{Offset: thisOffset})
|
||||||
|
@ -1278,8 +1281,12 @@ func Cat(f Fs, w io.Writer, offset, count int64) error {
|
||||||
}
|
}
|
||||||
if count >= 0 {
|
if count >= 0 {
|
||||||
in = &readCloser{Reader: &io.LimitedReader{R: in, N: count}, Closer: in}
|
in = &readCloser{Reader: &io.LimitedReader{R: in, N: count}, Closer: in}
|
||||||
|
// reduce remaining size to count
|
||||||
|
if size > count {
|
||||||
|
size = count
|
||||||
|
}
|
||||||
}
|
}
|
||||||
in = NewAccountWithBuffer(in, o) // account and buffer the transfer
|
in = NewAccountSizeNameWithBuffer(in, size, o.Remote()) // account and buffer the transfer
|
||||||
defer func() {
|
defer func() {
|
||||||
err = in.Close()
|
err = in.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue