Major restructure, bundle blobs
This commit also breaks the repository format.
This commit is contained in:
parent
b836da1980
commit
60a0fe8349
29 changed files with 937 additions and 1123 deletions
|
@ -3,6 +3,7 @@ package backend
|
|||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -96,3 +97,33 @@ outer:
|
|||
|
||||
return IDSize, nil
|
||||
}
|
||||
|
||||
// wrap around io.LimitedReader that implements io.ReadCloser
|
||||
type blobReader struct {
|
||||
f 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.closed {
|
||||
err := l.f.Close()
|
||||
l.closed = true
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func LimitReader(f io.ReadCloser, n int64) *blobReader {
|
||||
return &blobReader{f: f, rd: io.LimitReader(f, n)}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue