mirror of
https://github.com/restic/restic.git
synced 2024-12-23 08:16:36 +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:
parent
a0fea201d9
commit
2f3aa344af
2 changed files with 22 additions and 1 deletions
18
key.go
18
key.go
|
@ -543,6 +543,24 @@ func (d *decryptReader) Read(dst []byte) (int, error) {
|
||||||
return n, nil
|
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 {
|
func (d *decryptReader) Close() error {
|
||||||
if d.buf == nil {
|
if d.buf == nil {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -2,6 +2,7 @@ package restic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"compress/flate"
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -146,8 +147,10 @@ func (s Server) LoadJSONID(t backend.Type, storageID backend.ID, item interface{
|
||||||
}
|
}
|
||||||
|
|
||||||
// unzip
|
// unzip
|
||||||
|
br := decryptRd.(flate.Reader)
|
||||||
|
|
||||||
unzipRd := zReaderPool.Get().(zReader)
|
unzipRd := zReaderPool.Get().(zReader)
|
||||||
err = unzipRd.Reset(decryptRd, nil)
|
err = unzipRd.Reset(br, nil)
|
||||||
defer func() {
|
defer func() {
|
||||||
unzipRd.Close()
|
unzipRd.Close()
|
||||||
zReaderPool.Put(unzipRd)
|
zReaderPool.Put(unzipRd)
|
||||||
|
|
Loading…
Reference in a new issue