objects

package
v0.0.0-...-00e3bd6 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(objpath, hash string) bool

Exists returns whether an object for a given hash exists in an object path. The hash must be lower case. Returns false if objpath is empty.

func HashFromETag

func HashFromETag(etag string) string

HashFromETag attempts to convert an ETag to a valid hash. Returns an empty string if the hash could not be converted.

func IsHash

func IsHash(s string) bool

IsHash returns whether the given string is a valid hash.

func Path

func Path(objpath, hash string) string

Path returns the file path for the object of a given hash. Returns an empty string if the hash is invalid or if objpath is empty.

func Stat

func Stat(objpath, hash string) os.FileInfo

Stat returns the file info for the object of a given hash. Returns nil if the object does not exist or if objpath is empty.

Types

type Writer

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

Writer writes an object.

func NewWriter

func NewWriter(objpath string) *Writer

NewWriter returns a new Writer. If objpath is empty, then nil is returned. Otherwise, an ObjectWriter is returned, which will write to a temporary file. The opening of the file is deferred to the first call to Write.

func (*Writer) AsWriter

func (w *Writer) AsWriter() io.Writer

AsWriter returns the ObjectWriter as an io.Writer, ensuring that a nil pointer results in a nil interface.

func (*Writer) Close

func (w *Writer) Close() (size int64, hash string, err error)

Close finishes writing the file. A hash of the written content is computed, and always returned. The size of the content is also always returned.

If successfully written, the file is moved to the objpath directory with the hash as the file name. The file is located under a subdirectory that is named after the first two characters of the hash. This subdirectory will be created if it does not exist.

hash: d41d8cd98f00b204e9800998ecf8427e
path: objects/d4/d41d8cd98f00b204e9800998ecf8427e

If an error occurs, the temporary file will persist. It can be removed with Remove().

func (*Writer) ExpectSize

func (w *Writer) ExpectSize(size int64)

ExpectSize sets the expected size of the file, which will be checked when the file is closed.

func (*Writer) Remove

func (w *Writer) Remove() error

Remove closes and removes the temporary file.

func (*Writer) Write

func (w *Writer) Write(b []byte) (n int, err error)

Write implements the io.Writer interface. The first call to Write will attempt to open a temporary file, which will then be written to until the writer is closed.

Jump to

Keyboard shortcuts

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