func (f *FetcherEnumerator) Add(b *blob.Blob) { if *cacheSizeMB <= 0 { return } f.cached += int64(b.Size()) if f.cached >= int64(*cacheSizeMB)*512*1024 { f.cached = 0 f.c2 = f.c1 f.c1 = make(map[string]*blob.Blob) } f.c1[b.Ref().Digest()] = b }
func verifySizeAndHash(t *testing.T, blob *blob.Blob) { hash := sha1.New() r := blob.Open() n, err := io.Copy(hash, r) if err != nil { t.Fatal(err) } r.Close() if uint32(n) != blob.Size() { t.Fatalf("read %d bytes from blob %v; want %v", n, blob.Ref(), blob.Size()) } if !blob.SizedRef().HashMatches(hash) { t.Fatalf("read wrong bytes from blobref %v (digest mismatch)", blob.Ref()) } }