fs

package module
v0.0.0-...-0f47780 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2014 License: MIT Imports: 2 Imported by: 0

README

fs Build Status Build Status Build status Coverage Status

Interface and mocks for the os package. Plus utility and codegen commands.

cmd/gotree GoDoc

Command gotree is Go implementation of the Unix tree command.

Installation

~ $ go get -u github.com/rjeczalik/fs/cmd/gotree

Documentation

godoc.org/github.com/rjeczalik/fs/cmd/gotree

Usage

~/src $ gotree github.com/rjeczalik/fs
github.com/rjeczalik/fs/.
├── fs.go
├── fsutil
│   ├── fsutil.go
│   ├── fsutil_test.go
│   ├── tee.go
│   └── tee_test.go
└── memfs
    ├── memfs.go
    ├── memfs_test.go
    ├── tree.go
    ├── tree_test.go
    ├── util.go
    └── util_test.go

2 directories, 11 files

NOTE fs.Filesystem does not support symlinks yet (#1), that's why gotree will print any symlink as regular file or directory. Moreover it won't follow nor resolve any of them.

~/src $ gotree -go=80 github.com/rjeczalik/fs
memfs.Must(memfs.UnmarshalTab([]byte(".\n\tfs.go\n\tfsutil\n\t\tfsutil.go" +
	"\n\t\tfsutil_test.go\n\t\ttee.go\n\t\ttee_test.go\n\tmemfs\n\t\tmem" +
	"fs.go\n\t\tmemfs_test.go\n\t\ttree.go\n\t\ttree_test.go\n\t\tutil.g" +
	"o\n\t\tutil_test.go\n")))
~/src $ gotree -var=fspkg github.com/rjeczalik/fs
var fspkg = memfs.Must(memfs.UnmarshalTab([]byte(".\n\tfs.go\n\tfsutil\n\t" +
	"\tfsutil.go\n\t\tfsutil_test.go\n\t\ttee.go\n\t\ttee_test.go\n\tmem" +
	"fs\n\t\tmemfs.go\n\t\tmemfs_test.go\n\t\ttree.go\n\t\ttree_test.go\n" +
	"\t\tutil.go\n\t\tutil_test.go\n")))

cmd/mktree GoDoc

Command mktree creates a file tree out of tree output read from standard input.

Installation

~ $ go get -u github.com/rjeczalik/fs/cmd/mktree

Documentation

godoc.org/github.com/rjeczalik/fs/cmd/mktree

Usage

~ $ gotree
.
├── dir
│   └── file.txt
└── file.txt

1 directory, 2 files

~ $ gotree | mktree -o /tmp/mktree

~ $ gotree /tmp/mktree
/tmp/mktree
├── dir
│   └── file.txt
└── file.txt

1 directory, 2 files
~ $ gotree > tree.txt

~ $ mktree -o /tmp/mktree2 tree.txt

~ $ gotree /tmp/mktree2
/tmp/mktree2
├── dir
│   └── file.txt
└── file.txt

1 directory, 2 files

fs GoDoc

Package fs provides an interface for the filesystem-related functions from the os package.

Installation

~ $ go get -u github.com/rjeczalik/fs

Documentation

godoc.org/github.com/rjeczalik/fs

memfs GoDoc

Package memfs provides an implementation for an in-memory filesystem.

Installation

~ $ go get -u github.com/rjeczalik/fs/memfs

Documentation

godoc.org/github.com/rjeczalik/fs/memfs

fsutil GoDoc

Package fsutil is a collection of various filesystem utility functions.

Installation

~ $ go get -u github.com/rjeczalik/fs/fsutil

Documentation

godoc.org/github.com/rjeczalik/fs/fsutil

Documentation

Overview

Package fs provides an interface for a filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mkdir

func Mkdir(name string, perm os.FileMode) error

Mkdir wraps Default.Mkdir.

func MkdirAll

func MkdirAll(name string, perm os.FileMode) error

Mkdir wraps Default.MkdirAll.

func Remove

func Remove(name string) error

Remove wraps Default.Remove.

func RemoveAll

func RemoveAll(name string) error

RemoveAll wraps Default.RemoveAll.

func Stat

func Stat(name string) (os.FileInfo, error)

Stat wraps Default.Stat.

func Walk

func Walk(root string, fn filepath.WalkFunc) error

Walk wraps Default.Walk.

Types

type FS

type FS struct{}

FS provides an implementation for Filesystem interface, wrapping functions from the os package.

func (FS) Create

func (FS) Create(name string) (File, error)

Create wraps os.Create.

func (FS) Mkdir

func (FS) Mkdir(name string, perm os.FileMode) error

Mkdir wraps os.Mkdir.

func (FS) MkdirAll

func (FS) MkdirAll(name string, perm os.FileMode) error

Mkdir wraps os.MkdirAll.

func (FS) Open

func (FS) Open(name string) (File, error)

Open wraps os.Open.

func (FS) Remove

func (FS) Remove(name string) error

Remove wraps os.Remove.

func (FS) RemoveAll

func (FS) RemoveAll(name string) error

RemoveAll wraps os.RemoveAll.

func (FS) Stat

func (FS) Stat(name string) (os.FileInfo, error)

Stat wraps os.Stat.

func (FS) Walk

func (FS) Walk(root string, fn filepath.WalkFunc) error

Walk wraps filepath.Walk.

type File

type File interface {
	// Close closes the underlying file.
	// Default implementation wraps (*os.File).Close.
	Close() error
	// Read reads the content of the File.
	// Default implementation wraps (*os.File).Read.
	Read([]byte) (int, error)
	// Readdir gives the file list if the File is a directory.
	// Default implementation wraps (*os.File).Readdir.
	Readdir(int) ([]os.FileInfo, error)
	// Seek moves the current file offset.
	// Default implementation wraps (*os.File).Seek.
	Seek(int64, int) (int64, error)
	// Stat gives the File details.
	// Default implementation wraps (*os.File).Stat.
	Stat() (os.FileInfo, error)
	// Write writes data to the File.
	// Default implementation wraps (*os.File).Write.
	Write([]byte) (int, error)
}

File is an almost complete interface for the *os.File.

func Create

func Create(name string) (File, error)

Create wraps Default.Create.

func Open

func Open(name string) (File, error)

Open wraps Default.Open.

type Filesystem

type Filesystem interface {
	// Create creates new file or truncates existing one.
	Create(string) (File, error)
	// Mkdir creates new directory. It's a nop, if the directory already exists.
	Mkdir(string, os.FileMode) error
	// MkdirAll creates new directory and all its parents, if needed.
	MkdirAll(string, os.FileMode) error
	// Open opens a file or a directory given by the path.
	Open(string) (File, error)
	// Remove deletes a file given by the path.
	Remove(string) error
	// Stat gives a file or a directory details, given by the path.
	RemoveAll(string) error
	// RemoveAll deletes a file or a directory with all its descendants, given
	// by the path.
	Stat(string) (os.FileInfo, error)
	// Walk walks the file tree starting at root, calling WalkFunc for each file
	// or directory.
	Walk(string, filepath.WalkFunc) error
}

Filesystem provides an interface for operating on named files.

var Default Filesystem = FS{}

Default is the default implementation of Filesystem, which wraps functions from the os package.

Directories

Path Synopsis
cmd
gotree
Command gotree is a reimplmentation of the Unix tree command in Go.
Command gotree is a reimplmentation of the Unix tree command in Go.
mktree
Command mktree creates a file tree out of tree output read from standard input.
Command mktree creates a file tree out of tree output read from standard input.
Package fsutil is a collection of various filesystem utility functions.
Package fsutil is a collection of various filesystem utility functions.
Package memfs provides an interface for an in-memory filesystem.
Package memfs provides an interface for an in-memory filesystem.

Jump to

Keyboard shortcuts

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