cache

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatTime added in v0.9.0

func FormatTime(t time.Time) string

func RoundTime added in v0.9.0

func RoundTime(t time.Time) time.Time

Both the client and the original patcher treat the modification time as a floating point number, and then rounding to 6 decimal places.

Because of imprecisions within floating point numbers, the original patch (and therefore client) expect a slightly incorrect nanoseconds value, thus causing a typically off-by-one rounding error.

For example, if a file has a modification time of 1729218809s + 315336400ns, the correctly rounded nanoscond value should be 315336000ns (1729218809.315336). Instead, the client considers the floating point time as 1729218809.3153365s, thus causing it to round the nanoseconds to 315337000ns (1729218809.315337) instead.

Types

type Cache

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

func New

func New(f *os.File, flush ...int) *Cache

Creates a new *Cache with an optional flush threshold. The provided *os.File is used as persistent storage for the cache's QuickCheck values. New does NOT parse and store the contents of the given file.

func Open

func Open(name string, flush ...int) (*Cache, error)

Creates a new *Cache with an optional flush threshold from the file specified by name. Open creates the file if it doesn't already exist.

If opening the file does not return an error, Open parses and stores the contents of that file. If an error occurs when reading the file, the file is immediately closed and that error is returned.

func (*Cache) Close

func (cache *Cache) Close() error

Flushes the cache's contents, if necessary, to the underlying *os.File, and then closes the file.

func (*Cache) Flush

func (cache *Cache) Flush() error

Writes the cache's contents, in it's entirety, to the underlying *os.File, and resets the cache's internal state.

func (*Cache) FlushThreshold

func (cache *Cache) FlushThreshold(threshold int)

func (*Cache) ForEach

func (cache *Cache) ForEach(f RangeFunc)

func (*Cache) Get

func (cache *Cache) Get(path string) (QuickCheck, bool)

Returns the QuickCheck value for the given path.

func (*Cache) Read

func (cache *Cache) Read(r io.Reader) error

Parses the contents of provided io.Reader and stores valid QuickCheck values into the cache. Read returns the first parse error that occurs or any error that is returned from the provided io.Reader. Valid QuickCheck values parsed prior to a parse error are still stored.

func (*Cache) Store

func (cache *Cache) Store(path string, stat os.FileInfo, info archive.Info) error

Sets the QuickCheck of the provided file to the given path as its key. The path is always passed through filepath.FromSlash before being stored.

If the number of changes (# modifications + # additions) >= the configured flush threshold, the cache's contents are flushed to underlying *os.File. The result of this flush is NOT guaranteed to be equivalent to calling Flush.

func (*Cache) WriteTo

func (cache *Cache) WriteTo(w io.Writer) (n int64, err error)

Writes the cache's contents to the provided writer.

type QuickCheck

type QuickCheck interface {
	Path() string
	ModTime() time.Time
	Size() int64
	Checksum() []byte

	Check(os.FileInfo, archive.Info) error
}

type RangeFunc

type RangeFunc = func(qc QuickCheck) bool

Jump to

Keyboard shortcuts

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