Giter Club home page Giter Club logo

go-billy's Introduction

go-billy GoDoc 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

go-billy's People

Contributors

ajnavarro avatar alcortesm avatar jinroh avatar mcuadros avatar serabe avatar smola avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.