forked from mirrors/tar-split
tar/storage: Replace TeeReader with MultiWriter
It uses slightly less memory and more understandable. Benchmar results: benchmark old ns/op new ns/op delta BenchmarkPutter-4 57272 52375 -8.55% benchmark old allocs new allocs delta BenchmarkPutter-4 21 19 -9.52% benchmark old bytes new bytes delta BenchmarkPutter-4 19416 13336 -31.31% Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
ea73dc6f6f
commit
45399711c2
1 changed files with 6 additions and 6 deletions
|
@ -59,15 +59,15 @@ func (bfgp bufferFileGetPutter) Get(name string) (io.ReadCloser, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bfgp *bufferFileGetPutter) Put(name string, r io.Reader) (int64, []byte, error) {
|
func (bfgp *bufferFileGetPutter) Put(name string, r io.Reader) (int64, []byte, error) {
|
||||||
c := crc64.New(CRCTable)
|
crc := crc64.New(CRCTable)
|
||||||
tRdr := io.TeeReader(r, c)
|
buf := bytes.NewBuffer(nil)
|
||||||
b := bytes.NewBuffer([]byte{})
|
cw := io.MultiWriter(crc, buf)
|
||||||
i, err := io.Copy(b, tRdr)
|
i, err := io.Copy(cw, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
bfgp.files[name] = b.Bytes()
|
bfgp.files[name] = buf.Bytes()
|
||||||
return i, c.Sum(nil), nil
|
return i, crc.Sum(nil), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type readCloserWrapper struct {
|
type readCloserWrapper struct {
|
||||||
|
|
Loading…
Reference in a new issue