commit | df3e8e3144d8af04d42e3fa5da6f09ab058d9bb1 | [log] [tgz] |
---|---|---|
author | Máximo Cuadros <mcuadros@gmail.com> | Sat Apr 15 22:05:12 2017 |
committer | GitHub <noreply@github.com> | Sat Apr 15 22:05:12 2017 |
tree | c7100d4a154db58c629480177cec93f1b910a7f9 | |
parent | 88d97b784d2f0b57f6026d2cf6e52723cb99efb6 [diff] | |
parent | 3f6f030564ad546028709545a9692eb5b32dea96 [diff] |
Merge pull request #23 from src-d/test-improvements test improvements
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