Help us shape the future of Go! Take the 2026 Go Developer Survey

bindatafs

package module
v0.0.0-...-8635f75 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2017 License: BSD-3-Clause Imports: 6 Imported by: 0

README

afero-bindatafs

An afero filesystem for go-bindata.

usage

var fs afero.Fs = bindatafs.Fs{
    AssetFunc: Asset,
    AssetDirFunc: AssetDir,
    AssetDirInfo: AssetInfo,
}
f, err := fs.Open("data/a.txt")
if err != nil {
    log.Fatal(err)
}
b, err := ioutil.ReadAll(f)
if err != nil {
    log.Fatal(err)
}
fmt.Println("contents:", string(b))
  • afero - A filesystem abstraction system for Go
  • go-bindata - A small utility which generates Go code from any file. Useful for embedding binary data in a Go program.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

type Api interface {
	Asset(string) ([]byte, error)
	AssetDir(string) ([]string, error)
	AssetInfo(string) (os.FileInfo, error)
}

type AssetDirFunc

type AssetDirFunc func(path string) ([]string, error)

type AssetFunc

type AssetFunc func(path string) ([]byte, error)

type AssetInfoFunc

type AssetInfoFunc func(path string) (os.FileInfo, error)

type Dir

type Dir struct {
	Api
	// contains filtered or unexported fields
}

func (*Dir) Close

func (d *Dir) Close() error

func (*Dir) Name

func (d *Dir) Name() string

func (*Dir) Read

func (d *Dir) Read([]byte) (int, error)

func (*Dir) ReadAt

func (d *Dir) ReadAt([]byte, int64) (int, error)

func (*Dir) Readdir

func (d *Dir) Readdir(n int) (out []os.FileInfo, err error)

func (*Dir) Readdirnames

func (d *Dir) Readdirnames(int) ([]string, error)

func (*Dir) Seek

func (d *Dir) Seek(int64, int) (int64, error)

func (*Dir) Stat

func (d *Dir) Stat() (os.FileInfo, error)

func (*Dir) Sync

func (d *Dir) Sync() error

func (*Dir) Truncate

func (d *Dir) Truncate(int64) error

func (*Dir) Write

func (d *Dir) Write([]byte) (int, error)

func (*Dir) WriteAt

func (d *Dir) WriteAt([]byte, int64) (int, error)

func (*Dir) WriteString

func (d *Dir) WriteString(string) (int, error)

type File

type File struct {
	*bytes.Reader
	Api
	// contains filtered or unexported fields
}

func (*File) Close

func (f *File) Close() error

func (*File) Name

func (f *File) Name() string

func (*File) Readdir

func (f *File) Readdir(int) ([]os.FileInfo, error)

func (*File) Readdirnames

func (f *File) Readdirnames(int) ([]string, error)

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) Truncate

func (f *File) Truncate(int64) error

func (*File) Write

func (f *File) Write([]byte) (int, error)

func (*File) WriteAt

func (f *File) WriteAt([]byte, int64) (int, error)

func (*File) WriteString

func (f *File) WriteString(string) (int, error)

type Fs

type Fs struct {
	AssetFunc
	AssetDirFunc
	AssetInfoFunc
}
Example
package main

import (
	"fmt"
	"io/ioutil"
	"log"

	bindatafs "github.com/jncornett/afero-bindatafs"
	"github.com/spf13/afero"
)

var (
	Asset     bindatafs.AssetFunc
	AssetDir  bindatafs.AssetDirFunc
	AssetInfo bindatafs.AssetInfoFunc
)

func main() {
	var fs afero.Fs = &bindatafs.Fs{
		AssetFunc:     Asset,
		AssetInfoFunc: AssetInfo,
		AssetDirFunc:  AssetDir,
	}
	f, err := fs.Open("data/a.txt")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	b, err := ioutil.ReadAll(f)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("contents of file:", string(b))
}

func (*Fs) Asset

func (fs *Fs) Asset(name string) ([]byte, error)

func (*Fs) AssetDir

func (fs *Fs) AssetDir(name string) ([]string, error)

func (*Fs) AssetInfo

func (fs *Fs) AssetInfo(name string) (os.FileInfo, error)

func (*Fs) Chmod

func (fs *Fs) Chmod(string, os.FileMode) error

func (*Fs) Chtimes

func (fs *Fs) Chtimes(string, time.Time, time.Time) error

func (*Fs) Create

func (fs *Fs) Create(string) (afero.File, error)

func (*Fs) Mkdir

func (fs *Fs) Mkdir(string, os.FileMode) error

func (*Fs) MkdirAll

func (fs *Fs) MkdirAll(string, os.FileMode) error

func (*Fs) Name

func (fs *Fs) Name() string

func (*Fs) Open

func (fs *Fs) Open(name string) (afero.File, error)

func (*Fs) OpenFile

func (fs *Fs) OpenFile(
	name string,
	flag int,
	mode os.FileMode,
) (afero.File, error)

func (*Fs) Remove

func (fs *Fs) Remove(string) error

func (*Fs) RemoveAll

func (fs *Fs) RemoveAll(string) error

func (*Fs) Rename

func (fs *Fs) Rename(string, string) error

func (*Fs) Stat

func (fs *Fs) Stat(name string) (os.FileInfo, error)

Directories

Path Synopsis
cmd
test command

Jump to

Keyboard shortcuts

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