osfs

package module
v0.0.0-...-80b6215 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2022 License: MIT Imports: 7 Imported by: 1

README

osfs - Abstract File System interface

osfs package implements the absfs.FileSystem interface using the os standard library file access functions.

Install

$ go get github.com/absfs/osfs

Example Usage

package main

import (
	"log"
	"os"

	"github.com/absfs/osfs"
)

func ExitOnError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func main() {
	fs, err := osfs.NewFS()
	ExitOnError(err)

	f, err := fs.Create("example.txt")
	ExitOnError(err)

	_, err = f.Write([]byte("Hello, world!\n"))
	ExitOnError(err)

	err = f.Close()
	ExitOnError(err)

	// if "keep" is passed as the first argument, don't delete the file
	if len(os.Args) > 1 && os.Args[1] == "keep" {
		return
	}

	// delete the file
	err = fs.Remove("example.txt")
	ExitOnError(err)
}


absfs

Check out the absfs repo for more information about the abstract filesystem interface and features like filesystem composition

LICENSE

This project is governed by the MIT License. See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Name

func (f *File) Name() string

func (*File) Read

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

func (*File) ReadAt

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

func (*File) Readdir

func (f *File) Readdir(n int) ([]os.FileInfo, error)

func (*File) Readdirnames

func (f *File) Readdirnames(n int) ([]string, error)

func (*File) Seek

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

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) Truncate

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

func (*File) Write

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

func (*File) WriteAt

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

func (*File) WriteString

func (f *File) WriteString(s string) (n int, err error)

type FileSystem

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

func NewFS

func NewFS() (*FileSystem, error)

func (*FileSystem) Chdir

func (fs *FileSystem) Chdir(name string) error

func (*FileSystem) Chmod

func (fs *FileSystem) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*FileSystem) Chown

func (fs *FileSystem) Chown(name string, uid, gid int) error

Chown changes the owner and group ids of the named file

func (*FileSystem) Chtimes

func (fs *FileSystem) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*FileSystem) Create

func (fs *FileSystem) Create(name string) (absfs.File, error)

func (*FileSystem) FastWalk

func (fs *FileSystem) FastWalk(path string, fn func(string, os.FileMode) error) error

func (*FileSystem) Getwd

func (fs *FileSystem) Getwd() (dir string, err error)

func (*FileSystem) Lchown

func (fs *FileSystem) Lchown(name string, uid, gid int) error

func (*FileSystem) ListSeparator

func (fs *FileSystem) ListSeparator() uint8

func (*FileSystem) Lstat

func (fs *FileSystem) Lstat(name string) (os.FileInfo, error)

func (*FileSystem) Mkdir

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

func (*FileSystem) MkdirAll

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

func (*FileSystem) Open

func (fs *FileSystem) Open(name string) (absfs.File, error)

func (*FileSystem) OpenFile

func (fs *FileSystem) OpenFile(name string, flag int, perm os.FileMode) (absfs.File, error)
func (fs *FileSystem) Readlink(name string) (string, error)

func (*FileSystem) Remove

func (fs *FileSystem) Remove(name string) error

func (*FileSystem) RemoveAll

func (fs *FileSystem) RemoveAll(name string) error

func (*FileSystem) Rename

func (fs *FileSystem) Rename(oldpath, newpath string) error

func (*FileSystem) Separator

func (fs *FileSystem) Separator() uint8

func (*FileSystem) Stat

func (fs *FileSystem) Stat(name string) (os.FileInfo, error)
func (fs *FileSystem) Symlink(oldname, newname string) error

func (*FileSystem) TempDir

func (fs *FileSystem) TempDir() string

func (*FileSystem) Truncate

func (fs *FileSystem) Truncate(name string, size int64) error

func (*FileSystem) Walk

func (fs *FileSystem) Walk(path string, fn func(string, os.FileInfo, error) error) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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