mirror of
https://github.com/octoleo/restic.git
synced 2024-12-26 20:30:19 +00:00
Remove Compress() and Uncompress() from backend
This commit is contained in:
parent
b762a342d3
commit
06ed5c12b8
@ -98,13 +98,14 @@ func (arch *Archiver) Save(t backend.Type, id backend.ID, length uint, rd io.Rea
|
||||
func (arch *Archiver) SaveTreeJSON(item interface{}) (Blob, error) {
|
||||
// convert to json
|
||||
data, err := json.Marshal(item)
|
||||
// append newline
|
||||
data = append(data, '\n')
|
||||
if err != nil {
|
||||
return Blob{}, err
|
||||
}
|
||||
|
||||
// check if tree has been saved before
|
||||
buf := backend.Compress(data)
|
||||
id := backend.Hash(buf)
|
||||
id := backend.Hash(data)
|
||||
blob, err := arch.m.FindID(id)
|
||||
|
||||
// return the blob if we found it
|
||||
@ -113,7 +114,7 @@ func (arch *Archiver) SaveTreeJSON(item interface{}) (Blob, error) {
|
||||
}
|
||||
|
||||
// otherwise save the data
|
||||
blob, err = arch.s.Save(backend.Tree, buf, id)
|
||||
blob, err = arch.s.SaveJSON(backend.Tree, item)
|
||||
if err != nil {
|
||||
return Blob{}, err
|
||||
}
|
||||
|
@ -2,11 +2,9 @@ package backend
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/zlib"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"sort"
|
||||
)
|
||||
|
||||
@ -65,38 +63,6 @@ func EachID(be Lister, t Type, f func(ID)) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compress applies zlib compression to data.
|
||||
func Compress(data []byte) []byte {
|
||||
// apply zlib compression
|
||||
var b bytes.Buffer
|
||||
w := zlib.NewWriter(&b)
|
||||
_, err := w.Write(data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.Close()
|
||||
|
||||
return b.Bytes()
|
||||
}
|
||||
|
||||
// Uncompress reverses zlib compression on data.
|
||||
func Uncompress(data []byte) []byte {
|
||||
b := bytes.NewBuffer(data)
|
||||
r, err := zlib.NewReader(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
r.Close()
|
||||
|
||||
return buf
|
||||
}
|
||||
|
||||
// Hash returns the ID for data.
|
||||
func Hash(data []byte) ID {
|
||||
h := hashData(data)
|
||||
|
Loading…
Reference in New Issue
Block a user