forked from TrueCloudLab/restic
cache: Replace readCloser+LimitedReader by backend.LimitedReadCloser
This commit is contained in:
parent
c0b5ec55ab
commit
72922a79ed
1 changed files with 4 additions and 10 deletions
14
internal/cache/file.go
vendored
14
internal/cache/file.go
vendored
|
@ -7,6 +7,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/restic/restic/internal/backend"
|
||||||
"github.com/restic/restic/internal/crypto"
|
"github.com/restic/restic/internal/crypto"
|
||||||
"github.com/restic/restic/internal/debug"
|
"github.com/restic/restic/internal/debug"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
|
@ -30,11 +31,6 @@ func (c *Cache) canBeCached(t restic.FileType) bool {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
type readCloser struct {
|
|
||||||
io.Reader
|
|
||||||
io.Closer
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load returns a reader that yields the contents of the file with the
|
// Load returns a reader that yields the contents of the file with the
|
||||||
// given handle. rd must be closed after use. If an error is returned, the
|
// given handle. rd must be closed after use. If an error is returned, the
|
||||||
// ReadCloser is nil.
|
// ReadCloser is nil.
|
||||||
|
@ -75,12 +71,10 @@ func (c *Cache) load(h restic.Handle, length int, offset int64) (io.ReadCloser,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rd := readCloser{Reader: f, Closer: f}
|
if length <= 0 {
|
||||||
if length > 0 {
|
return f, nil
|
||||||
rd.Reader = io.LimitReader(f, int64(length))
|
|
||||||
}
|
}
|
||||||
|
return backend.LimitReadCloser(f, int64(length)), nil
|
||||||
return rd, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save saves a file in the cache.
|
// Save saves a file in the cache.
|
||||||
|
|
Loading…
Reference in a new issue