From 72922a79ed153155b1c151d6303d01dca5c50af6 Mon Sep 17 00:00:00 2001 From: greatroar <61184462+greatroar@users.noreply.github.com> Date: Tue, 3 Jan 2023 19:03:36 +0100 Subject: [PATCH] cache: Replace readCloser+LimitedReader by backend.LimitedReadCloser --- internal/cache/file.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/internal/cache/file.go b/internal/cache/file.go index 5b93f3990..c315be19f 100644 --- a/internal/cache/file.go +++ b/internal/cache/file.go @@ -7,6 +7,7 @@ import ( "runtime" "github.com/pkg/errors" + "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/crypto" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/fs" @@ -30,11 +31,6 @@ func (c *Cache) canBeCached(t restic.FileType) bool { return ok } -type readCloser struct { - io.Reader - io.Closer -} - // 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 // 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 { - rd.Reader = io.LimitReader(f, int64(length)) + if length <= 0 { + return f, nil } - - return rd, nil + return backend.LimitReadCloser(f, int64(length)), nil } // Save saves a file in the cache.