*: fix os.PathSeparator in windows
3 files changed
tree: f6c22a8a91c27b500262e40316ede4b219f45be5
  1. memfs/
  2. osfs/
  3. subdir/
  4. test/
  5. .travis.yml
  6. appveyor.yml
  7. fs.go
  8. LICENSE
  9. Makefile
  10. README.md
  11. utils.go
README.md

go-billy GoDoc Build Status Build status codebeat badge

An interface to abstract several storages.

This library was extracted from src-d/go-git.

Installation

go get -u gopkg.in/src-d/go-billy.v2/...

Why billy?

The library billy deals with storage systems and Billy is the name of a well-known, IKEA bookcase. That's it.

Usage

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
}

License

MIT, see LICENSE