asset

package
v3.116.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const (
	AssetSig          = sig.AssetSig
	AssetHashProperty = "hash" // the dynamic property for an asset's hash.
	AssetTextProperty = "text" // the dynamic property for an asset's text.
	AssetPathProperty = "path" // the dynamic property for an asset's path.
	AssetURIProperty  = "uri"  // the dynamic property for an asset's URI.
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Asset

type Asset struct {
	// Sig is the unique asset type signature (see properties.go).
	Sig string `json:"4dabf18193072939515e22adb298388d" yaml:"4dabf18193072939515e22adb298388d"`
	// Hash is the SHA256 hash of the asset's contents.
	Hash string `json:"hash,omitempty" yaml:"hash,omitempty"`
	// Text is set to a non-empty value for textual assets.
	Text string `json:"text,omitempty" yaml:"text,omitempty"`
	// Path will contain a non-empty path to the file on the current filesystem for file assets.
	Path string `json:"path,omitempty" yaml:"path,omitempty"`
	// URI will contain a non-empty URI (file://, http://, https://, or custom) for URI-backed assets.
	URI string `json:"uri,omitempty" yaml:"uri,omitempty"`
}

Asset is a serialized asset reference. It is a union: thus, at most one of its fields will be non-nil. Several helper routines exist as members in order to easily interact with the assets referenced by an instance of this type.

func Deserialize

func Deserialize(obj map[string]interface{}) (*Asset, bool, error)

DeserializeAsset checks to see if the map contains an asset, using its signature, and if so deserializes it.

func FromPath

func FromPath(path string) (*Asset, error)

FromPath produces a new asset and its corresponding SHA256 hash from the given filesystem path.

func FromPathWithWD added in v3.115.0

func FromPathWithWD(path string, wd string) (*Asset, error)

FromPathWithWD produces a new asset and its corresponding SHA256 hash from the given filesystem path.

func FromText

func FromText(text string) (*Asset, error)

FromText produces a new asset and its corresponding SHA256 hash from the given text.

func FromURI

func FromURI(uri string) (*Asset, error)

FromURI produces a new asset and its corresponding SHA256 hash from the given network URI.

func (*Asset) Bytes

func (a *Asset) Bytes() ([]byte, error)

Bytes returns the contents of the asset as a byte slice.

func (*Asset) EnsureHash

func (a *Asset) EnsureHash() error

EnsureHash computes the SHA256 hash of the asset's contents and stores it on the object.

func (*Asset) EnsureHashWithWD added in v3.115.0

func (a *Asset) EnsureHashWithWD(wd string) error

EnsureHash computes the SHA256 hash of the asset's contents and stores it on the object.

func (*Asset) Equals

func (a *Asset) Equals(other *Asset) bool

Equals returns true if a is value-equal to other. In this case, value equality is determined only by the hash: even if the contents of two assets come from different sources, they are treated as equal if their hashes match. Similarly, if the contents of two assets come from the same source but the assets have different hashes, the assets are not equal.

func (*Asset) GetPath

func (a *Asset) GetPath() (string, bool)

func (*Asset) GetText

func (a *Asset) GetText() (string, bool)

func (*Asset) GetURI

func (a *Asset) GetURI() (string, bool)

func (*Asset) GetURIURL

func (a *Asset) GetURIURL() (*url.URL, bool, error)

GetURIURL returns the underlying URI as a parsed URL, provided it is one. If there was an error parsing the URI, it will be returned as a non-nil error object.

func (*Asset) HasContents

func (a *Asset) HasContents() bool

HasContents indicates whether or not an asset's contents can be read.

func (*Asset) IsPath

func (a *Asset) IsPath() bool

func (*Asset) IsText

func (a *Asset) IsText() bool

func (*Asset) IsURI

func (a *Asset) IsURI() bool

func (*Asset) Read

func (a *Asset) Read() (*Blob, error)

Read begins reading an asset.

func (*Asset) ReadWithWD added in v3.115.0

func (a *Asset) ReadWithWD(wd string) (*Blob, error)

ReadWithWD begins reading an asset.

func (*Asset) Serialize

func (a *Asset) Serialize() map[string]interface{}

Serialize returns a weakly typed map that contains the right signature for serialization purposes.

type Blob

type Blob struct {
	// contains filtered or unexported fields
}

Blob is a blob that implements ReadCloser and offers Len functionality.

func NewByteBlob

func NewByteBlob(data []byte) *Blob

NewByteBlob creates a new byte blob.

func NewFileBlob

func NewFileBlob(f *os.File) (*Blob, error)

NewFileBlob creates a new asset blob whose size is known thanks to stat.

func NewRawBlob

func NewRawBlob(r io.ReadCloser, size int64) *Blob

func NewReadCloserBlob

func NewReadCloserBlob(r io.ReadCloser) (*Blob, error)

NewReadCloserBlob turn any old ReadCloser into an Blob, usually by making a copy.

func (*Blob) Close

func (blob *Blob) Close() error

func (*Blob) Read

func (blob *Blob) Read(p []byte) (int, error)

func (*Blob) Size

func (blob *Blob) Size() int64

Jump to

Keyboard shortcuts

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