You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: pull.go
    path of file: ./repos/faasd/vendor/github.com/containerd/containerd
    
    the code of the file until where you have to start completion: /*
   Copyright The containerd Authors.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package containerd

import (
	"context"
	"errors"
	"fmt"

	"github.com/containerd/containerd/errdefs"
	"github.com/containerd/containerd/images"
	"github.com/containerd/containerd/pkg/unpack"
	"github.com/containerd/containerd/platforms"
	"github.com/containerd/containerd/remotes"
	"github.com/containerd/containerd/remotes/docker"
	"github.com/containerd/containerd/remotes/docker/schema1" //nolint:staticcheck // Ignore SA1019. Need to keep deprecated package for compatibility.
	"github.com/containerd/containerd/tracing"
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
	"golang.org/x/sync/semaphore"
)

const (
	pullSpanPrefix = "pull"
)

// Pull downloads the provided content into containerd's content store
// and returns a platform specific image object
func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (_ Image, retErr error) {
	ctx, span := tracing.StartSpan(ctx, tracing.Name(pullSpanPrefix, "Pull"))
	defer span.End()

	pullCtx := defaultRemoteContext()

	for _, o := range opts {
		if err := o(c, pullCtx); err != nil {
			return nil, err
		}
	}

	if pullCtx.PlatformMatcher == nil {
		if len(pullCtx.Platforms) > 1 {
			return nil, errors.New("cannot pull multiplatform image locally, try Fetch")
		} else if len(pullCtx.Platforms) == 0 {
			pullCtx.PlatformMatcher = c.platform
		} else {
			p, err := platforms.Parse(pullCtx.Platforms[0])
			if err != nil {
				return nil, fmt.Errorf("invalid platform %s: %w", pullCtx.Platforms[0], err)
			}

			pullCtx.PlatformMatcher = platforms.Only(p)
		}
	}

	span.SetAttributes(
		tracing.Attribute("image.ref", ref),
		tracing.Attribute("unpack", pullCtx.Unpack),
		tracing.Attribute("max.concurrent.downlo
    
func (c *Client) Pull(ctx context.Context, ref string, opts ...RemoteOpt) (_ Image, retErr error) {
	ctx, span := tracing.StartSpan(ctx, tracing.Name(pullSpanPrefix, "Pull"))
	defer span.End()

	pullCtx := defaultRemoteContext()

	for _, o := range opts {
		if err := o(c, pullCtx); err != nil {
			return nil, err
		}
	}

	if pullCtx.PlatformMatcher == nil {
		if len(pullCtx.Platforms) > 1 {
			return nil, errors.New("cannot pull multiplatform image locally, try Fetch")
		} else if len(pullCtx.Platforms) == 0 {
			pullCtx.PlatformMatcher = c.platform
		} else {
			p, err := platforms.Parse(pullCtx.Platforms[0])
			if err != nil {
				return nil, fmt.Errorf("invalid platform %s: %w", pullCtx.Platforms[0], err)
			}

			pullCtx.PlatformMatcher = platforms.Only(p)
		}
	}

	span.SetAttributes(
		tracing.Attribute("image.ref", ref),
		tracing.Attribute("unpack", pullCtx.Unpack),
		tracing.Attribute("max.concurrent.downloads", pullCtx.MaxConcurrentDownloads),
		tracing.Attribute("platforms.count", len(pullCtx.Platforms)),
	)

	ctx, done, err := c.WithLease(ctx)
	if err != nil {
		return nil, err
	}
	defer done(ctx)

	var unpacker *unpack.Unpacker

	if pullCtx.Unpack {
		snapshotterName, err := c.resolveSnapshotterName(ctx, pullCtx.Snapshotter)
		if err != nil {
			return nil, fmt.Errorf("unable to resolve snapshotter: %w", err)
		}
		span.SetAttributes(tracing.Attribute("snapshotter.name", snapshotterName))
		var uconfig UnpackConfig
		for _, opt := range pullCtx.UnpackOpts {
			if err := opt(ctx, &uconfig); err != nil {
				return nil, err
			}
		}
		var platformMatcher platforms.Matcher
		if !uconfig.CheckPlatformSupported {
			platformMatcher = platforms.All
		}

		// Check client Unpack config
		platform := unpack.Platform{
			Platform:       platformMatcher,
			SnapshotterKey: snapshotterName,
			Snapshotter:    c.SnapshotService(snapshotterName),
			SnapshotOpts:   append(pullCtx.SnapshotterOpts, uconfig.SnapshotOpts...),
			Applier:        c.DiffService(),
			ApplyOpts:      uconfig.ApplyOpts,
		}
		uopts := []unpack.UnpackerOpt{unpack.WithUnpackPlatform(platform)}
		if pullCtx.MaxConcurrentDownloads > 0 {
			uopts = append(uopts, unpack.WithLimiter(semaphore.NewWeighted(int64(pullCtx.MaxConcurrentDownloads))))
		}
		if uconfig.DuplicationSuppressor != nil {
			uopts = append(uopts, unpack.WithDuplicationSuppressor(uconfig.DuplicationSuppressor))
		}
		unpacker, err = unpack.NewUnpacker(ctx, c.ContentStore(), uopts...)
		if err != nil {
			return nil, fmt.Errorf("unable to initialize unpacker: %w", err)
		}
		defer func() {
			if _, err := unpacker.Wait(); err != nil {
				if retErr == nil {
					retErr = fmt.Errorf("unpack: %w", err)
				}
			}
		}()
		wrapper := pullCtx.HandlerWrapper
		pullCtx.HandlerWrapper = func(h images.Handler) images.Handler {
			if wrapper == nil {
				return unpacker.Unpack(h)
			}
			return unpacker.Unpack(wrapper(h))
		}
	}

	img, err := c.fetch(ctx, pullCtx, ref, 1)
	if err != nil {
		return nil, err
	}

	// NOTE(fuweid): unpacker defers blobs download. before create image
	// record in ImageService, should wait for unpacking(including blobs
	// download).
	var ur unpack.Result
	if unpacker != nil {
		_, unpackSpan := tracing.StartSpan(ctx, tracing.Name(pullSpanPrefix, "UnpackWait"))
		if ur, err = unpacker.Wait(); err != nil {
			unpackSpan.SetStatus(err)
			unpackSpan.End()
			return nil, err
		}
		unpackSpan.End()
	}

	img, err = c.createNewImage(ctx, img)
	if err != nil {
		return nil, err
	}

	i := NewImageWithPlatform(c, img, pullCtx.PlatformMatcher)
	span.SetAttributes(tracing.Attribute("image.ref", i.Name()))

	if unpacker != nil && ur.Unpacks == 0 {
		// Unpack was tried previously but nothing was unpacked
		// This is at least required for schema 1 image.
		if err := i.Unpack(ctx, pullCtx.Snapshotter, pullCtx.UnpackOpts...); err != nil {
			return nil, fmt.Errorf("failed to unpack image on snapshotter %s: %w", pullCtx.Snapshotter, err)
		}
	}

	return i, nil
}