2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-28 14:40:49 +00:00
restic/internal/fuse/blob_size_cache.go

36 lines
772 B
Go
Raw Normal View History

// +build !openbsd
// +build !windows
2017-06-18 12:59:44 +00:00
package fuse
import (
2017-07-24 15:42:25 +00:00
"github.com/restic/restic/internal/restic"
2017-06-18 12:59:44 +00:00
"golang.org/x/net/context"
)
// BlobSizeCache caches the size of blobs in the repo.
type BlobSizeCache struct {
m map[restic.ID]uint
}
// NewBlobSizeCache returns a new blob size cache containing all entries from midx.
func NewBlobSizeCache(ctx context.Context, idx restic.Index) *BlobSizeCache {
m := make(map[restic.ID]uint, 1000)
for pb := range idx.Each(ctx) {
2017-06-18 14:28:39 +00:00
m[pb.ID] = uint(restic.PlaintextLength(int(pb.Length)))
2017-06-18 12:59:44 +00:00
}
return &BlobSizeCache{
m: m,
}
}
// Lookup returns the size of the blob id.
func (c *BlobSizeCache) Lookup(id restic.ID) (size uint, found bool) {
if c == nil {
return 0, false
}
size, found = c.m[id]
return size, found
}