Skip to content

Commit 35732c5

Browse files
authored
readme: update description
1 parent edaa8cd commit 35732c5

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

README.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# go-billy [![GoDoc](https://godoc.org/gopkg.in/src-d/go-billy.v2?status.svg)](https://godoc.org/gopkg.in/src-d/go-billy.v2) [![Build Status](https://travis-ci.org/src-d/go-billy.svg)](https://travis-ci.org/src-d/go-billy) [![Build status](https://ci.appveyor.com/api/projects/status/vx2qn6vlakbi724t?svg=true)](https://ci.appveyor.com/project/mcuadros/go-billy) [![codecov](https://codecov.io/gh/src-d/go-billy/branch/master/graph/badge.svg)](https://codecov.io/gh/src-d/go-billy) [![codebeat badge](https://codebeat.co/badges/03bdec03-b477-4472-bbe3-b552e3799174)](https://codebeat.co/projects/github-com-src-d-go-billy)
22

3-
An interface to abstract several storages.
3+
The missing interface filesystem abstraction for Go.
4+
Billy implements an interface based on the `os` standard library, allowing to develop applications without dependency on the underlying storage. Make virtually free implement an mocks and testing over filesystem operations.
45

5-
This library was extracted from
6-
[src-d/go-git](https://github.com/src-d/go-git).
6+
Billy was born as part of [src-d/go-git](https://github.com/src-d/go-git) project.
77

88
## Installation
99

@@ -27,29 +27,39 @@ The following example caches in memory all readable files in a directory from an
2727
billy's filesystem implementation.
2828

2929
```go
30-
func LoadToMemory(fs billy.Filesystem, path string) (*memory.Memory, error) {
30+
func LoadToMemory(origin billy.Filesystem, path string) (*memory.Memory, error) {
3131
memory := memory.New()
3232

33-
files, err := fs.ReadDir("/")
33+
files, err := origin.ReadDir("/")
3434
if err != nil {
3535
return nil, err
3636
}
3737

3838
for _, file := range files {
39-
if !file.IsDir() {
40-
orig, err := fs.Open(file.Name())
41-
if err != nil {
42-
continue
43-
}
44-
45-
dest, err := memory.Create(file.Name())
46-
if err != nil {
47-
continue
48-
}
49-
50-
if _, err = io.Copy(dest, orig); err != nil {
51-
return nil, err
52-
}
39+
if file.IsDir() {
40+
continue
41+
}
42+
43+
src, err := origin.Open(file.Name())
44+
if err != nil {
45+
return nil, err
46+
}
47+
48+
dst, err := memory.Create(file.Name())
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
if _, err = io.Copy(dst, src); err != nil {
54+
return nil, err
55+
}
56+
57+
if err := dst.Close(); err != nil {
58+
return nil, err
59+
}
60+
61+
if err := src.Close(); err != nil {
62+
return nil, err
5363
}
5464
}
5565

0 commit comments

Comments
 (0)