fileio

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileIOType = iota + 1 // Standard File IO
	BufIOType             // File IO with buffer
	MmapIOType            // Memory Mapping IO
)
View Source
const DataFilePerm = 0644

0644 Indicates that a file is created. The file owner can read and write the file, but others can only read the file

View Source
const DefaultFileSize = 256 * 1024 * 1024

Variables

This section is empty.

Functions

This section is empty.

Types

type Bufio

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

Bufio File IO with buffer

func NewBufIOManager

func NewBufIOManager(path string) (*Bufio, error)

NewBufIOManager init Bufio

func (*Bufio) Close

func (b *Bufio) Close() error

Close file

func (*Bufio) Flush

func (b *Bufio) Flush() error

Flush buffer

func (*Bufio) Read

func (b *Bufio) Read(bytes []byte, offset int64) (int, error)

Read bytes from offset

func (*Bufio) Size

func (b *Bufio) Size() (int64, error)

Size of file

func (*Bufio) Sync

func (b *Bufio) Sync() error

Sync file

func (*Bufio) Write

func (b *Bufio) Write(bytes []byte) (int, error)

Write bytes to file

type FileIO

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

FileIO represents the standard system file I/O.

func NewFileIOManager

func NewFileIOManager(fileName string) (*FileIO, error)

NewFileIOManager initializes the standard file I/O manager.

func (*FileIO) Close

func (fio *FileIO) Close() error

func (*FileIO) Read

func (fio *FileIO) Read(b []byte, offset int64) (int, error)

func (*FileIO) Size

func (fio *FileIO) Size() (int64, error)

func (*FileIO) Sync

func (fio *FileIO) Sync() error

func (*FileIO) Write

func (fio *FileIO) Write(b []byte) (int, error)

type IOManager

type IOManager interface {
	// Read reads the corresponding data from the file at the given position.
	Read([]byte, int64) (int, error)

	// Write writes a byte array to the file.
	Write([]byte) (int, error)

	// Sync persists data.
	Sync() error

	// Close closes the file.
	Close() error

	// Size gets the file size.
	Size() (int64, error)
}

IOManager is an abstract IO management interface that can accommodate different IO types. Currently, it supports standard file IO.

func NewIOManager

func NewIOManager(filename string, fileSize int64, fioType int8) (IOManager, error)

NewIOManager get IOManager based on type

type MMapIO

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

func NewMMapIOManager

func NewMMapIOManager(fileName string, fileSize int64) (*MMapIO, error)

NewMMapIOManager Initialize Mmap IO

func (*MMapIO) Close

func (mio *MMapIO) Close() (err error)

Close file

func (*MMapIO) Read

func (mio *MMapIO) Read(b []byte, offset int64) (int, error)

Read Copy data from the mapping area to byte slice

func (*MMapIO) Size

func (mio *MMapIO) Size() (int64, error)

Size return the size of current file

func (*MMapIO) Sync

func (mio *MMapIO) Sync() error

Sync Synchronize data from memory to disk

func (*MMapIO) UnMap

func (mio *MMapIO) UnMap() error

UnMap Unmapping between memory and files

func (*MMapIO) Write

func (mio *MMapIO) Write(b []byte) (int, error)

Write Copy data from byte slice to the mapping area

Jump to

Keyboard shortcuts

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