// Fetch downloads an item from the server.
516461
func (i *Client) Fetch(c context.Context, digest isolated.HexDigest, dest io.Writer) error {
	// Perform initial request.
	name := ""
	switch i.h {
	case crypto.SHA1:
		name = "sha-1"
	case crypto.SHA256:
		name = "sha-256"
	case crypto.SHA512:
		name = "sha-512"
	}
	url := i.url + "/_ah/api/isolateservice/v1/retrieve"
	in := &isolateservice.HandlersEndpointsV1RetrieveRequest{
		Digest: string(digest),
		Namespace: &isolateservice.HandlersEndpointsV1Namespace{
			DigestHash: name,
			Namespace:  i.namespace,
		},
		Offset: 0,
	}
	var out isolateservice.HandlersEndpointsV1RetrievedContent
	if _, err := lhttp.PostJSON(c, i.retryFactory, i.authClient, url, nil, in, &out); err != nil {
		return err
	}

	// Handle DB items.
	if out.Content != "" {
		decoded, err := base64.StdEncoding.DecodeString(out.Content)
		if err != nil {
			return err
		}
		decompressor, err := isolated.GetDecompressor(i.namespace, bytes.NewReader(decoded))
		if err != nil {
			return err
		}
		defer decompressor.Close()
		_, err = io.Copy(dest, decompressor)
		return err
	}

	// Handle GCS items.
	return i.gcsHandler.Fetch(c, i, out, dest)
}
1163577
func (ds *DiskSource) Fetch(loc BlockLocation, data []byte) (int, error) {
	addr := ds.BlockAddresses.Get(loc)
	if addr == "" {
		return 0, errors.WithStack(fmt.Errorf("no address for block %+v", loc))
	}
	path := filepath.Join(ds.BasePath, addr)

	fr, err := os.Open(path)
	if err != nil {
		return 0, errors.WithStack(err)
	}

	defer fr.Close()

	if ds.Decompressor == nil {
		bytesRead, err := io.ReadFull(fr, data)
		if err != nil {
			if err == io.ErrUnexpectedEOF {
				// all good
			} else {
				return 0, errors.WithStack(err)
			}
		}

		return bytesRead, nil
	}

	return ds.Decompressor.Decompress(data, fr)
}
1013129
func (c *Client) Get(ctx context.Context, url string) (*http.Response, error) {
	req, err := http.NewRequest("GET", url, nil)
	if err != nil {
		return nil, err
	}

	return c.Do(ctx, req)
}
35443
func (c *Client) Fetch(ctx context.Context, ref string, opts ...RemoteOpt) (images.Image, error) {
	fetchCtx := defaultRemoteContext()
	for _, o := range opts {
		if err := o(c, fetchCtx); err != nil {
			return images.Image{}, err
		}
	}

	if fetchCtx.Unpack {
		return images.Image{}, errors.New("unpack on fetch not supported, try pull")
	}

	if fetchCtx.PlatformMatcher == nil {
		if len(fetchCtx.Platforms) == 0 {
			fetchCtx.PlatformMatcher = platforms.All
		} else {
			var ps []ocispec.Platform
			for _, s := range fetchCtx.Platforms {
				p, err := platforms.Parse(s)
				if err != nil {
					return images.Image{}, errors.Wrapf(err, "invalid platform %s", s)
				}
				ps = append(ps, p)
			}

			fetchCtx.PlatformMatcher = platforms.Any(ps...)
		}
	}

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

	return c.fetch(ctx, fetchCtx, ref, 0)
}
69156
func fetch(source string, duration, timeout time.Duration, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, src string, err error) {
	var f io.ReadCloser

	if sourceURL, timeout := adjustURL(source, duration, timeout); sourceURL != "" {
		ui.Print("Fetching profile over HTTP from " + sourceURL)
		if duration > 0 {
			ui.Print(fmt.Sprintf("Please wait... (%v)", duration))
		}
		f, err = fetchURL(sourceURL, timeout, tr)
		src = sourceURL
	} else if isPerfFile(source) {
		f, err = convertPerfData(source, ui)
	} else {
		f, err = os.Open(source)
	}
	if err == nil {
		defer f.Close()
		p, err = profile.Parse(f)
	}
	return
}
314821
func (s *simpleCache) Fetch(id uint64) (*Row, bool) {
	m, ok := s.cache[id]
	return m, ok
}
173168
func (n *NetStore) FetchFunc(ctx context.Context, ref Address) func(context.Context) error {
	chunk, fetch, _ := n.get(ctx, ref)
	if chunk != nil {
		return nil
	}
	return func(ctx context.Context) error {
		_, err := fetch(ctx)
		return err
	}
}
452814
func (d *downloader) download() (n int64, err error) {
	// If range is specified fall back to single download of that range
	// this enables the functionality of ranged gets with the downloader but
	// at the cost of no multipart downloads.
	if rng := aws.StringValue(d.in.Range); len(rng) > 0 {
		d.downloadRange(rng)
		return d.written, d.err
	}

	// Spin off first worker to check additional header information
	d.getChunk()

	if total := d.getTotalBytes(); total >= 0 {
		// Spin up workers
		ch := make(chan dlchunk, d.cfg.Concurrency)

		for i := 0; i < d.cfg.Concurrency; i++ {
			d.wg.Add(1)
			go d.downloadPart(ch)
		}

		// Assign work
		for d.getErr() == nil {
			if d.pos >= total {
				break // We're finished queuing chunks
			}

			// Queue the next range of bytes to read.
			ch <- dlchunk{w: d.w, start: d.pos, size: d.cfg.PartSize}
			d.pos += d.cfg.PartSize
		}

		// Wait for completion
		close(ch)
		d.wg.Wait()
	} else {
		// Checking if we read anything new
		for d.err == nil {
			d.getChunk()
		}

		// We expect a 416 error letting us know we are done downloading the
		// total bytes. Since we do not know the content's length, this will
		// keep grabbing chunks of data until the range of bytes specified in
		// the request is out of range of the content. Once, this happens, a
		// 416 should occur.
		e, ok := d.err.(awserr.RequestFailure)
		if ok && e.StatusCode() == http.StatusRequestedRangeNotSatisfiable {
			d.err = nil
		}
	}

	// Return error
	return d.written, d.err
}
895874
func (c *Client) Download(name string) (io.ReadCloser, error) {
	out, err := c.Files.Download(&dropbox.DownloadInput{name})
	if err != nil {
		return nil, err
	}

	return out.Body, nil
}
1266435
func (m *MemAccResolver) Fetch(name string) (string, error) {
	if j, ok := m.sm.Load(name); ok {
		return j.(string), nil
	}
	return _EMPTY_, ErrMissingAccount
}
82171
func Download(src string, dest string) error {
	res, err := http.Get(src)
	if err != nil {
		return err
	}
	if res.StatusCode != 200 {
		return errors.New(res.Status)
	}
	defer res.Body.Close()
	data, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return err
	}
	if err = ioutil.WriteFile(dest, data, 0644); err != nil {
		return err
	}
	return nil
}
976176
func (dlr Downloader) Download(req Request) (string, error) {
	if err := os.MkdirAll(req.TargetDir, 0755); err != nil {
		return "", errors.Trace(err)
	}
	dl := dlr.Start(req)
	filename, err := dl.Wait()
	return filename, errors.Trace(err)
}
1258476
func (s *SecondaryCache) Fetch(secondary string, duration time.Duration, fetch func() (interface{}, error)) (*Item, error) {
	item := s.Get(secondary)
	if item != nil {
		return item, nil
	}
	value, err := fetch()
	if err != nil {
		return nil, err
	}
	return s.Set(secondary, value, duration), nil
}
429567
func Fetch(remotes ...string) error {
	if len(remotes) == 0 {
		return nil
	}

	var args []string
	if len(remotes) > 1 {
		args = []string{"--multiple", "--"}
	}
	args = append(args, remotes...)

	_, err := gitNoLFSSimple(append([]string{"fetch"}, args...)...)
	return err
}
1082080
func (c *KafkaClient) Fetch(topic string, partition int32, offset int64) (*FetchResponse, error) {
	response, err := c.tryFetch(topic, partition, offset)
	if err != nil {
		return response, err
	}

	if response.Error(topic, partition) == ErrNotLeaderForPartition {
		log.Infof("Sent a fetch reqest to a non-leader broker. Refreshing metadata for topic %s and retrying the request", topic)
		err = c.metadata.Refresh([]string{topic})
		if err != nil {
			return nil, err
		}
		response, err = c.tryFetch(topic, partition, offset)
	}

	return response, err
}
551079
func Fetch(dir, target string, pool int, dynamic bool) error {
	local, err := GetOrigin(dir)
	if err != nil {
		log.Error("bad local origin:", err)
		return err
	}
	localHashes, localSource, err := local.Scan()
	if target != "" {
		localSource = target
	}
	global, err := GetOrigin(localSource)
	if err != nil {
		log.Error("bad global origin:", err)
		return err
	}
	globalHashes, globalSource, err := global.Scan()
	if globalSource != localSource {
		log.Warning("unverified origin:", globalSource)
	} else {
		log.Notice("verified origin:", globalSource)
	}

	missingHashes := Compare(localHashes, globalHashes)
	if pool < 2 {
		err = FetchSpecific(dir, global, missingHashes)
	} else {
		if dynamic {
			pool *= runtime.NumCPU()
		}
		err = FetchSpecificAsync(dir, global, missingHashes, pool)
	}
	if err != nil {
		log.Error("failed to fetch files:", err)
		return err
	}
	log.Notice("fetched", len(missingHashes), "files from origin")

	return Write(dir, globalSource, globalHashes)
}
739091
func (f *fetcher) Fetch() error {
	resp, err := f.client.Do(f.req)
	if err != nil {
		return errors.Trace(err)
	}

	defer func() {
		err = resp.Body.Close()
		if err != nil {
			logger.Debugf("failed defer %q", errors.Trace(err))
		}
	}()

	if resp.StatusCode != 200 {
		f.image.cleanup()
		return errors.NotFoundf(
			"got %d fetching image %q", resp.StatusCode, path.Base(
				f.req.URL.String()))
	}
	err = f.image.write(resp.Body, f.metadata)
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}