fs

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fs (file system) is an independent component to operate file and directory.

Package fs (file system) is an independent component to operate file and directory.

Package fs (file system) is an independent component to operate file and directory.

Index

Constants

View Source
const (
	IsNotExistError
)

FileSystemError code.

Variables

This section is empty.

Functions

func MustClose added in v0.6.0

func MustClose(c Closer)

MustClose closes c and panics if it cannot close.

func MustFlush added in v0.6.0

func MustFlush(fs FileSystem, buffer []byte, name string, permission Mode)

MustFlush flushes all data to one file and panics if it cannot write all data.

func MustReadData added in v0.6.0

func MustReadData(r Reader, offset int64, buff []byte)

MustReadData reads data from r and panics if it cannot read all data.

func MustWriteData added in v0.6.0

func MustWriteData(w SeqWriter, data []byte)

MustWriteData writes data to w and panics if it cannot write all data.

Types

type Closer added in v0.6.0

type Closer interface {
	// Returns the absolute path of the file.
	Path() string
	// Close File.
	Close() error
}

Closer allows closing a file.

type DirEntry added in v0.6.0

type DirEntry interface {
	// Name returns the name of the file or directory.
	Name() string

	// IsDir reports whether the entry describes a directory.
	IsDir() bool
}

DirEntry is the interface that wraps the basic information about a file or directory.

type File

type File interface {
	Writer
	Reader
	// Vector Append mode, which supports appending consecutive buffers to the end of the file.
	Writev(iov *[][]byte) (int, error)
	// Reading contiguous regions of a file and dispersing them into discontinuous buffers.
	Readv(offset int64, iov *[][]byte) (int, error)
	// Get the file written data's size and return an error if the file does not exist. The unit of file size is Byte.
	Size() (int64, error)
	// Returns the absolute path of the file.
	Path() string
	// Close File.
	Close() error
}

File operation interface.

func MustCreateFile added in v0.6.0

func MustCreateFile(fs FileSystem, path string, permission Mode) File

MustCreateFile creates a new file with the specified name and permission.

type FileSystem

type FileSystem interface {
	// MkdirIfNotExist creates a new directory with the specified name and permission if it does not exist.
	// If the directory exists, it will do nothing.
	MkdirIfNotExist(path string, permission Mode)
	// MkdirPanicIfExist creates a new directory with the specified name and permission if it does not exist.
	// If the directory exists, it will panic.
	MkdirPanicIfExist(path string, permission Mode)
	// ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename.
	ReadDir(dirname string) []DirEntry
	// Create and open the file by specified name and mode.
	CreateFile(name string, permission Mode) (File, error)
	// Create and open lock file by specified name and mode.
	CreateLockFile(name string, permission Mode) (File, error)
	// Open the file by specified name and mode.
	OpenFile(name string) (File, error)
	// Flush mode, which flushes all data to one file.
	Write(buffer []byte, name string, permission Mode) (int, error)
	// Read the entire file using streaming read.
	Read(name string) ([]byte, error)
	// Delete the file.
	DeleteFile(name string) error
	// Delete the directory.
	MustRMAll(path string)
	// SyncPath the directory of file.
	SyncPath(path string)
	// MustGetFreeSpace returns the free space of the file system.
	MustGetFreeSpace(path string) uint64
}

FileSystem operation interface.

func NewLocalFileSystem added in v0.6.0

func NewLocalFileSystem() FileSystem

NewLocalFileSystem is used to create the Local File system.

func NewLocalFileSystemWithLogger added in v0.6.0

func NewLocalFileSystemWithLogger(parent *logger.Logger) FileSystem

NewLocalFileSystemWithLogger is used to create the Local File system with logger.

type FileSystemError added in v0.6.0

type FileSystemError struct {
	Message string
	Code    int
}

FileSystemError implements the Error interface.

func (*FileSystemError) Error added in v0.6.0

func (err *FileSystemError) Error() string

type LocalFile added in v0.6.0

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

LocalFile implements the File interface.

func (*LocalFile) Close added in v0.6.0

func (file *LocalFile) Close() error

Close is used to close File.

func (*LocalFile) Path added in v0.6.0

func (file *LocalFile) Path() string

Path returns the absolute path of the file.

func (*LocalFile) Read added in v0.6.0

func (file *LocalFile) Read(offset int64, buffer []byte) (int, error)

Read is used to read a specified location of file.

func (*LocalFile) Readv added in v0.6.0

func (file *LocalFile) Readv(offset int64, iov *[][]byte) (int, error)

Readv is used to read contiguous regions of a file and disperse them into discontinuous buffers. TODO: Optimizing under Linux.

func (*LocalFile) SequentialRead added in v0.6.0

func (file *LocalFile) SequentialRead() SeqReader

SequentialRead is used to read the entire file using streaming read.

func (*LocalFile) SequentialWrite added in v0.6.0

func (file *LocalFile) SequentialWrite() SeqWriter

SequentialWrite supports appending consecutive buffers to the end of the file.

func (*LocalFile) Size added in v0.6.0

func (file *LocalFile) Size() (int64, error)

Size is used to get the file written data's size and return an error if the file does not exist. The unit of file size is Byte.

func (*LocalFile) Write added in v0.6.0

func (file *LocalFile) Write(buffer []byte) (int, error)

Write adds new data to the end of a file.

func (*LocalFile) Writev added in v0.6.0

func (file *LocalFile) Writev(iov *[][]byte) (int, error)

Writev supports appending consecutive buffers to the end of the file. TODO: Optimizing under Linux.

type Mode

type Mode uint64

Mode contains permission of file and directory.

type Reader added in v0.6.0

type Reader interface {
	// Read the entire file at a specified offset.
	Read(offset int64, buffer []byte) (int, error)
	// Read the entire file using sequential read.
	SequentialRead() SeqReader
	// Returns the absolute path of the file.
	Path() string
	// Close File.
	Close() error
}

Reader allows reading data from a file.

type SeqReader added in v0.6.0

type SeqReader interface {
	io.Reader
	Path() string
	Close() error
}

SeqReader allows reading data from a file in a sequential way.

type SeqWriter added in v0.6.0

type SeqWriter interface {
	io.Writer
	Path() string
	Close() error
}

SeqWriter allows writing data to a file in a sequential way.

type Writer added in v0.6.0

type Writer interface {
	// Append mode, which adds new data to the end of a file.
	Write(buffer []byte) (int, error)
	// SequentialWrite mode, which supports appending consecutive buffers to the end of the file.
	SequentialWrite() SeqWriter
	// Returns the absolute path of the file.
	Path() string
	// Close File.
	Close() error
}

Writer allows writing data to a file.

Jump to

Keyboard shortcuts

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