Giter Club home page Giter Club logo

afero's Introduction

afero


.go file https://github.com/spf13/afero

import "github.com/spf13/afero"

var AppFs = afero.NewMemMapFs()

var AppFs = afero.NewOsFs()

os.Open('/tmp/foo')
AppFs.Open('/tmp/foo')

Chmod(name string, mode os.FileMode) : error
Chtimes(name string, atime time.Time, mtime time.Time) : error
Create(name string) : File, error
Mkdir(name string, perm os.FileMode) : error
MkdirAll(path string, perm os.FileMode) : error
Name() : string
Open(name string) : File, error
OpenFile(name string, flag int, perm os.FileMode) : File, error
Remove(name string) : error
RemoveAll(name string) : error
Rename(oldname, newname string) : error
Stat(name string) : os.FileInfo, error


io.Closer
io.Reader
io.ReaderAt
io.Seeker
io.Writer
io.WriterAt

Name() : string
Readdir(count int) : []os.FileInfo, error
Readdirnames(n int) : []string, error
Stat() : os.FileInfo, error
Sync() : error
Truncate(size int64) : error
WriteString(s string) : ret int, err error


DirExists(path string) (bool, error)
Exists(path string) (bool, error)
FileContainsBytes(filename string, subslice []byte) (bool, error)
GetTempDir(subPath string) string
IsDir(path string) (bool, error)
IsEmpty(path string) (bool, error)
ReadDir(dirname string) (bool, error)
ReadFile(filename string) ([]byte, error)
SafeWriteReader(path string, r io.Reader) (err error)
TempDir(dir, prefix string) (name string, err error)
TempFile(dir, prefix string)(f File, err error)
Walk(root string, walkFn filepath.WalkFunc) error
WriteFile(filename string, data []byte, perm os.FileMode) error
WriteReader(path string, r io.Reader) (err error)


fs := new(afero.MemMapFs)
f, err := afero.Temp(fs, "", "ioutil-test")

fs := afero.NewMemMapFs()
afs := &afero.Afero{Fs: fs}
f, err := afs.TempFile("", "ioutil-test")


func TestExist(t *testing.T) {
  appFS := afero.NewMemMapFs()
  
  appFS.MkdirAll("src/a", 0755)
  afero.WriteFile(appFS, "src/a/b", []byte(), 0644)
  afero.WriteFile(appFS, "src/c", []byte("file c"), 0644)
  name := "src/c"
  _, err := appFS.Stat(name)
  if os.IsNotExist(err) {
    t.Errorf("file \"%s\" does not exist.\n", name)
  }
}


appfs := afero.NewOsFs()
appfs.MkdirAll("src/a", 0755)

mm := afero.NewMemMapFs()
mm.MkdirAll("src/a", 0755)

bq := afero.NewBasePathFs(afero.NewOsFs(), "/base/path")

fs := afero.NewReadOnlyFs(afero.NewOsFs())
_, err := fs.Create("/file.txt")

fs := afero.NewRegexpFs(afero.NewMemMapFs(), regexp.MustCopile(`\.txt$`))
_, err := fs.Create("/file.html")


httpFs := afero.NewHttpFs(<ExistingFS>)
fileserver := http.FileServer(httpFs.Dir(<PATH>))
http.Handle("/", fileserver)

base := afero.NewOsFs()
layer := afero.NewMemMapFs()
ufs := afero.NewCacheOnReadFs(base, layer, 100 * time.Second)

base := afero.NewOsFs()
roBase := afero.NewReadOnlyFs(base)
ufs := afero.NewCpyOnWriteFs(roBase, afero.NewMemMapFs())

fh, _ = ufs.Create("/home/test/file2.txt")
fh.WriteString("This is atest")
fh.Close()
go get github.com/spf13/afero

afero's People

Contributors

takagotch avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.