file

package
v0.0.0-...-6dfdce2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHashCheck = errors.New("hash check failed")
View Source
var ErrWriteAfterEnd = errors.New("writing after end of file")

Functions

This section is empty.

Types

type File

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

A File used as a persistent data store. This attempts to guard against some of the pitfalls in reliably writing to a disk.

func Open

func Open(path string) (*File, error)

Open a file for reading and possibly writing.

func (*File) Begin

func (f *File) Begin() (*Tx, error)

Begin writing to the file.

func (*File) Close

func (f *File) Close() error

func (*File) ReadAt

func (f *File) ReadAt(buf []byte, pos int64) (int, error)

ReadAt reads from the file at the given location.

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

Size returns the current size of the file.

func (*File) WriteAt

func (f *File) WriteAt(buf []byte, pos int64) (int, error)

WriteAt opens a transaction, writes the data, and then commits the transaction.

type Tx

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

Tx represents a transaction of changes applied to a file. A given file may only have one transaction open at any given time.

func (*Tx) Close

func (f *Tx) Close() error

func (*Tx) Commit

func (f *Tx) Commit() error

Commit writes all of the staged changes into the file in such a way that if the process is interrupted, the file can be restored to a known-good state.

func (*Tx) Truncate

func (f *Tx) Truncate(size int64) error

Truncate statges a change to the size of the file.

func (*Tx) WriteAt

func (f *Tx) WriteAt(buf []byte, pos int64) (int, error)

WriteAt stages a change to the file.

Jump to

Keyboard shortcuts

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