Documentation
¶
Overview ¶
Package asset provides content-addressable storage, URI resolution, and MIME detection for contextual reference assets in Spool repositories.
Index ¶
- Constants
- Variables
- func DetectMIMEType(filename string, peek []byte) string
- func ExtractAssetHash(node graphcontract.Node) (string, bool)
- func ExtractAssetHashes(nodes map[string]graphcontract.Node) []string
- func FormatLocator(hash string) string
- func IsValidHash(hash string) bool
- func ParseLocator(locator string) (string, error)
- type AddRequest
- type AddResult
- type Metadata
- type Store
Constants ¶
const ( // URIPrefix is the canonical URI scheme prefix for stored repository assets. URIPrefix = "spool://assets/" // HashHexLength is the required hexadecimal character length of a 256-bit BLAKE3 hash. HashHexLength = 64 // DefaultBufferPoolSize is the chunk size used for streaming asset reads/writes. DefaultBufferPoolSize = 32 * 1024 // LooseSubdir is the repository state subdirectory for loose asset blobs. LooseSubdir = "assets/loose" )
Variables ¶
var ( // ErrAssetNotFound reports that a requested asset blob is absent from storage. ErrAssetNotFound = errors.New("asset not found") // ErrInvalidAssetURI reports an asset URI that does not conform to the canonical scheme. ErrInvalidAssetURI = errors.New("invalid asset URI") // ErrInvalidAssetHash reports an invalid or non-hexadecimal BLAKE3 asset hash. ErrInvalidAssetHash = errors.New("invalid asset hash") // ErrCorruptAsset reports an asset blob whose stored contents do not match its content hash. ErrCorruptAsset = errors.New("corrupt asset blob") )
Functions ¶
func DetectMIMEType ¶
DetectMIMEType determines the MIME type of content based on filename extension and leading peek bytes. If the extension is known, it takes precedence. If indeterminate, it sniffs leading content bytes, defaulting to application/octet-stream.
func ExtractAssetHash ¶
func ExtractAssetHash(node graphcontract.Node) (string, bool)
ExtractAssetHash checks whether node has an assetUri property and extracts its canonical BLAKE3 hash.
func ExtractAssetHashes ¶
func ExtractAssetHashes(nodes map[string]graphcontract.Node) []string
ExtractAssetHashes inspects a map of nodes and returns a sorted, unique list of referenced asset hashes.
func FormatLocator ¶
FormatLocator returns the canonical URI for a given BLAKE3 hash.
func IsValidHash ¶
IsValidHash reports whether hash is a valid 64-character lowercase hexadecimal BLAKE3 hash.
func ParseLocator ¶
ParseLocator parses a locator string, which may be a canonical URI (spool://assets/{hash}) or a bare 64-character hex hash, and returns the normalized lowercase BLAKE3 hash.
Types ¶
type AddRequest ¶
type AddRequest struct {
Branch string
FilePath string
Reader io.Reader
Filename string
Title string
ID string
}
AddRequest specifies parameters for ingesting an asset into repository storage.
type AddResult ¶
type AddResult struct {
Node string `json:"node"`
AssetURI string `json:"assetUri"`
Hash string `json:"hash"`
Size int64 `json:"size"`
MIMEType string `json:"mimeType"`
Branch string `json:"branch"`
Staged bool `json:"staged"`
Status string `json:"status"`
}
AddResult defines the structured outcome of ingesting an asset into Spool, complying with contract-asset-add-cli-payload.
type Metadata ¶
type Metadata struct {
AssetURI string `json:"assetUri"`
Hash string `json:"hash"`
ByteSize int64 `json:"byteSize"`
MIMEType string `json:"mimeType"`
OriginalFilename string `json:"originalFilename,omitempty"`
}
Metadata captures the descriptive properties of an asset stored in Spool.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages content-addressable storage for loose asset blobs.
func NewStore ¶
NewStore initializes an asset Store. If stateDir is non-empty, blobs are durably persisted beneath filepath.Join(stateDir, "assets", "loose"). If stateDir is empty, blobs are retained in memory.
func (*Store) BlobPath ¶
BlobPath returns the sharded on-disk path for a hash: looseDir/hash[:2]/hash[2:].
func (*Store) LooseDir ¶
LooseDir returns the on-disk directory where loose blobs are stored, or "" if in-memory.