1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-25 01:06:39 +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():]
plaintext, err := key.Open(ciphertext[:0], nonce, ciphertext, nil)
if err == nil && entry.IsCompressed() {
if cap(decode) < int(entry.DataLength()) {
decode = make([]byte, 0, entry.DataLength())
}
// DecodeAll will allocate a slice if it is not large enough since it
// knows the decompressed size (because we're using EncodeAll)
decode, err = dec.DecodeAll(plaintext, decode[:0])
plaintext = decode
if err != nil {