embedbin

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSuchFile is returned when the embedbin does not contain an
	// embedded file with the requested name.
	ErrNoSuchFile = errors.New("embedded file does not exist")
	// ErrCorruptedImage is returned when the embedbin image has been
	// corrupted.
	ErrCorruptedImage = errors.New("corrupted embedbin image")
)

Functions

func Sniff

func Sniff(r io.ReaderAt, size int64) (offset int64, err error)

Sniff sniffs a binary's embedbin offset. Sniff returns errors returned by the provided reader, or ErrCorruptedImage if the binary is identified as an embedbin image with a checksum mismatch.

Types

type Info

type Info struct {
	Name string
	Size int64
}

Info provides information for an embedded file.

func (Info) String

func (info Info) String() string

type Reader

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

Reader reads images from an embedbin.

func NewReader

func NewReader(r io.ReaderAt, embedOffset, totalSize int64) (*Reader, error)

NewReader returns a new embedbin reader from the provided reader.

func OpenFile

func OpenFile(r io.ReaderAt, size int64) (*Reader, error)

OpenFile parses the provided ReaderAt with the provided size. The file's contents are parsed to determine the offset of the embedbin's archive. OpenFile returns an error if the file is not an embedbin.

func Self

func Self() (*Reader, error)

Self reads the currently executing binary image as an embedbin and returns a reader to it.

func (*Reader) List

func (r *Reader) List() []Info

List returns information about embedded files.

func (*Reader) Open

func (r *Reader) Open(name string) (io.ReadCloser, error)

Open returns a ReadCloser for the named embedded file. Open returns ErrNoSuchImage if the embedbin does not contain the file.

func (*Reader) OpenBase

func (r *Reader) OpenBase() (io.ReadCloser, error)

Open returns a ReadCloser for the original executable, without appended embedded files.

func (*Reader) Stat

func (r *Reader) Stat(name string) (info Info, ok bool)

Stat returns the information for the named embedded file. It returns a boolean indicating whether the requested file was found.

func (*Reader) StatBase

func (r *Reader) StatBase() Info

StatBase returns the information for the base image.

type WriteOpt

type WriteOpt func(*Writer)

WriteOpt is an option to NewWriter.

var Deflate WriteOpt = func(w *Writer) {
	w.embedMethod = zip.Deflate
}

Deflate compresses embedded files.

type Writer

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

Writer is used to append embedbin files to an existing binary.

func NewFileWriter

func NewFileWriter(file *os.File) (*Writer, error)

NewFileWriter returns a writer that can be used to append embedbin files to the binary represented by the provided file. NewFileWriter removes any existing embedbin files that may be attached to the binary. It relies on content sniffing (see Sniff) to determine its offset.

func NewWriter

func NewWriter(w io.Writer, embedOffset int64, opts ...WriteOpt) *Writer

NewWriter returns a writer that may be used to append embedbin files to the writer w. The writer should be positioned at the end of the base binary image.

func (*Writer) Close

func (w *Writer) Close() error

Close should be called after all embedded files have been written. No more files can be written after a call to Close.

func (*Writer) Create

func (w *Writer) Create(name string) (io.Writer, error)

Create returns a Writer into which the named file should be written. The image's contents must be written before the next call to Create or Close.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush flushes the unwritten data to the underlying file.

Jump to

Keyboard shortcuts

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