MCPcopy
hub / github.com/containerd/containerd / reader

Method reader

core/remotes/docker/httpreadseeker.go:145–179  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

143}
144
145func (hrs *httpReadSeeker) reader() (io.Reader, error) {
146 if hrs.rc != nil {
147 return hrs.rc, nil
148 }
149
150 if hrs.size == -1 || hrs.offset < hrs.size {
151 // only try to reopen the body request if we are seeking to a value
152 // less than the actual size.
153 if hrs.open == nil {
154 return nil, fmt.Errorf("cannot open: %w", errdefs.ErrNotImplemented)
155 }
156
157 rc, err := hrs.open(hrs.offset)
158 if err != nil {
159 return nil, fmt.Errorf("httpReadSeeker: failed open: %w", err)
160 }
161
162 if hrs.rc != nil {
163 if err := hrs.rc.Close(); err != nil {
164 log.L.WithError(err).Error("httpReadSeeker: failed to close ReadCloser")
165 }
166 }
167 hrs.rc = rc
168 } else {
169 // There is an edge case here where offset == size of the content. If
170 // we seek, we will probably get an error for content that cannot be
171 // sought (?). In that case, we should err on committing the content,
172 // as the length is already satisfied but we just return the empty
173 // reader instead.
174
175 hrs.rc = io.NopCloser(bytes.NewReader([]byte{}))
176 }
177
178 return hrs.rc, nil
179}

Callers 1

ReadMethod · 0.95

Calls 3

openMethod · 0.80
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected