MCPcopy Create free account
hub / github.com/cph6/zsync / fetchRange

Method fetchRange

target_fetch.go:130–145  ·  view source on GitHub ↗
(ctx context.Context, client HTTPRequester, url *url.URL, r ByteRange)

Source from the content-addressed store, hash-verified

128}
129
130func (zs *Syncer) fetchRange(ctx context.Context, client HTTPRequester, url *url.URL, r ByteRange) (int64, error) {
131 req, err := http.NewRequestWithContext(ctx, "GET", url.String(), nil)
132 if err != nil {
133 return 0, err
134 }
135 req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", r.Start, r.End))
136 resp, err := client.Do(req)
137 if err != nil {
138 return 0, err
139 }
140 defer resp.Body.Close()
141 if resp.StatusCode != http.StatusPartialContent {
142 return 0, fmt.Errorf("expected partial content from %s, got %s", url.String(), resp.Status)
143 }
144 return zs.SubmitTargetData(r.Start, resp.Body)
145}

Callers 1

Calls 5

SubmitTargetDataMethod · 0.95
CloseMethod · 0.80
DoMethod · 0.65
StringMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected