MCPcopy Create free account
hub / github.com/containers/image / splitHTTP200ResponseToPartial

Function splitHTTP200ResponseToPartial

docker/docker_image_src.go:275–312  ·  view source on GitHub ↗

splitHTTP200ResponseToPartial splits a 200 response in multiple streams as specified by the chunks

(streams chan io.ReadCloser, errs chan error, body io.ReadCloser, chunks []private.ImageSourceChunk)

Source from the content-addressed store, hash-verified

273
274// splitHTTP200ResponseToPartial splits a 200 response in multiple streams as specified by the chunks
275func splitHTTP200ResponseToPartial(streams chan io.ReadCloser, errs chan error, body io.ReadCloser, chunks []private.ImageSourceChunk) {
276 defer close(streams)
277 defer close(errs)
278 currentOffset := uint64(0)
279
280 body = makeBufferedNetworkReader(body, 64, 16384)
281 defer body.Close()
282 for _, c := range chunks {
283 if c.Offset != currentOffset {
284 if c.Offset < currentOffset {
285 errs <- fmt.Errorf("invalid chunk offset specified %v (expected >= %v)", c.Offset, currentOffset)
286 break
287 }
288 toSkip := c.Offset - currentOffset
289 if _, err := io.Copy(io.Discard, io.LimitReader(body, int64(toSkip))); err != nil {
290 errs <- err
291 break
292 }
293 currentOffset += toSkip
294 }
295 var reader io.Reader
296 if c.Length == math.MaxUint64 {
297 reader = body
298 } else {
299 reader = io.LimitReader(body, int64(c.Length))
300 }
301 s := signalCloseReader{
302 closed: make(chan struct{}),
303 stream: io.NopCloser(reader),
304 consumeStream: true,
305 }
306 streams <- s
307
308 // Wait until the stream is closed before going to the next chunk
309 <-s.closed
310 currentOffset += c.Length
311 }
312}
313
314// handle206Response reads a 206 response and send each part as a separate ReadCloser to the streams chan.
315func handle206Response(streams chan io.ReadCloser, errs chan error, body io.ReadCloser, chunks []private.ImageSourceChunk, mediaType string, params map[string]string) {

Callers 2

GetBlobAtMethod · 0.85

Calls 2

CloseMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…