repository: Remove pack implementation details from MasterIndex

This commit is contained in:
Michael Eischer committed 2022-03-28 22:09:49 +02:00
1 parent dc3d77dacc
commit f78bd14e28
6 files changed
+31 -26

No files matched your search

+26
View File
@@ -1,6 +1,7 @@
package pack
import (
"context"
"encoding/binary"
"fmt"
"io"
@@ -317,3 +318,28 @@ func parseHeaderEntry(p []byte) (b restic.Blob, err error) {
return b, nil
}
func CalculateHeaderSize(blobs []restic.Blob) int {
return HeaderSize + len(blobs)*int(EntrySize)
}
// Size returns the size of all packs computed by index information.
// If onlyHdr is set to true, only the size of the header is returned
// Note that this function only gives correct sizes, if there are no
// duplicates in the index.
func Size(ctx context.Context, mi restic.MasterIndex, onlyHdr bool) map[restic.ID]int64 {
packSize := make(map[restic.ID]int64)
for blob := range mi.Each(ctx) {
size, ok := packSize[blob.PackID]
if !ok {
size = HeaderSize
}
if !onlyHdr {
size += int64(blob.Length)
}
packSize[blob.PackID] = size + int64(EntrySize)
}
return packSize
}