fs

package
v0.0.0-...-9645bb5 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package fs contains functionalities of reader and writer for a file

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFilesystemFilepathIsEmpty                 = errors.New("package fs - could not create new file system instance - path is empty")
	ErrFilesystemMemoryRentConflictWithFlushSize = errors.New("package fs - filesystem memory rent size always should be greater than flush size")
	ErrFilesystemCouldNotWrite                   = errors.New("package fs - filesystem could not write")
	ErrFilesystemWriterNil                       = errors.New("package fs - writer instance of filesystem has been closed or doesn't initialized")
	ErrFilesystemWriterCouldNotSync              = errors.New("package fs - writer instance of filesystem could not sync")
	ErrFilesystemCouldNotCloseWriter             = errors.New("package fs - filesystem could not close writer instance")
	ErrFilesystemReaderOccupying                 = errors.New("package fs - filesystem doesn't have any free reader")
	ErrFilesystemCouldNotReadData                = errors.New("package fs - filesystem could not read data")
	ErrFilesystemCouldNotReadAllData             = errors.New("package fs - filesystem could not read all data")
	ErrFilesystemReaderNil                       = errors.New("package fs - reader instance of filesystem has been closed or doesn't initialized")
	ErrFilesystemCouldNotCloseReader             = errors.New("package fs - filesystem could not close reader")
)
View Source
var (
	ErrFileIsNotExists         = errors.New("file path doesn't exist")
	ErrDirectoryIsNotExists    = errors.New("directory path doesn't exist")
	ErrCouldNotCreateDirectory = errors.New("could not create directory")
)

Functions

func CreateDirectory

func CreateDirectory(path string, mkdirAllFunc MkdirAll) error

CreateDirectory will create directory recursively

func IsDirectoryExists

func IsDirectoryExists(path string, statFunc Stat, isNotExistFunc IsNotExist) error

IsDirectoryExists checks directory exist or not

func IsFileExists

func IsFileExists(path string, statFunc Stat) error

IsFileExists checks file exist or not

Types

type Filesystem

type Filesystem interface {
	// Write will write or update raw data into file
	Write(rawData []byte, offset int64, seek int) error
	// Sync will sync data from in-memory to disk
	Sync() error
	// GetWriterId return id of writer instance
	GetWriterId() (uuid.UUID, error)
	// CloseWriter will close writer of filesystem instance
	CloseWriter() error
	// ReadData func provides reading data from file by defining custom pos & seek option
	ReadData(offset int64, length int, seek int) ([]byte, error)
	// ReadAllData func provides reading all data from file
	ReadAllData() ([]byte, error)
	// GetReaderId return id of reader instance
	GetReaderId() (uuid.UUID, error)
	// CloseReader func provides close reader of filesystem instance
	CloseReader() error
	// GetReaderState return state of reader instance
	GetReaderState() (bool, error)
}

func NewFilesystem

func NewFilesystem(fPath string, config fsConfig.FSConfiguration, file file.File, statFunc Stat, isNotExistFunc IsNotExist, mkdirAllFunc MkdirAll) (Filesystem, error)

NewFilesystem provide new instance of filesystem with readers and writer based on your configuration

type IsNotExist

type IsNotExist func(err error) bool

type MkdirAll

type MkdirAll func(path string, mode fs.FileMode) error

type Stat

type Stat func(path string) (fs.FileInfo, error)

Jump to

Keyboard shortcuts

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