repository: add PackBlob.UncompressedCiphertextLength()

This commit is contained in:
Michael Eischer
2026-06-05 13:18:59 +02:00
parent e247118f49
commit c967d634be
5 changed files with 16 additions and 3 deletions
+2 -3
View File
@@ -11,7 +11,6 @@ import (
"time"
"github.com/restic/chunker"
"github.com/restic/restic/internal/crypto"
"github.com/restic/restic/internal/data"
"github.com/restic/restic/internal/global"
"github.com/restic/restic/internal/repository"
@@ -168,10 +167,10 @@ func runStats(ctx context.Context, opts StatsOptions, gopts global.Options, args
}
stats.TotalSize += uint64(pbs[0].CiphertextLength())
if repo.Config().Version >= 2 {
stats.TotalUncompressedSize += uint64(crypto.CiphertextLength(int(pbs[0].PlaintextLength())))
stats.TotalUncompressedSize += uint64(pbs[0].UncompressedCiphertextLength())
if pbs[0].IsCompressed() {
stats.TotalCompressedBlobsSize += uint64(pbs[0].CiphertextLength())
stats.TotalCompressedBlobsUncompressedSize += uint64(crypto.CiphertextLength(int(pbs[0].PlaintextLength())))
stats.TotalCompressedBlobsUncompressedSize += uint64(pbs[0].UncompressedCiphertextLength())
}
}
stats.TotalBlobCount++
+4
View File
@@ -27,6 +27,10 @@ func (b Blob) DataLength() uint {
return uint(crypto.PlaintextLength(int(b.Length)))
}
func (b Blob) UncompressedCiphertextLength() uint {
return uint(crypto.CiphertextLength(int(b.DataLength())))
}
func (b Blob) IsCompressed() bool {
return b.UncompressedLength != 0
}
+6
View File
@@ -8,12 +8,18 @@ type PackedBlob struct {
Blob Blob
}
var _ restic.PackBlob = (*PackedBlob)(nil)
func (pb *PackedBlob) PackID() restic.ID { return pb.Pack }
func (pb *PackedBlob) Handle() restic.BlobHandle { return pb.Blob.BlobHandle }
func (pb *PackedBlob) CiphertextLength() uint { return pb.Blob.Length }
func (pb *PackedBlob) UncompressedCiphertextLength() uint {
return pb.Blob.UncompressedCiphertextLength()
}
func (pb *PackedBlob) PlaintextLength() uint { return pb.Blob.DataLength() }
func (pb *PackedBlob) IsCompressed() bool { return pb.Blob.IsCompressed() }
+2
View File
@@ -14,6 +14,8 @@ type PackBlob interface {
Handle() BlobHandle
// CiphertextLength is the encrypted size stored in the pack.
CiphertextLength() uint
// UncompressedCiphertextLength is the encrypted size of the uncompressed blob.
UncompressedCiphertextLength() uint
// PlaintextLength is the size after decryption/decompression.
PlaintextLength() uint
IsCompressed() bool
+2
View File
@@ -47,6 +47,8 @@ func (pb *testPackBlob) Handle() restic.BlobHandle { return pb.handle }
func (pb *testPackBlob) CiphertextLength() uint { return pb.ciphertext }
func (pb *testPackBlob) UncompressedCiphertextLength() uint { return pb.ciphertext }
func (pb *testPackBlob) PlaintextLength() uint { return pb.plaintext }
func (pb *testPackBlob) IsCompressed() bool { return pb.compressed }