Documentation
¶
Overview ¶
Package storagekit holds the few helpers every storage.Store implementation shares, so the adapters (storage/local, storage/s3 and storagetest's memory store) cannot drift apart on them. It is internal: an adapter written elsewhere writes its own, and the conformance suite holds it to the same contract.
Index ¶
Constants ¶
const KeyAttempts = 3
KeyAttempts is how many generated keys a write tries before it reports a collision as storage.ErrExists.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check is the preamble every call that names a key shares: the context, then the key's form.
func NormalizePrefix ¶ added in v0.7.0
NormalizePrefix returns prefix as "" or "a/b/" after checking that it cannot name anything outside itself. The error names the offending prefix but not the adapter, which wraps it.
func Range ¶
Range resolves an Open request against an object of size bytes: it returns the end of the range starting at offset. A negative length, or one that reaches or exceeds the remaining bytes (math.MaxInt64 included), reads to the end. An offset that is negative or beyond the end is storage.ErrInvalidRange. It never overflows, whatever length is.
func ValidSHA256 ¶ added in v0.7.0
ValidSHA256 reports whether s is a lowercase hex SHA-256 digest, the form the adapters store as object metadata.
Types ¶
type ContextReader ¶
ContextReader stops a copy as soon as Ctx is done.
type FileOps ¶ added in v0.7.0
type FileOps struct {
Sync func(*os.File) error
Close func(*os.File) error
Remove func(string) error
}
FileOps are the file operations a SpoolFile performs. The zero value uses the operating system; a test substitutes failing operations.
type SpoolFile ¶ added in v0.7.0
type SpoolFile struct {
// contains filtered or unexported fields
}
SpoolFile is a temporary file holding one upload body. Its life has three steps. Fill writes the body, syncs it and closes it: every failure of those is returned before any upload begins, so an upload never starts on bytes that did not reach the file. Open reopens the completed file read-only for the upload. Release closes what is still open and removes the file.
Release is best effort: it always tries to close and remove, but a failure it reports cannot undo an upload that has already committed, so a caller that has committed must not treat a Release error as a failed write.
func NewSpoolFile ¶ added in v0.7.0
NewSpoolFile creates the file in dir. prefix names the adapter in errors.
func (*SpoolFile) Fill ¶ added in v0.7.0
Fill copies r into the file, then syncs and closes it. It reports the first failure of the copy, the sync or the close.