backend: rename LimitReader to LimitReadCloser

This commit is contained in:
Alexander Neumann 2015-05-02 16:13:56 +02:00
parent 0ca678228d
commit 1f94ac724f
3 changed files with 8 additions and 6 deletions

View File

@ -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)}
}

View File

@ -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.

View File

@ -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.