Categorygithub.com/go-git/go-billy/v5
modulepackage
5.6.2
Repository: https://github.com/go-git/go-billy.git
Documentation: pkg.go.dev

# README

go-billy GoDoc Test

The missing interface filesystem abstraction for Go. Billy 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.

Billy was born as part of go-git/go-git project.

Installation

import "github.com/go-git/go-billy/v5" // with go modules enabled (GO111MODULE=on or outside GOPATH)
import "github.com/go-git/go-billy" // with go modules disabled

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(origin billy.Filesystem, path string) (*memory.Memory, error) {
	memory := memory.New()

	files, err := origin.ReadDir("/")
	if err != nil {
		return nil, err
	}

	for _, file := range files {
		if file.IsDir() {
			continue
		}

		src, err := origin.Open(file.Name())
		if err != nil {
			return nil, err
		}

		dst, err := memory.Create(file.Name())
		if err != nil {
			return nil, err
		}

		if _, err = io.Copy(dst, src); err != nil {
			return nil, err
		}

		if err := dst.Close(); err != nil {
			return nil, err
		}

		if err := src.Close(); err != nil {
			return nil, err
		}
	}

	return memory, nil
}

Why billy?

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

License

Apache License Version 2.0, see LICENSE

# Packages

No description provided by the author
Package memfs provides a billy filesystem base on memory.
Package osfs provides a billy filesystem for the OS.
No description provided by the author
No description provided by the author

# Functions

Capabilities returns the features supported by a filesystem.
CapabilityCheck tests the filesystem for the provided capabilities and returns true in case it supports all of them.

# Constants

AllCapabilities lists all capable features.
DefaultCapabilities lists all capable features supported by filesystems without Capability interface.
LockCapability is the ability to lock a file.
ReadAndWriteCapability is the ability to open a file in read and write mode.
ReadCapability means that the fs is readable.
SeekCapability means it is able to move position inside the file.
TruncateCapability means that a file can be truncated.
WriteCapability means that the fs is writable.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

Basic abstract the basic operations in a storage-agnostic interface as an extension to the Basic interface.
Capable interface can return the available features of a filesystem.
Change abstract the FileInfo change related operations in a storage-agnostic interface as an extension to the Basic interface.
Chroot abstract the chroot related operations in a storage-agnostic interface as an extension to the Basic interface.
Dir abstract the dir related operations in a storage-agnostic interface as an extension to the Basic interface.
File represent a file, being a subset of the os.File.
Filesystem abstract the operations in a storage-agnostic interface.
Symlink abstract the symlink related operations in a storage-agnostic interface as an extension to the Basic interface.
No description provided by the author

# Type aliases

Capability holds the supported features of a billy filesystem.