v2 – github.com/gobuffalo/packr/v2 Index | Files | Directories

package packr

import "github.com/gobuffalo/packr/v2"

Index

Constants

const Version = "v2.8.3"

Version of Packr

Variables

var (
	// ErrResOutsideBox gets returned in case of the requested resources being outside the box
	// Deprecated
	ErrResOutsideBox = fmt.Errorf("can't find a resource outside the box")
)

Functions

func PackBytes

func PackBytes(box string, name string, bb []byte)

PackBytes packs bytes for a file into a box. Deprecated

func PackBytesGzip

func PackBytesGzip(box string, name string, bb []byte) error

PackBytesGzip packets the gzipped compressed bytes into a box. Deprecated

func PackJSONBytes

func PackJSONBytes(box string, name string, jbb string) error

PackJSONBytes packs JSON encoded bytes for a file into a box. Deprecated

Types

type Box

type Box struct {
	Path            string            `json:"path"`
	Name            string            `json:"name"`
	ResolutionDir   string            `json:"resolution_dir"`
	DefaultResolver resolver.Resolver `json:"default_resolver"`
	// contains filtered or unexported fields
}

Box represent a folder on a disk you want to have access to in the built Go binary.

func Folder

func Folder(path string) *Box

Folder returns a Box that will NOT be packed. This is useful for writing tests or tools that need to work with a folder at runtime.

func New

func New(name string, path string) *Box

New returns a new Box with the name of the box and the path of the box.

func NewBox

func NewBox(path string) *Box

NewBox returns a Box that can be used to retrieve files from either disk or the embedded binary. Deprecated: Use New instead.

func (*Box) AddBytes

func (b *Box) AddBytes(path string, t []byte) error

AddBytes sets t in b.data by the given path

func (*Box) AddString

func (b *Box) AddString(path string, t string) error

AddString converts t to a byteslice and delegates to AddBytes to add to b.data

func (*Box) Bytes

func (b *Box) Bytes(name string) []byte

Bytes is deprecated. Use Find instead

func (*Box) Find

func (b *Box) Find(name string) ([]byte, error)

Find returns either the byte slice of the requested file or an error if it can not be found.

func (*Box) FindString

func (b *Box) FindString(name string) (string, error)

FindString returns either the string of the requested file or an error if it can not be found.

func (*Box) Has

func (b *Box) Has(name string) bool

Has returns true if the resource exists in the box

func (*Box) HasDir

func (b *Box) HasDir(name string) bool

HasDir returns true if the directory exists in the box

func (*Box) List

func (b *Box) List() []string

List shows "What's in the box?"

func (*Box) MustBytes

func (b *Box) MustBytes(name string) ([]byte, error)

MustBytes is deprecated. Use Find instead.

func (*Box) MustString

func (b *Box) MustString(name string) (string, error)

MustString is deprecated. Use FindString instead

func (*Box) Open

func (b *Box) Open(name string) (http.File, error)

Open returns a File using the http.File interface

func (*Box) Resolve

func (b *Box) Resolve(key string) (file.File, error)

Resolve will attempt to find the file in the box, returning an error if the find can not be found.

func (*Box) SetResolver

func (b *Box) SetResolver(file string, res resolver.Resolver)

SetResolver allows for the use of a custom resolver for the specified file

func (*Box) String

func (b *Box) String(name string) string

String is deprecated. Use FindString instead

func (*Box) Walk

func (b *Box) Walk(wf WalkFunc) error

Walk will traverse the box and call the WalkFunc for each file in the box/folder.

func (*Box) WalkPrefix

func (b *Box) WalkPrefix(prefix string, wf WalkFunc) error

WalkPrefix will call box.Walk and call the WalkFunc when it finds paths that have a matching prefix

type File

type File = file.File

File has been deprecated and file.File should be used instead

type Pointer

type Pointer struct {
	ForwardBox  string
	ForwardPath string
}

Pointer is a resolvr which resolves a file from a different box.

func (Pointer) Resolve

func (p Pointer) Resolve(box string, path string) (file.File, error)

Resolve attempts to find the file in the specific box with the specified key

type WalkFunc

type WalkFunc = packd.WalkFunc

WalkFunc is used to walk a box

Source Files

box.go box_map.go deprecated.go dirs_map.go helpers.go packr.go pointer.go resolvers_map.go version.go walk.go

Directories

PathSynopsis
file
file/resolver
file/resolver/encoding
file/resolver/encoding/hexPackage hex implements hexadecimal encoding and decoding.
_fixtures
_fixtures/import_pkg
jam
jam/parser
jam/parser/_fixtures
jam/parser/_fixtures/new_from_roots
jam/parser/_fixtures/new_from_roots/e
jam/parser/_fixtures/new_from_roots/_r
jam/parser/_fixtures/new_from_roots/w
jam/store
jam/store/_fixtures
jam/store/_fixtures/disk
jam/store/_fixtures/disk/e
jam/store/_fixtures/disk/_r
jam/store/_fixtures/disk/w
packr2
packr2/cmd
packr2/cmd/fix
plog
Version
v2.8.3 (latest)
Published
Nov 23, 2021
Platform
js/wasm
Imports
20 packages
Last checked
now

Tools for package owners.