2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-01 08:30:49 +00:00

Leave allocating slices to the decompress code

This commit is contained in:
Alexander Neumann 2022-04-20 20:55:43 +02:00 committed by Michael Eischer
parent 5eb05a0afe
commit 8776031f96

View File

@ -1021,9 +1021,8 @@ func StreamPack(ctx context.Context, beLoad BackendLoadFn, key *crypto.Key, pack
nonce, ciphertext := buf[:key.NonceSize()], buf[key.NonceSize():] nonce, ciphertext := buf[:key.NonceSize()], buf[key.NonceSize():]
plaintext, err := key.Open(ciphertext[:0], nonce, ciphertext, nil) plaintext, err := key.Open(ciphertext[:0], nonce, ciphertext, nil)
if err == nil && entry.IsCompressed() { if err == nil && entry.IsCompressed() {
if cap(decode) < int(entry.DataLength()) { // DecodeAll will allocate a slice if it is not large enough since it
decode = make([]byte, 0, entry.DataLength()) // knows the decompressed size (because we're using EncodeAll)
}
decode, err = dec.DecodeAll(plaintext, decode[:0]) decode, err = dec.DecodeAll(plaintext, decode[:0])
plaintext = decode plaintext = decode
if err != nil { if err != nil {