From 1f94ac724fe01365b23ae114222dfa6c42fdf3e1 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 2 May 2015 16:13:56 +0200 Subject: [PATCH] backend: rename LimitReader to LimitReadCloser --- backend/generic.go | 10 ++++++---- backend/local/local.go | 2 +- backend/sftp/sftp.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backend/generic.go b/backend/generic.go index 0244cdab1..c7d569972 100644 --- a/backend/generic.go +++ b/backend/generic.go @@ -100,7 +100,7 @@ outer: // wrap around io.LimitedReader that implements io.ReadCloser type blobReader struct { - f io.Closer + cl io.Closer rd io.Reader closed bool } @@ -120,7 +120,7 @@ func (l *blobReader) Close() error { } if !l.closed { - err := l.f.Close() + err := l.cl.Close() l.closed = true return err } @@ -128,6 +128,8 @@ func (l *blobReader) Close() error { return nil } -func LimitReader(f io.ReadCloser, n int64) *blobReader { - return &blobReader{f: f, rd: io.LimitReader(f, n)} +// LimitReadCloser returns a new reader wraps r in an io.LimitReader, but also +// implements the Close() method. +func LimitReadCloser(r io.ReadCloser, n int64) *blobReader { + return &blobReader{cl: r, rd: io.LimitReader(r, n)} } diff --git a/backend/local/local.go b/backend/local/local.go index 0fbd5fcf7..a50d2ef31 100644 --- a/backend/local/local.go +++ b/backend/local/local.go @@ -312,7 +312,7 @@ func (b *Local) GetReader(t backend.Type, name string, offset, length uint) (io. return f, nil } - return backend.LimitReader(f, int64(length)), nil + return backend.LimitReadCloser(f, int64(length)), nil } // Test returns true if a blob of the given type and name exists in the backend. diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index 09dad6242..5c850ce77 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -446,7 +446,7 @@ func (r *SFTP) GetReader(t backend.Type, name string, offset, length uint) (io.R return f, nil } - return backend.LimitReader(f, int64(length)), nil + return backend.LimitReadCloser(f, int64(length)), nil } // Test returns true if a blob of the given type and name exists in the backend.