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
- func MustClose(c Closer)
- func MustFlush(fs FileSystem, buffer []byte, name string, permission Mode)
- func MustReadData(r Reader, offset int64, buff []byte)
- func MustWriteData(w SeqWriter, data []byte)
- type Closer
- type DirEntry
- type File
- type FileSystem
- type FileSystemError
- type LocalFile
- func (file *LocalFile) Close() error
- func (file *LocalFile) Path() string
- func (file *LocalFile) Read(offset int64, buffer []byte) (int, error)
- func (file *LocalFile) Readv(offset int64, iov *[][]byte) (int, error)
- func (file *LocalFile) SequentialRead() SeqReader
- func (file *LocalFile) SequentialWrite() SeqWriter
- func (file *LocalFile) Size() (int64, error)
- func (file *LocalFile) Write(buffer []byte) (int, error)
- func (file *LocalFile) Writev(iov *[][]byte) (int, error)
- type Mode
- type Reader
- type SeqReader
- type SeqWriter
- type Writer
Constants ¶
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
MustReadData reads data from r and panics if it cannot read all data.
func MustWriteData ¶ added in v0.6.0
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
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) Readv ¶ added in v0.6.0
Readv is used to read contiguous regions of a file and disperse them into discontinuous buffers.
func (*LocalFile) SequentialRead ¶ added in v0.6.0
SequentialRead is used to read the entire file using streaming read.
func (*LocalFile) SequentialWrite ¶ added in v0.6.0
SequentialWrite supports appending consecutive buffers to the end of the file.
func (*LocalFile) Size ¶ added in v0.6.0
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.
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 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.