desfacer

package module
v0.0.0-...-b43512b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 7 Imported by: 4

README

go-billy-desfacer GoDocBuild Statuscodecov

go-billy filesystem that wraps afero. It lets use afero filesystems with software that expects go-billy, for example with go-git.

Installation

go get gopkg.in/jfontan/go-billy-desfacer.v0

Example of use

package main

import (
	"fmt"

	"github.com/spf13/afero"
	"gopkg.in/jfontan/go-billy-desfacer.v0"
)

func main() {
	// wrap an afero filesystem to billy interface
	aferofs := afero.NewMemMapFs()
	billyfs := desfacer.New(aferofs)

	// create a file with billy interface
	billyfile, err := billyfs.Create("file")
	if err != nil {
		panic(err)
	}

	_, err = billyfile.Write([]byte("some data"))
	if err != nil {
		panic(err)
	}
	_ = billyfile.Close()

	// read file directly in afero filesystem
	aferofile, err := aferofs.Open("file")
	if err != nil {
		panic(err)
	}

	buf := make([]byte, 32)
	n, err := aferofile.Read(buf)
	if err != nil {
		panic(err)
	}
	_ = aferofile.Close()

	fmt.Println(string(buf[:n]))
}

Notes

  • The functions Symlink and Readlink are not implemented as afero does not have that functionality.

The name

"desfacer" means "to undo" or "to unmake" in Galician and old Spanish.

License

Apache License Version 2.0, see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrNotImplemented is returned when the function is not implemented.
	ErrNotImplemented = fmt.Errorf("functionality not implemented")
)

Functions

This section is empty.

Types

type FS

type FS struct {
	// contains filtered or unexported fields
}

func New

func New(fs afero.Fs) *FS

func NewPath

func NewPath(fs afero.Fs, path string) *FS

func (*FS) Chroot

func (f *FS) Chroot(path string) (billy.Filesystem, error)

Chroot implements billy.Chroot interface.

func (*FS) Create

func (f *FS) Create(filename string) (billy.File, error)

Create implements billy.Basic interface.

func (*FS) Join

func (f *FS) Join(elem ...string) string

Join implements billy.Basic interface.

func (*FS) Lstat

func (f *FS) Lstat(filename string) (os.FileInfo, error)

Lstat implements billy.Symlink interface.

func (*FS) MkdirAll

func (f *FS) MkdirAll(filename string, perm os.FileMode) error

MkdirAll implements billy.Dir interface.

func (*FS) Open

func (f *FS) Open(filename string) (billy.File, error)

Open implements billy.Basic interface.

func (*FS) OpenFile

func (f *FS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

OpenFile implements billy.Basic interface.

func (*FS) ReadDir

func (f *FS) ReadDir(path string) ([]os.FileInfo, error)

ReadDir implements billy.Dir interface.

func (f *FS) Readlink(link string) (string, error)

Readlink implements billy.Symlink interface.

func (*FS) Remove

func (f *FS) Remove(filename string) error

Remove implements billy.Basic interface.

func (*FS) Rename

func (f *FS) Rename(oldpath string, newpath string) error

Rename implements billy.Basic interface.

func (*FS) Root

func (f *FS) Root() string

Root implements billy.Chroot interface.

func (*FS) Stat

func (f *FS) Stat(filename string) (os.FileInfo, error)

Stat implements billy.Basic interface.

func (f *FS) Symlink(target string, link string) error

Symlink implements billy.Symlink interface.

func (*FS) TempFile

func (f *FS) TempFile(dir string, prefix string) (billy.File, error)

TempFile implements billy.TempFile interface.

type File

type File struct {
	// contains filtered or unexported fields
}

File wraps an afero.File.

func NewFile

func NewFile(path string, a afero.File) *File

NewFile creates a new File.

func (*File) Close

func (f *File) Close() error

Close implements billy.File interface.

func (*File) Lock

func (f *File) Lock() error

Lock implements billy.File interface.

func (*File) Name

func (f *File) Name() string

Name implements billy.File interface.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Read implements billy.File interface.

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements billy.File interface.

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek implements billy.File interface.

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate implements billy.File interface.

func (*File) Unlock

func (f *File) Unlock() error

Unlock implements billy.File interface.

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

Write implements billy.File interface.

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL