1
0
mirror of https://github.com/regclient/regclient.git synced 2025-04-18 22:44:00 +03:00
regclient/types/blob/blob.go
Brandon Mitchell 1e588c18ef Blob changing from ReadCloser to Reader
Close and Seek methods are used when available.
Forcing a Closer resulted in a NoopCloser that blocked Seek.

Signed-off-by: Brandon Mitchell <git@bmitch.net>
2022-01-16 19:23:59 -05:00

62 lines
1.0 KiB
Go

package blob
import (
"io"
"net/http"
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/regclient/regclient/types/ref"
)
// Blob interface is used for returning blobs
type Blob interface {
Common
RawBody() ([]byte, error)
}
type BlobConfig struct {
desc ociv1.Descriptor
header http.Header
image ociv1.Image
r ref.Ref
rdr io.Reader
resp *http.Response
}
type Opts func(*BlobConfig)
func WithDesc(d ociv1.Descriptor) Opts {
return func(bc *BlobConfig) {
bc.desc = d
}
}
func WithHeader(header http.Header) Opts {
return func(bc *BlobConfig) {
bc.header = header
}
}
func WithImage(image ociv1.Image) Opts {
return func(bc *BlobConfig) {
bc.image = image
}
}
func WithReader(rc io.Reader) Opts {
return func(bc *BlobConfig) {
bc.rdr = rc
}
}
func WithRef(r ref.Ref) Opts {
return func(bc *BlobConfig) {
bc.r = r
}
}
func WithResp(resp *http.Response) Opts {
return func(bc *BlobConfig) {
bc.resp = resp
if bc.header == nil {
bc.header = resp.Header
}
}
}