Documentation
¶
Overview ¶
Package base provides shared HTTP handler infrastructure for artifact format handlers. Artifact-level format handlers (cargo, helm, nuget, pypi, etc.) embed BaseHandler to eliminate duplicated struct definitions, constructors, and resolveRepoID.
Index ¶
- Constants
- Variables
- func CloseLog(c io.Closer, log *logger.Logger)
- func Compress(next http.HandlerFunc) http.HandlerFunc
- func ContentETag(body []byte) string
- func DescriptorLicenses(filename string, data []byte) []string
- func Guard[R any](h *Handler, classify func(path string) (R, bool), ...) func(http.Handler) http.Handler
- func IsTooLarge(err error) bool
- func OriginTag(origin string) string
- func ReadAllLimited(r io.Reader, maxBytes int64) ([]byte, error)
- func ReaderAtLimited(r io.Reader, limit int64) (io.ReaderAt, int64, error)
- func Revalidate(w http.ResponseWriter, r *http.Request, repoPublic bool, etag string, ...) bool
- func ServeBlob(w http.ResponseWriter, r *http.Request, store storage.BlobStore, id string, ...) error
- func ServeRepoMetadata(w http.ResponseWriter, r *http.Request, log *logger.Logger, ...) bool
- func SetSpoolDir(dir string)
- func SharedCacheable(r *http.Request, repoPublic bool) bool
- func SpoolDescriptorLicenses(filename string, s *Spool) []string
- func WriteJSON(w http.ResponseWriter, status int, data []byte)
- type BlobOptions
- type Form
- type FormSpec
- type Gate
- type Handler
- func (h *Handler) CommitBlobRow(ctx context.Context, spool *Spool, sha256, filename string, blobKey *string, ...) (err error)
- func (h *Handler) DeleteAccounted(ctx context.Context, repoID, sha256 string, size int64, ...) error
- func (h *Handler) DeleteRelease(ctx context.Context, repo *models.Repository, kind models.TrashKind, id string, ...) (bool, error)
- func (h *Handler) DenyIfQuarantined(w http.ResponseWriter, r *http.Request, repoID string, keys ...string) bool
- func (h *Handler) Emit(ctx context.Context, repoID, eventType string, payload map[string]any)
- func (h *Handler) PublicBase(w http.ResponseWriter, r *http.Request) string
- func (h *Handler) ReleaseQuota(ctx context.Context, repoID, repoName string, size int64)
- func (h *Handler) Rendered(ctx context.Context, key string, ...) (*Rendered, error)
- func (h *Handler) ReserveQuotaOrRespond(ctx context.Context, w http.ResponseWriter, repoID, repoName string, ...) bool
- func (h *Handler) ResolveRepo(ctx context.Context, name string) (*models.Repository, error)
- func (h *Handler) ResolveRepoID(ctx context.Context, name string) (string, error)
- func (h *Handler) ResolveRepoIDOrRespond(w http.ResponseWriter, r *http.Request, name string) string
- func (h *Handler) ServeRendered(w http.ResponseWriter, r *http.Request, repoPublic bool, etag, key string, ...)
- func (h *Handler) SetPublisher(p webhook.Publisher)
- func (h *Handler) TryPresign(w http.ResponseWriter, r *http.Request, blob presign.Blob) bool
- type HandlerStore
- type RenderCache
- type Rendered
- type ServeBlobOptions
- type ServeRepoMetadataStore
- type Spool
- type SpoolReader
Constants ¶
const DefaultMaxFormFields = 10 << 20
DefaultMaxFormFields caps the text fields of a form when FormSpec.MaxFields is zero: the limit net/http's own form parser applies to non-file data.
Variables ¶
var ErrContentTooLarge = errors.New("content too large")
ErrContentTooLarge reports that a reader exceeded its content limit.
var ErrFormFieldsTooLarge = errors.New("form fields too large")
ErrFormFieldsTooLarge reports that the text fields of a form together exceed FormSpec.MaxFields.
var ErrInvalidForm = errors.New("invalid multipart form")
ErrInvalidForm reports a multipart/form-data body that cannot be read: not multipart, truncated or malformed. A body over the request's byte cap is not reported with it alone: the error also matches *http.MaxBytesError.
var ErrNegativeContentLimit = errors.New("negative content limit")
ErrNegativeContentLimit reports a negative content limit.
var ErrNoFormFile = errors.New("form has no file part")
ErrNoFormFile reports a form without its file part.
Functions ¶
func CloseLog ¶
CloseLog closes a Closer and logs any error. Use for deferred closes where the error cannot be meaningfully handled but should not be silently discarded.
func Compress ¶ added in v0.6.0
func Compress(next http.HandlerFunc) http.HandlerFunc
Compress wraps a metadata handler so its text response (JSON, YAML, XML, HTML, plain text) is zstd- or gzip-encoded when the client's Accept-Encoding allows it; see httpcompress.Middleware for the exact rules (200 responses of a textual type that are not already encoded, ranged or downloads; bodies below httpcompress.MinSize are left alone). Only GET requests are encoded. Apply it to metadata routes only, never to artifact downloads.
func ContentETag ¶ added in v0.15.0
ContentETag is the quoted strong entity-tag of a document that is its own version: the SHA-256 of its bytes. Proxy and group repositories use it for documents they generate or merge, so an unchanged document revalidates to a 304 whatever produced it.
func DescriptorLicenses ¶ added in v0.4.0
DescriptorLicenses returns the licenses declared by a published Ivy module descriptor (<info><license name="..."/></info>) or Maven POM (<licenses><license><name>). Files that are not a .xml/.pom descriptor, are oversized or cannot be parsed declare no license.
func Guard ¶ added in v0.15.0
func Guard[R any]( h *Handler, classify func(path string) (R, bool), serve func(w http.ResponseWriter, r *http.Request, repoName string, route R), ) func(http.Handler) http.Handler
Guard returns chi middleware for the shared /repos/{name} subrouter, for a format whose paths clash with the wildcard routes the other formats register at the same depth. A request is claimed (answered by serve) when classify recognises the path below the repository and {name} is a repository of the handler's format (h.Format), and passed on untouched otherwise. Mount it before the per-format routes.
func IsTooLarge ¶ added in v0.19.0
IsTooLarge reports whether err means the body, the file part or the fields of a form exceeded a limit (the 413 cases of ReadForm).
func OriginTag ¶ added in v0.15.0
OriginTag is a short, entity-tag-safe digest of the origin a document's absolute URLs were built from. Fold it into the validator and any in-process cache key of such a document, so a client holding an ETag for one origin never gets a 304 (and no cache serves a rendering) for another.
func ReadAllLimited ¶
ReadAllLimited reads r up to maxBytes and reports when the limit is exceeded.
func ReaderAtLimited ¶ added in v0.9.0
ReaderAtLimited returns r as an io.ReaderAt and its size without copying when r already is one (*io.SectionReader, *bytes.Reader: it must be unread, as their size ignores the read position); any other reader is read to its end into memory, failing with ErrContentTooLarge past limit bytes. Zip parsers need random access, so they use this instead of always buffering.
func Revalidate ¶ added in v0.4.0
func Revalidate(w http.ResponseWriter, r *http.Request, repoPublic bool, etag string, maxAgeSeconds int) bool
Revalidate sets the validator and cache headers of a metadata response (ETag, Cache-Control, Vary: Authorization) and answers 304 Not Modified when the request's If-None-Match matches etag. It returns true when the 304 was written and the caller must return. Call it only after authorisation has passed (the RBAC middleware runs before every format handler) and as soon as the ETag is known, before any expensive rendering.
etag must be a quoted entity-tag. maxAgeSeconds applies to shared-cacheable responses only; every other response is private and must be revalidated.
func ServeBlob ¶ added in v0.19.0
func ServeBlob(w http.ResponseWriter, r *http.Request, store storage.BlobStore, id string, o ServeBlobOptions) error
ServeBlob serves a stored blob the way http.ServeContent serves a file: single and multiple byte Range requests (206 with Content-Range, 416 when unsatisfiable), If-Range, If-None-Match and If-Modified-Since, Accept-Ranges, Content-Length, and no body for HEAD. Headers the caller set on w beforehand (Docker-Content-Digest, X-Checksum-Sha256...) are kept.
The blob is opened up front when the request cannot be answered without its bytes from the start, so an unreadable blob is returned as an error before anything is written and the caller answers it in its own error format; with a Range or a validator the open is deferred to the first read, and a blob that disappears in between aborts the response.
func ServeRepoMetadata ¶ added in v0.13.0
func ServeRepoMetadata( w http.ResponseWriter, r *http.Request, log *logger.Logger, db ServeRepoMetadataStore, store storage.BlobStore, repo *models.Repository, path string, opts BlobOptions, ) bool
ServeRepoMetadata serves the pre-generated metadata blob stored under path. The blob digest is the ETag, so a matching If-None-Match is answered without reading the blob. It returns true when a response was written (the blob, a 304 or a 500) and false, with nothing written, when no blob exists at path.
func SetSpoolDir ¶ added in v0.19.0
func SetSpoolDir(dir string)
SetSpoolDir sets the directory body spools are created in; empty (the default) is the OS temp dir. Point it at the blob filesystem so a spooled upload becomes the blob by a hard link instead of a second copy.
func SharedCacheable ¶ added in v0.4.0
SharedCacheable reports whether the response to r may be stored by shared caches: only an anonymous caller reading a public repository qualifies. The decision uses the principal the RBAC middleware resolved, never the mere presence of an Authorization header; a request without a resolved principal fails closed.
func SpoolDescriptorLicenses ¶ added in v0.9.0
SpoolDescriptorLicenses is DescriptorLicenses for an uploaded body: only a descriptor small enough to be parsed is read back from the spool.
Types ¶
type BlobOptions ¶ added in v0.13.0
type BlobOptions struct {
ContentType string
// MaxAge is the shared-cache lifetime of a public repository's response.
MaxAge int
// ContentLength sends the blob size as Content-Length.
ContentLength bool
// LastModified sends the generation time as Last-Modified and answers an
// If-Modified-Since that is not older with 304 when the request carries no
// If-None-Match (what pacman asks).
LastModified bool
}
BlobOptions shapes the response of ServeRepoMetadata.
type Form ¶ added in v0.19.0
type Form struct {
// File is the file part; nil when the form has none and ReadForm returned
// ErrNoFormFile.
File *Spool
// Filename is the file part's client-supplied name.
Filename string
// Header is the file part's MIME header (Content-Type, Content-Transfer-Encoding).
Header textproto.MIMEHeader
// contains filtered or unexported fields
}
Form is a multipart upload read in one streaming pass: the text fields are held in memory and the file part is a Spool, written once to its temp file (or kept in memory when small) while it is hashed. net/http's ParseMultipartForm would first buffer the part in memory up to its limit and then in its own temp file, and removes that file only for the original *http.Request: a request copied by r.WithContext (every routed request is) leaked a full-size file per upload. A Form owns no file but the spool, which Close removes.
func ReadForm ¶ added in v0.19.0
ReadForm reads the multipart/form-data body of r, wrapped by the caller in http.MaxBytesReader to cap the whole body. A body longer than the cap fails with an error matching *http.MaxBytesError, a file part longer than spec.MaxFile with ErrContentTooLarge, too many field bytes with ErrFormFieldsTooLarge, a form without the file part with ErrNoFormFile and anything unreadable with ErrInvalidForm. The caller closes the Form it gets on success; on ErrNoFormFile it is returned too, so the fields can be read.
func (*Form) Close ¶ added in v0.19.0
func (f *Form) Close()
Close releases the file part. Safe on nil.
type FormSpec ¶ added in v0.19.0
type FormSpec struct {
// FileField is the name of the file part.
FileField string
// MaxFile is the most bytes the file part may hold; more fails with
// ErrContentTooLarge.
MaxFile int64
// MaxFields is the most bytes all text fields may hold together, 0 for
// DefaultMaxFormFields.
MaxFields int64
// Hashes also receive every byte of the file part (SHA-256 is always
// computed).
Hashes []hash.Hash
}
FormSpec describes the multipart upload ReadForm reads.
type Gate ¶ added in v0.6.0
type Gate chan struct{}
Gate bounds how many callers run a memory-heavy section at once (whole documents read and re-encoded in memory). A nil Gate is unbounded.
func NewGate ¶ added in v0.6.0
NewGate returns a Gate admitting n concurrent holders (n < 1 means 1).
type Handler ¶
type Handler struct {
// Format is the repository format this handler serves. ResolveRepo,
// ResolveRepoID and ResolveRepoIDOrRespond treat a repository of any other
// format as unknown, so a route mounted on the shared /repos/{name}
// sub-router never acts on another format's rows.
Format string
Log *logger.Logger
DB HandlerStore
BlobStore storage.BlobStore
// BaseURL is the configured BASE_URL when the operator set one, "" otherwise.
// Read it only through PublicBase.
BaseURL string
// Publisher receives artifact.* events; nil disables event publishing.
Publisher webhook.Publisher
// contains filtered or unexported fields
}
Handler provides shared fields and methods for artifact-level format HTTP handlers. Embed this in format-specific HTTPHandler structs to eliminate duplicated boilerplate.
func New ¶
func New(format string, log *logger.Logger, db HandlerStore, blobStore storage.BlobStore, baseURL string) *Handler
New creates a new base handler for the given repository format with the common dependencies.
func (*Handler) CommitBlobRow ¶ added in v0.26.0
func (h *Handler) CommitBlobRow( ctx context.Context, spool *Spool, sha256, filename string, blobKey *string, createdAt *time.Time, create func(ctx context.Context) error, ) (err error)
CommitBlobRow stores the spool as the content-addressed blob sha256 (with its filename in the object metadata), then runs create, which inserts the row that references the blob, under the per-blob lock so a concurrent delete cannot remove the blob in between. Before create runs, *blobKey is set to the blob's storage key and *createdAt to the import-aware creation time: they are the row's BlobKey and CreatedAt fields. When create fails the blob is dropped again unless something else references it (a failed cleanup is logged under the handler's format). The error of create is returned as is.
func (*Handler) DeleteAccounted ¶ added in v0.15.0
func (h *Handler) DeleteAccounted( ctx context.Context, repoID, sha256 string, size int64, deleteRow func(context.Context) error, ) error
DeleteAccounted is the permanent delete of a row that owns a content-addressed blob: deleteRow removes the row, then the quota the row held is given back and the blob is dropped once no row references it any more. Failing to give the quota back or to drop the blob is logged, not returned: the row is gone either way.
func (*Handler) DeleteRelease ¶ added in v0.26.0
func (h *Handler) DeleteRelease( ctx context.Context, repo *models.Repository, kind models.TrashKind, id string, art webhook.Artifact, hard func() error, ) (bool, error)
DeleteRelease deletes the row id of kind in repo, the release art describes (its Name, Version, Path, SHA256 and Size; Repository and Format are filled in here): into the trash when the repository's retention allows, through hard otherwise (see trash.Delete). On success it emits artifact.deleted. found is false when the row is no longer live in the repository (answer 404); err is the failure of the delete otherwise.
func (*Handler) DenyIfQuarantined ¶ added in v0.2.0
func (h *Handler) DenyIfQuarantined(w http.ResponseWriter, r *http.Request, repoID string, keys ...string) bool
DenyIfQuarantined refuses the download with 403 when the artifact is quarantined and returns true; the caller MUST then return immediately. keys are every identifier the artifact is known by (see quarantine.PathKeys).
func (*Handler) Emit ¶ added in v0.2.0
Emit publishes a webhook event (a no-op without a Publisher). It never fails the caller.
func (*Handler) PublicBase ¶ added in v0.15.0
PublicBase returns the origin (scheme://host, plus BASE_URL's path prefix, no trailing slash) this handler hands to clients in absolute URLs for the request r: BASE_URL when it is set, else the request's own origin, with X-Forwarded-* honored only from a trusted proxy (internal/publicurl). A document built from it MUST carry the result in its validator or cache key, and PublicBase MUST run before the response headers are written (it adds Vary). Formats whose clients resolve relative URLs should emit those instead.
func (*Handler) ReleaseQuota ¶ added in v0.15.0
ReleaseQuota returns size bytes (one artifact) to the repository's storage quota; a failure is only logged, repoName names the repository in the log.
func (*Handler) Rendered ¶ added in v0.6.0
func (h *Handler) Rendered(ctx context.Context, key string, render func(ctx context.Context) (*Rendered, error)) (*Rendered, error)
Rendered returns the metadata document cached under key, rendering it with render on a miss (concurrent misses share one render). key must embed the validator of the data the document is derived from; see RenderCache.
func (*Handler) ReserveQuotaOrRespond ¶ added in v0.15.0
func (h *Handler) ReserveQuotaOrRespond(ctx context.Context, w http.ResponseWriter, repoID, repoName string, size int64) bool
ReserveQuotaOrRespond reserves size bytes (one artifact) of the repository's storage quota before an upload is persisted. When it cannot it writes the response (the quota-exceeded one, or a 500 for a lookup failure) and returns false; the caller MUST then return immediately. After a successful reservation every failure path must return it with quota.Release.
func (*Handler) ResolveRepo ¶ added in v0.4.0
ResolveRepo loads a repository by name. It returns nil without an error when the repository does not exist or its format is not the handler's: callers answer 404 for both, so a handler never acts on another format's data.
func (*Handler) ResolveRepoID ¶
ResolveRepoID resolves a repository name to its ID. Returns empty string if the repository does not exist or is not of the handler's format.
func (*Handler) ResolveRepoIDOrRespond ¶ added in v0.15.0
func (h *Handler) ResolveRepoIDOrRespond(w http.ResponseWriter, r *http.Request, name string) string
ResolveRepoIDOrRespond is ResolveRepoID for handlers that answer the request themselves: on a lookup failure it writes a 500, for an unknown repository a 404, and returns "" in both cases; the caller MUST then return immediately.
func (*Handler) ServeRendered ¶ added in v0.13.0
func (h *Handler) ServeRendered( w http.ResponseWriter, r *http.Request, repoPublic bool, etag, key string, maxAge int, render func(ctx context.Context) (*Rendered, error), failMsg string, fields ...any, )
ServeRendered revalidates a stamp-validated metadata document and serves it: a matching If-None-Match is answered 304 from etag alone, otherwise the document is rendered once per etag-derived key (see Handler.Rendered) and written. failMsg and fields describe the document in the error log written when rendering fails (the error itself is appended), and the client gets 500.
func (*Handler) SetPublisher ¶ added in v0.2.0
SetPublisher sets the webhook publisher used by Emit. It must be called before the handler serves requests.
func (*Handler) TryPresign ¶ added in v0.5.0
TryPresign answers a blob download with a 307 to a presigned object-store URL when presigned downloads are enabled for the repository and the blob qualifies (see package presign), and returns true; the caller MUST then return immediately. It returns false, having written nothing, when the caller should stream the blob itself.
This is the single hook of the download path: call it from the binary download branch of a handler only after authorisation (the RBAC middleware runs before every format handler), quarantine checks and download counters, and right before opening the blob. Never call it for metadata. blob.Repo defaults to the {name} URL parameter.
type HandlerStore ¶ added in v0.15.0
type HandlerStore interface {
quarantine.Checker
BlobReferenceCount(ctx context.Context, sha256 string) (int, error)
DecrementStorageUsage(ctx context.Context, repoID string, sizeBytes int64, artifactCount int) error
GetRawArtifact(ctx context.Context, repoID string, path string) (*models.RawArtifact, error)
GetRepositoryByName(ctx context.Context, name string) (*models.Repository, error)
ReserveStorageUsage(ctx context.Context, repoID string, sizeBytes int64, artifactCount int) (bool, error)
UpsertRawArtifact(ctx context.Context, artifact *models.RawArtifact) error
}
HandlerStore is the part of the database Handler needs.
type RenderCache ¶ added in v0.6.0
type RenderCache struct {
// contains filtered or unexported fields
}
RenderCache is a byte-bounded LRU of rendered metadata documents with per-key single-flight rendering. Keys must embed the validator (ETag) of the data the document was rendered from, so a changed source can never be served from an old entry: an outdated key simply ages out.
func NewRenderCache ¶ added in v0.6.0
func NewRenderCache(maxBytes int64) *RenderCache
NewRenderCache returns a cache holding at most maxBytes of documents.
func (*RenderCache) Do ¶ added in v0.6.0
func (c *RenderCache) Do(ctx context.Context, key string, render func(ctx context.Context) (*Rendered, error)) (*Rendered, error)
Do returns the document for key, rendering it with render on a miss. Callers racing on the same missing key share a single render. render runs detached from the first caller's cancellation so one aborted request cannot fail the others.
func (*RenderCache) Get ¶ added in v0.6.0
func (c *RenderCache) Get(key string) (*Rendered, bool)
Get returns the cached document for key.
func (*RenderCache) Len ¶ added in v0.6.0
func (c *RenderCache) Len() int
Len reports the number of cached documents (tests).
type Rendered ¶ added in v0.6.0
type Rendered struct {
Body []byte
ContentType string
// Opaque marks a body that is already a compressed file format (such as
// RubyGems' specs.4.8.gz): it is served byte for byte, never re-encoded
// and without Content-Encoding.
Opaque bool
// Transient marks a degraded rendering (a part of the source could not be
// read): it answers the requests sharing this render only. It is never
// cached and goes out as no-store without a validator, so neither this
// cache nor a client can keep serving it once the source recovers.
Transient bool
// Compact lets the cache keep a large (from compactBytes) document only
// in its gzip form, 5-10x smaller for JSON metadata, so a multi-megabyte
// document costs a fraction of its size in the byte budget and fits at all.
// A client that does not accept gzip is served by decompressing it on the
// fly, which is far cheaper than rendering again. Set it only when the
// producer never reads Body from the document Do returns: Body is nil there.
Compact bool
// contains filtered or unexported fields
}
Rendered is one immutable rendered metadata document. It is shared between requests and must not be modified after it is handed to the cache.
func CachedMerged ¶ added in v0.19.0
CachedMerged returns the document MergedRendered holds under key, if any, without rendering it: a caller that can name a document by a cheap validator answers from the cache before collecting what the document is built from.
func MergedRendered ¶ added in v0.6.0
func MergedRendered(ctx context.Context, key string, render func(ctx context.Context) (*Rendered, error)) (*Rendered, error)
MergedRendered is Handler.Rendered for documents that are not rendered by a format handler, such as a group's merge of its members' documents. key must identify every input of the rendering (hash the inputs, not their ages).
func (*Rendered) Serve ¶ added in v0.6.0
func (r *Rendered) Serve(w http.ResponseWriter, req *http.Request)
Serve writes the document: gzip-encoded when the client accepts it, plain otherwise. Any ETag already set on w (see Revalidate) is kept, downgraded to a weak validator on the compressed representation, because the two representations are not byte-identical.
type ServeBlobOptions ¶ added in v0.19.0
type ServeBlobOptions struct {
// ContentType is the Content-Type of the response.
ContentType string
// Size is the blob size in bytes.
Size int64
// ETag is the quoted strong entity-tag, empty for none. A matching
// If-None-Match is answered 304 and If-Range is evaluated against it.
ETag string
// ModTime is the Last-Modified time, zero for none.
ModTime time.Time
}
ServeBlobOptions shapes the response of ServeBlob.
type ServeRepoMetadataStore ¶ added in v0.15.0
type ServeRepoMetadataStore interface {
GetRepoMetadataByPath(ctx context.Context, repositoryID string, path string) (*models.RepoMetadata, error)
}
ServeRepoMetadataStore is the part of the database ServeRepoMetadata needs.
type Spool ¶ added in v0.9.0
type Spool struct {
// contains filtered or unexported fields
}
Spool is a request body read once, with its SHA-256 and size known, held in memory when small and in an unlinked-on-Close temp file otherwise. Parsers and the blob store read it back through Reader/ReaderAt, so handlers that need random access (zip, tar) or several passes never hold the whole body in memory. Close is mandatory.
func SpoolLimited ¶ added in v0.9.0
SpoolLimited reads r to its end, keeping at most maxBytes: a longer body fails with ErrContentTooLarge (reading no further than maxBytes+1 bytes), a read error is returned as is. Each extra hash receives every byte, so callers can get MD5/SHA-1 in the same pass. The SHA-256 is available from SHA256Hex.
func SpoolWrite ¶ added in v0.19.0
SpoolWrite keeps what produce writes, like SpoolLimited keeps a body: for the output of a library that writes to an io.Writer (a re-signed package). It runs produce on its own goroutine and returns only once produce has returned, so produce may read its own inputs without the caller racing it. A produce error is returned as is.
func (*Spool) Bytes ¶ added in v0.9.0
Bytes returns the body as one slice: the memory copy itself (do not modify) when the body is small, otherwise it reads the file back. Only call it for bodies a handler already knows are small (descriptors, manifests).
func (*Spool) Close ¶ added in v0.9.0
func (s *Spool) Close()
Close releases the spool and removes its temp file. Safe on nil and twice.
func (*Spool) Reader ¶ added in v0.9.0
func (s *Spool) Reader() *SpoolReader
Reader returns an independent reader over the whole body, positioned at its start; it also implements io.Seeker and io.ReaderAt.
type SpoolReader ¶ added in v0.19.0
type SpoolReader struct {
*io.SectionReader
// contains filtered or unexported fields
}
SpoolReader is the reader Spool.Reader returns. When the body is in a temp file and nothing has been read yet it also tells a blob store where that file is and what it hashes to (storage.VerifiedFile), so the store takes the file over instead of reading, hashing and writing it again.
func (*SpoolReader) Close ¶ added in v0.19.0
func (r *SpoolReader) Close() error
Close does nothing: the reader owns no resource, the Spool does. It lets the reader stand in for an opened blob (io.ReadCloser with ReadAt and Seek), so code that wants random access uses the spool file itself, not a copy.
func (*SpoolReader) VerifiedFile ¶ added in v0.19.0
func (r *SpoolReader) VerifiedFile() (string, string, int64, bool)
VerifiedFile implements storage.VerifiedFile.