package imageasset

Import Path
	github.com/pancsta/d2/lib/imageasset (on go.dev)

Dependency Relation
	imports 33 packages, and imported by 2 packages

Involved Source Files Package imageasset resolves bounded local, HTTP, and data-URI image resources without depending on a renderer or scene representation. Animated GIF, APNG, and WebP resources use their first frame on the logical canvas; later frames are neither decoded nor charged to the decoded-pixel budget. probe.go resolve.go
Package-Level Type Names (total 9)
/* sort by: | */
Cache is optional. Implementations must be safe for concurrent use. Only Resources produced by this package can contain non-empty immutable data. ( Cache) Get(key string) (*Resource, bool) ( Cache) Put(key string, resource *Resource) *MemoryCache
Kind identifies how a resolved resource must be consumed. ( Kind) String() string Kind : expvar.Var Kind : fmt.Stringer func (*Resource).Kind() Kind const KindRaster const KindSVG
LimitError reports the exact inclusive ceiling that was exceeded. Actual int64 Limit int64 Name string (*LimitError) Error() string *LimitError : error
Limits are caller-selected, inclusive ceilings. There are intentionally no package defaults: callers must choose budgets appropriate to their corpus. MaxAssets bounds distinct successfully resolved canonical sources. MaxCumulativeDecodedBytes bounds unique canonical sources successfully returned by one Resolver session. Raster resources, including animated inputs represented by their first frame, charge at least width*height*4, or eight bytes per pixel for 16-bit models; SVG resources charge their strict raw byte length. MaxCumulativeEncodedBytes bounds immutable encoded bytes retained by one Resolver session. MaxDecodedHeight int MaxDecodedPixels int64 MaxDecodedWidth int MaxDecompressedBytes bounds bytes after HTTP content decoding. Identity, local-file, and data-URI sources are checked against it as well. MaxEncodedBytes bounds the final PNG, JPEG, GIF, WebP, or SVG byte stream. MaxFetchedBytes bounds bytes read from a local file or HTTP response and the encoded payload text of a data URI. MaxSVGBytes bounds raw or declared-compressed SVG XML before tokenization. Callers that import resolved SVG must align this with the importer's per-source byte ceiling. ( Limits) Validate() error
MemoryCache is a bounded, concurrency-safe LRU cache. It is never installed globally; callers explicitly own it, and Resolver namespaces every key. (*MemoryCache) Get(key string) (*Resource, bool) (*MemoryCache) Put(key string, resource *Resource) *MemoryCache : Cache func NewMemoryCache(maxEntries int, maxBytes int64) (*MemoryCache, error)
Options configures one independent resolver. BaseDir resolves relative local paths. New makes it absolute. When it is empty, rooted local-file policies use their configured root and other policies freeze the current working directory at construction time. Cache Cache CacheNamespace is required when Cache is set. Reusing a namespace asserts identical tenant, credentials, CookieJar, redirect policy, transport, and fetch semantics for every Resolver sharing that cache. NetworkPolicy is automatically included in the effective namespace. HTTPClient *http.Client Limits Limits LocalFiles controls local-file access. Its zero value denies local files. Use localfile.Rooted for untrusted input. localfile.Unrestricted is an explicit opt-in intended only for trusted local applications. NetworkPolicy defaults to public addresses only. Trusted callers can explicitly allow private-network assets. func New(options Options) (*Resolver, error)
Resolver is one cumulative-budget session (normally one output document). It owns no global state and is safe for concurrent use. CloseIdleConnections releases idle connections held by the transport New created for this resolver session. A trusted caller-injected transport is borrowed and remains the caller's responsibility. Resolve resolves one image source and charges its decoded footprint before returning. Supported inputs are relative/absolute local paths, http(s) URLs, and data URIs. Animated GIF, APNG, and WebP resources retain their original bytes; native raster consumers deterministically paint the first animation frame on the format's logical canvas. func New(options Options) (*Resolver, error)
Resource is immutable after construction. BytesContext returns an owned copy, so a cached Resource can safely be shared between goroutines and converted into a scene asset without exposing the cache's backing storage. BytesContext returns an owned copy while observing cancellation between bounded chunks. A canceled copy never exposes partially initialized bytes. DataURIContext returns a data URI for the immutable resource while observing cancellation between bounded encoding chunks. It encodes the resource's private backing bytes directly, avoiding the full owned copy required by BytesContext for callers that only need a self-contained representation. (*Resource) DecodedBytes() int64 (*Resource) EncodedBytes() int64 (*Resource) Kind() Kind (*Resource) MIMEType() string (*Resource) PixelHeight() int (*Resource) PixelWidth() int func Cache.Get(key string) (*Resource, bool) func (*MemoryCache).Get(key string) (*Resource, bool) func (*Resolver).Resolve(ctx context.Context, source string) (*Resource, error) func Cache.Put(key string, resource *Resource) func (*MemoryCache).Put(key string, resource *Resource)
SourceError associates an error with the external source and resolution stage. Data URI payloads are never copied into Source or error text. Err error Op string Source string (*SourceError) Error() string (*SourceError) Unwrap() error *SourceError : error *SourceError : golang.org/x/xerrors.Wrapper
Package-Level Functions (total 2)
func New(options Options) (*Resolver, error)
NewMemoryCache returns a cache with inclusive entry and encoded-byte limits.
Package-Level Variables (only one)
ErrUnavailable identifies a source whose bytes could not be fetched. It is reserved for absence and transport failures; malformed image data, policy limits, unsupported sources, and caller cancellation do not match it.
Package-Level Constants (total 2)
const KindRaster Kind = 1
const KindSVG Kind = 2