file

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MmapFile

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

MmapFile 内存映射式文件操作,不支持并发操作

func NewMmapFile

func NewMmapFile(path string, mmSize int) (*MmapFile, error)

func OpenMmapFile

func OpenMmapFile(path string, mmSize int, flag int, perm os.FileMode, mapFlag int, lock bool) (*MmapFile, error)

OpenMmapFile 打开一个mmapfile path:文件路径,mmSize:映射区大小,flag:文件指定的flag, perm:创建文件的权限, mapFlag:映射时指定的flag, lock:是否锁定映射区

func (*MmapFile) Close

func (mf *MmapFile) Close() error

Close 关闭映射区并关闭底层文件

func (*MmapFile) Read

func (mf *MmapFile) Read(data []byte) (int, error)

Read 顺序读取数据到data,同普通文件Read

func (*MmapFile) ReadAt

func (mf *MmapFile) ReadAt(data []byte, offset int64) (int, error)

ReadAt 从offset处读取数据到data,同普通文件ReadAt

func (*MmapFile) Seek

func (mf *MmapFile) Seek(offset int64, whence int) (ret int64, err error)

Seek 设置读写偏移量 同普通文件Seek

func (*MmapFile) Size

func (mf *MmapFile) Size() int64

Size 获取文件的大小,因为使用的是mmap,故写入到映射区相当于写入到了os缓存区,此时调用的获取底层文件的size等同于操作普通文件一样

func (*MmapFile) Sync

func (mf *MmapFile) Sync() error

Sync 将数据刷新到磁盘 同普通文件Sync

func (*MmapFile) Truncate

func (mf *MmapFile) Truncate(size int64) error

Truncate 截断文件 同普通文件Truncate

func (*MmapFile) Write

func (mf *MmapFile) Write(data []byte) (int, error)

Write 追加写入数据 同普通文件Write

func (*MmapFile) WriteAt

func (mf *MmapFile) WriteAt(data []byte, offset int64) (int, error)

WriteAt 从offset处写入data数据,同普通文件WriteAt

type NormalFile

type NormalFile struct {
	*os.File
}

func NewFile

func NewFile(path string) (*NormalFile, error)

func OpenFile

func OpenFile(path string, flag int, perm os.FileMode) (*NormalFile, error)

func (*NormalFile) Size

func (fn *NormalFile) Size() int64

type WalFile

type WalFile interface {
	Write([]byte) (int, error)
	Read([]byte) (int, error)
	WriteAt(data []byte, offset int64) (int, error)
	ReadAt(data []byte, offset int64) (int, error)
	Size() int64
	Close() error
	Seek(offset int64, whence int) (ret int64, err error)
	Truncate(size int64) error
	Sync() error
}

Jump to

Keyboard shortcuts

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