asset

package
v1.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package asset provides content-addressable storage, URI resolution, and MIME detection for contextual reference assets in Spool repositories.

Index

Constants

View Source
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

View Source
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

func DetectMIMEType(filename string, peek []byte) string

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

func FormatLocator(hash string) string

FormatLocator returns the canonical URI for a given BLAKE3 hash.

func IsValidHash

func IsValidHash(hash string) bool

IsValidHash reports whether hash is a valid 64-character lowercase hexadecimal BLAKE3 hash.

func ParseLocator

func ParseLocator(locator string) (string, error)

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

func NewStore(stateDir string) *Store

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

func (s *Store) BlobPath(hash string) (string, error)

BlobPath returns the sharded on-disk path for a hash: looseDir/hash[:2]/hash[2:].

func (*Store) HasBlob

func (s *Store) HasBlob(hash string) (bool, error)

HasBlob reports whether the blob identified by hash exists in the store.

func (*Store) LooseDir

func (s *Store) LooseDir() string

LooseDir returns the on-disk directory where loose blobs are stored, or "" if in-memory.

func (*Store) ReadBlob

func (s *Store) ReadBlob(hash string) (io.ReadCloser, int64, error)

ReadBlob opens the asset blob identified by hash for streaming. The caller is responsible for closing the returned ReadCloser.

func (*Store) WriteBlob

func (s *Store) WriteBlob(r io.Reader) (hash string, size int64, err error)

WriteBlob streams data from r, computes its BLAKE3-256 hash, and atomically stores the blob into the content-addressable store. If an identical blob already exists, writing is deduplicated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL