backend: Remove GetReader
This commit is contained in:
parent
2c3a6a6fa9
commit
adbe9e2e1c
13 changed files with 26 additions and 288 deletions
|
@ -3,7 +3,6 @@ package backend
|
|||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -82,39 +81,3 @@ outer:
|
|||
|
||||
return IDSize, nil
|
||||
}
|
||||
|
||||
// wrap around io.LimitedReader that implements io.ReadCloser
|
||||
type blobReader struct {
|
||||
cl io.Closer
|
||||
rd io.Reader
|
||||
closed bool
|
||||
}
|
||||
|
||||
func (l *blobReader) Read(p []byte) (int, error) {
|
||||
n, err := l.rd.Read(p)
|
||||
if err == io.EOF {
|
||||
l.Close()
|
||||
}
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (l *blobReader) Close() error {
|
||||
if l == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !l.closed {
|
||||
err := l.cl.Close()
|
||||
l.closed = true
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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)}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue