commit | 92b2976bbd598726dc4aef9895f75aba4ad506cf | [log] [tgz] |
---|---|---|
author | Máximo Cuadros <mcuadros@gmail.com> | Fri Apr 14 19:43:18 2017 |
committer | Máximo Cuadros <mcuadros@gmail.com> | Fri Apr 14 19:43:18 2017 |
tree | d959f2047bdb2dc5a167b990897f99b1a7989249 | |
parent | 7b31338a87d39489a486979650b9cb497485a461 [diff] | |
parent | bf5cdf7d823be98aa2851ad3e1253cd11bcea1fe [diff] |
Merge branch 'master' of github.com:src-d/go-billy
An interface to abstract several storages.
This library was extracted from src-d/go-git.
go get -u gopkg.in/src-d/go-billy.v2/...
The library billy deals with storage systems and Billy is the name of a well-known, IKEA bookcase. That's it.
Billy exposes filesystems using the Filesystem
interface. Each filesystem implementation gives you a New
method, whose arguments depend on the implementation itself, that returns a new Filesystem
.
The following example caches in memory all readable files in a directory from any billy's filesystem implementation.
func LoadToMemory(fs billy.Filesystem, path string) (*memory.Memory, error) {
memory := memory.New()
files, err := fs.ReadDir("/")
if err != nil {
return nil, err
}
for _, file := range files {
if !file.IsDir() {
orig, err := fs.Open(file.Name())
if err != nil {
continue
}
dest, err := memory.Create(file.Name())
if err != nil {
continue
}
if _, err = io.Copy(dest, orig); err != nil {
return nil, err
}
}
}
return memory, nil
}
MIT, see LICENSE