// Blobs is part of the Container interface.
506215
func (c container) Blobs() ([]Blob, error) {
	//TODO(axw) handle pagination.
	resp, err := c.Container.ListBlobs(storage.ListBlobsParameters{})
	if err != nil {
		return nil, errors.Trace(err)
	}
	blobs := make([]Blob, len(resp.Blobs))
	for i := range blobs {
		blobs[i] = blob{&resp.Blobs[i]}
	}
	return blobs, nil
}
1056803
func (st largeBlobStreamer) StreamBlobs(ctx context.Context, dest chan<- blobserver.BlobAndToken, contToken string) (err error) {
	defer close(dest)
	s := st.sto
	large := s.large

	var after string // for enumerateAll
	var skipFiles int
	var firstRef blob.Ref // first we care about

	if contToken != "" {
		f := strings.SplitN(contToken, ":", 2)
		if len(f) != 2 {
			return errContToken
		}
		firstRef, _ = blob.Parse(f[0])
		skipFiles, err = strconv.Atoi(f[1])
		if !firstRef.Valid() || err != nil {
			return errContToken
		}
		// EnumerateAllFrom takes a cursor that's greater, but
		// we want to start _at_ firstRef. So start
		// enumerating right before our target.
		after = firstRef.StringMinusOne()
	}
	return blobserver.EnumerateAllFrom(ctx, large, after, func(sb blob.SizedRef) error {
		if firstRef.Valid() {
			if sb.Ref.Less(firstRef) {
				// Skip.
				return nil
			}
			if firstRef.Less(sb.Ref) {
				skipFiles = 0 // reset it.
			}
		}
		fileN := 0
		return s.foreachZipBlob(ctx, sb.Ref, func(bap BlobAndPos) error {
			if skipFiles > 0 {
				skipFiles--
				fileN++
				return nil
			}
			select {
			case dest <- blobserver.BlobAndToken{
				Blob: blob.NewBlob(bap.Ref, bap.Size, func(ctx context.Context) ([]byte, error) {
					return slurpSizedRef(ctx, s, bap.SizedRef)
				}),
				Token: fmt.Sprintf("%s:%d", sb.Ref, fileN),
			}:
				fileN++
				return nil
			case <-ctx.Done():
				return ctx.Err()
			}
		})
	})
}
1267610
func (c *Client) ListBlobs(ctx context.Context, container string, maxResults int) (blobs []*Blob, err error) {
	if maxResults < 0 {
		return nil, errors.New("invalid negative maxKeys")
	}
	marker := ""
	for len(blobs) < maxResults {
		fetchN := maxResults - len(blobs)
		if fetchN > maxList {
			fetchN = maxList
		}
		var bres listBlobsResults

		listURL := fmt.Sprintf("%s?restype=container&comp=list&marker=%s&maxresults=%d",
			c.containerURL(container), url.QueryEscape(marker), fetchN)

		req := newReq(ctx, listURL)
		c.Auth.SignRequest(req)

		res, err := c.transport().RoundTrip(req)
		if err != nil {
			return nil, err
		}
		if res.StatusCode != http.StatusOK {
			if res.StatusCode < 500 {
				aerr := getAzureError("ListBlobs", res)
				return nil, aerr
			}
		} else {
			bres = listBlobsResults{}
			var logbuf bytes.Buffer
			err = xml.NewDecoder(io.TeeReader(res.Body, &logbuf)).Decode(&bres)
			if err != nil {
				log.Printf("Error parsing Azure XML response: %v for %q", err, logbuf.Bytes())
			} else if bres.MaxResults != fetchN || bres.ContainerName != container || bres.Marker != marker {
				err = fmt.Errorf("unexpected parse from server: %#v from: %s", bres, logbuf.Bytes())
				log.Print(err)
			}
		}
		res.Body.Close()
		if err != nil {
			log.Print(err)
			return nil, err
		}

		for _, it := range bres.Blobs.Blob {
			blobs = append(blobs, it)
		}
		if bres.NextMarker == "" {
			// No more blobs to list
			break
		}
		marker = bres.NextMarker
	}
	return blobs, nil
}
424346
func (buh *blobUploadHandler) writeBlobCreatedHeaders(w http.ResponseWriter, desc distribution.Descriptor) error {
	ref, err := reference.WithDigest(buh.Repository.Named(), desc.Digest)
	if err != nil {
		return err
	}
	blobURL, err := buh.urlBuilder.BuildBlobURL(ref)
	if err != nil {
		return err
	}

	w.Header().Set("Location", blobURL)
	w.Header().Set("Content-Length", "0")
	w.Header().Set("Docker-Content-Digest", desc.Digest.String())
	w.WriteHeader(http.StatusCreated)
	return nil
}
601392
func (sto *overlayStorage) EnumerateBlobs(ctx context.Context, dest chan<- blob.SizedRef, after string, limit int) error {
	defer close(dest)

	enums := []blobserver.BlobEnumerator{sto.lower, sto.upper}

	// Ensure that we send limit blobs if possible.
	sent := 0
	for sent < limit {
		ch := make(chan blob.SizedRef)
		errch := make(chan error, 1)
		go func() {
			errch <- blobserver.MergedEnumerate(ctx, ch, enums, after, limit-sent)
		}()

		var last blob.Ref

		// Yield all blobs that weren't deleted from ch to destch.
		seen := 0
		for sbr := range ch {
			seen++
			if !sto.isDeleted(sbr.Ref) {
				log.Println(sent, sbr.Ref)
				dest <- sbr
				sent++
			}
			last = sbr.Ref
		}

		if err := <-errch; err != nil {
			return err
		}

		// if no blob was received, enumeration is finished
		if seen == 0 {
			return nil
		}

		// resume enumeration after the last blob seen
		after = last.String()
	}

	return nil
}
1200542
func (repo *repository) Blobs(ctx context.Context) distribution.BlobStore {
	var statter distribution.BlobDescriptorService = &linkedBlobStatter{
		blobStore:   repo.blobStore,
		repository:  repo,
		linkPathFns: []linkPathFunc{blobLinkPath},
	}

	if repo.descriptorCache != nil {
		statter = cache.NewCachedBlobStatter(repo.descriptorCache, statter)
	}

	if repo.registry.blobDescriptorServiceFactory != nil {
		statter = repo.registry.blobDescriptorServiceFactory.BlobAccessController(statter)
	}

	return &linkedBlobStore{
		registry:             repo.registry,
		blobStore:            repo.blobStore,
		blobServer:           repo.blobServer,
		blobAccessController: statter,
		repository:           repo,
		ctx:                  ctx,

		// TODO(stevvooe): linkPath limits this blob store to only layers.
		// This instance cannot be used for manifest checks.
		linkPathFns:            []linkPathFunc{blobLinkPath},
		deleteEnabled:          repo.registry.deleteEnabled,
		resumableDigestEnabled: repo.resumableDigestEnabled,
	}
}
616155
func (l *location) filesToContainers(root string, files ...string) ([]stow.Container, error) {
	cs := make([]stow.Container, 0, len(files))
	for _, f := range files {
		info, err := os.Stat(f)
		if err != nil {
			return nil, err
		}
		if !info.IsDir() {
			continue
		}
		absroot, err := filepath.Abs(root)
		if err != nil {
			return nil, err
		}
		path, err := filepath.Abs(f)
		if err != nil {
			return nil, err
		}
		name, err := filepath.Rel(absroot, path)
		if err != nil {
			return nil, err
		}
		cs = append(cs, &container{
			name: name,
			path: path,
		})
	}
	return cs, nil
}
1266776
func (sto *replicaStorage) StatBlobs(ctx context.Context, blobs []blob.Ref, fn func(blob.SizedRef) error) error {
	var (
		mu     sync.Mutex // serializes calls to fn, guards need
		need   = make(map[blob.Ref]bool)
		failed bool
	)
	for _, br := range blobs {
		need[br] = true
	}

	group, ctx := errgroup.WithContext(ctx)

	for _, replica := range sto.readReplicas {
		replica := replica
		group.Go(func() error {
			return replica.StatBlobs(ctx, blobs, func(sb blob.SizedRef) error {
				mu.Lock()
				defer mu.Unlock()
				if failed {
					return nil
				}
				if !need[sb.Ref] {
					// dup, lost race from other replica
					return nil
				}
				delete(need, sb.Ref)
				if err := fn(sb); err != nil {
					failed = true
					return err
				}
				return nil
			})
		})
	}

	return group.Wait()
}
850001
func (s *storage) foreachZipBlob(ctx context.Context, zipRef blob.Ref, fn func(BlobAndPos) error) error {
	sb, err := blobserver.StatBlob(ctx, s.large, zipRef)
	if err != nil {
		return err
	}
	zr, err := zip.NewReader(blob.ReaderAt(ctx, s.large, zipRef), int64(sb.Size))
	if err != nil {
		return zipOpenError{zipRef, err}
	}
	var maniFile *zip.File // or nil if not found
	var firstOff int64     // offset of first file (the packed data chunks)
	for i, f := range zr.File {
		if i == 0 {
			firstOff, err = f.DataOffset()
			if err != nil {
				return err
			}
		}
		if f.Name == zipManifestPath {
			maniFile = f
			break
		}
	}
	if maniFile == nil {
		return errors.New("no camlistore manifest file found in zip")
	}
	// apply fn to all the schema blobs
	for _, f := range zr.File {
		if !strings.HasPrefix(f.Name, "camlistore/") || f.Name == zipManifestPath ||
			!strings.HasSuffix(f.Name, ".json") {
			continue
		}
		brStr := strings.TrimSuffix(strings.TrimPrefix(f.Name, "camlistore/"), ".json")
		br, ok := blob.Parse(brStr)
		if ok {
			off, err := f.DataOffset()
			if err != nil {
				return err
			}
			if err := fn(BlobAndPos{
				SizedRef: blob.SizedRef{Ref: br, Size: uint32(f.UncompressedSize64)},
				Offset:   off,
			}); err != nil {
				return err
			}
		}
	}
	maniRC, err := maniFile.Open()
	if err != nil {
		return err
	}
	defer maniRC.Close()

	var mf Manifest
	if err := json.NewDecoder(maniRC).Decode(&mf); err != nil {
		return err
	}
	if !mf.WholeRef.Valid() || mf.WholeSize == 0 || !mf.DataBlobsOrigin.Valid() {
		return errors.New("incomplete blobpack manifest JSON")
	}
	// apply fn to all the data blobs
	for _, bap := range mf.DataBlobs {
		bap.Offset += firstOff
		if err := fn(bap); err != nil {
			return err
		}
	}
	return nil
}
458853
func (sto *unionStorage) RemoveBlobs(ctx context.Context, blobs []blob.Ref) error {
	return blobserver.ErrReadonly
}
643778
func FileContains(filename string, subslice []byte, fs afero.Fs) (bool, error) {
	return afero.FileContainsBytes(fs, filename, subslice)
}
481599
func (b *Blob) Data() (io.Reader, error) {
	stdout := new(bytes.Buffer)
	stderr := new(bytes.Buffer)

	// Preallocate memory to save ~50% memory usage on big files.
	stdout.Grow(int(b.Size() + 2048))

	if err := b.DataPipeline(stdout, stderr); err != nil {
		return nil, concatenateError(err, stderr.String())
	}
	return stdout, nil
}
241638
func (r repositoryVerifier) Blobs(ctx context.Context) distribution.BlobStore {
	return blobStoreVerifier{BlobStore: r.Repository.Blobs(ctx)}
}
909946
func (c *Corpus) EnumerateSingleBlob(fn func(camtypes.BlobMeta) bool, br blob.Ref) {
	if bm := c.blobs[br]; bm != nil {
		fn(*bm)
	}
}
1031933
func (sb *storageBackend) AllVolumes() ([]Volume, error) {
	volumes, err := sb.volumes(nil)
	if err != nil {
		return nil, errors.Annotate(err, "cannot get volumes")
	}
	return volumesToInterfaces(volumes), nil
}
1354566
func StorageBackends() []string {
	bes := make([]string, 0, len(storageNameToBackendMap))
	for k := range storageNameToBackendMap {
		bes = append(bes, k)
	}
	sort.Strings(bes)
	return bes
}
1185224
func (v *azureVolumeSource) listBlobs(ctx context.ProviderCallContext) ([]internalazurestorage.Blob, error) {
	blobsClient := v.maybeStorageClient.GetBlobService()
	vhdContainer := blobsClient.GetContainerReference(dataDiskVHDContainer)
	// TODO(axw) consider taking a set of IDs and computing the
	//           longest common prefix to pass in the parameters
	blobs, err := vhdContainer.Blobs()
	if err != nil {
		errorutils.HandleCredentialError(err, ctx)
		if err, ok := err.(azurestorage.AzureStorageServiceError); ok {
			switch err.Code {
			case "ContainerNotFound":
				return nil, nil
			}
		}
		return nil, errors.Annotate(err, "listing blobs")
	}
	return blobs, nil
}