2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 06:46:34 +00:00

Make decryptReader fulfill flate.Reader

benchmark               old ns/op     new ns/op     delta
    BenchmarkLoadJSONID     50232171      48596972      -3.26%

    benchmark               old allocs     new allocs     delta
    BenchmarkLoadJSONID     43643          42884          -1.74%

    benchmark               old bytes     new bytes     delta
    BenchmarkLoadJSONID     5773048       3785517       -34.43%
This commit is contained in:
Alexander Neumann 2015-02-18 23:30:59 +01:00
parent a0fea201d9
commit 2f3aa344af
2 changed files with 22 additions and 1 deletions

18
key.go
View File

@ -543,6 +543,24 @@ func (d *decryptReader) Read(dst []byte) (int, error) {
return n, nil
}
func (d *decryptReader) ReadByte() (c byte, err error) {
if d.buf == nil {
return 0, io.EOF
}
remaining := len(d.buf) - d.pos
if remaining == 1 {
c = d.buf[d.pos]
d.Close()
return c, io.EOF
}
c = d.buf[d.pos]
d.pos++
return
}
func (d *decryptReader) Close() error {
if d.buf == nil {
return nil

View File

@ -2,6 +2,7 @@ package restic
import (
"bytes"
"compress/flate"
"compress/zlib"
"crypto/sha256"
"encoding/json"
@ -146,8 +147,10 @@ func (s Server) LoadJSONID(t backend.Type, storageID backend.ID, item interface{
}
// unzip
br := decryptRd.(flate.Reader)
unzipRd := zReaderPool.Get().(zReader)
err = unzipRd.Reset(decryptRd, nil)
err = unzipRd.Reset(br, nil)
defer func() {
unzipRd.Close()
zReaderPool.Put(unzipRd)