file

package
v1.0.0-test.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FLock

type FLock interface {
	Lock(file *os.File) error   // 获取排他锁
	Unlock(file *os.File) error // 释放锁
}

FLock 接口定义了文件锁的基本操作

type FLocker

type FLocker struct{}

FLocker 实现了 Lock 接口,基于系统的 flock 实现

func NewFLocker

func NewFLocker() *FLocker

NewFLocker 创建一个新的 FLocker 实例

func (*FLocker) Lock

func (f *FLocker) Lock(file *os.File) error

Lock 获取排他锁(阻塞模式) 若文件已被锁定,当前调用会阻塞直到锁被释放

func (*FLocker) Unlock

func (f *FLocker) Unlock(file *os.File) error

Unlock 释放已获取的锁

type File

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

func OpenFile

func OpenFile(filePath string, lock FLock) (*File, error)

func (*File) Close

func (f *File) Close() error

func (*File) ReadAt

func (f *File) ReadAt(offset int64, data []byte) (int, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) WriteAt

func (f *File) WriteAt(offset int64, data []byte) (int, error)

Jump to

Keyboard shortcuts

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