1# go-billy [![GoDoc](https://godoc.org/gopkg.in/go-git/go-billy.v5?status.svg)](https://pkg.go.dev/github.com/go-git/go-billy/v5) [![Test](https://github.com/go-git/go-billy/workflows/Test/badge.svg)](https://github.com/go-git/go-billy/actions?query=workflow%3ATest)
 2
 3The missing interface filesystem abstraction for Go.
 4Billy implements an interface based on the `os` standard library, allowing to develop applications without dependency on the underlying storage. Makes it virtually free to implement mocks and testing over filesystem operations.
 5
 6Billy was born as part of [go-git/go-git](https://github.com/go-git/go-git) project.
 7
 8## Version support
 9
10go-billy v5 is in maintenance mode. Users should upgrade to [go-billy v6](https://pkg.go.dev/github.com/go-git/go-billy/v6) where possible.
11
12## Installation
13
14```go
15import "github.com/go-git/go-billy/v5" // with go modules enabled (GO111MODULE=on or outside GOPATH)
16import "github.com/go-git/go-billy" // with go modules disabled
17```
18
19## Usage
20
21Billy exposes filesystems using the
22[`Filesystem` interface](https://pkg.go.dev/github.com/go-git/go-billy/v5?tab=doc#Filesystem).
23Each filesystem implementation gives you a `New` method, whose arguments depend on
24the implementation itself, that returns a new `Filesystem`.
25
26The following example caches in memory all readable files in a directory from any
27billy's filesystem implementation.
28
29```go
30func LoadToMemory(origin billy.Filesystem, path string) (*memory.Memory, error) {
31	memory := memory.New()
32
33	files, err := origin.ReadDir("/")
34	if err != nil {
35		return nil, err
36	}
37
38	for _, file := range files {
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
63		}
64	}
65
66	return memory, nil
67}
68```
69
70## Why billy?
71
72The library billy deals with storage systems and Billy is the name of a well-known, IKEA
73bookcase. That's it.
74
75## License
76
77Apache License Version 2.0, see [LICENSE](LICENSE)