byteexec

package
v0.0.0-...-8b1022e Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 11 Imported by: 0

README

byteexec Travis CI Status Coverage Status GoDoc

byteexec provides a Golang package that allows executing files that are stored as Go byte arrays. This is handy when combined with go-bindata.

To install:

go get github.com/getlantern/byteexec

For docs:

godoc github.com/getlantern/byteexec

Documentation

Overview

Package byteexec provides a very basic facility for running executables supplied as byte arrays, which is handy when used with github.com/jteeuwen/go-bindata.

byteexec works by storing the provided command in a file.

Example Usage:

programBytes := // read bytes from somewhere
be, err := byteexec.New(programBytes)
if err != nil {
  log.Fatalf("Uh oh: %s", err)
}
cmd := be.Command("arg1", "arg2")
// cmd is an os/exec.Cmd
err = cmd.Run()

Note - byteexec.New is somewhat expensive, and Exec is safe for concurrent use, so it's advisable to create only one Exec for each executable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

Types

type Exec

type Exec struct {
	Filename string
}

Exec is a handle to an executable that can be used to create an exec.Cmd using the Command method. Exec is safe for concurrent use.

func New

func New(data []byte, filename string) (*Exec, error)

New creates a new Exec using the program stored in the provided data, at the provided filename (relative or absolute path allowed). If the path given is a relative path, the executable will be placed in one of the following locations:

On Windows - %APPDATA%/byteexec On OSX - ~/Library/Application Support/byteexec All Others - ~/.byteexec

Creating a new Exec can be somewhat expensive, so it's best to create only one Exec per executable and reuse that.

WARNING - if a file already exists at this location and its contents differ from data, Exec will attempt to overwrite it.

func (*Exec) Command

func (be *Exec) Command(args ...string) *exec.Cmd

Command creates an exec.Cmd using the supplied args.

Jump to

Keyboard shortcuts

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