{"modulePath":"github.com/git-lfs/gitobj","version":"v1.4.1","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package gitobj\n\n## Functions\n\n```go\nfunc NewFilesystemBackend(root, tmp string) (storage.Backend, error)\n```\nNewFilesystemBackend initializes a new filesystem-based backend.\n\n```go\nfunc NewFilesystemBackendWithAlternates(root, tmp, alternates string) (storage.Backend, error)\n```\nNewFilesystemBackendWithAlternates initializes a new filesystem-based backend, optionally with additional alternates as specified in the \\`alternates\\` variable. The syntax is that of the Git environment variable GIT\\_ALTERNATE\\_OBJECT\\_DIRECTORIES.\n\n```go\nfunc NewMemoryBackend(m map[string]io.ReadWriter) (storage.Backend, error)\n```\nNewMemoryBackend initializes a new memory-based backend.\n\nA value of \"nil\" is acceptable and indicates that no entries should be added to the memory backend at construction time.\n\n## Types\n\n```go\ntype Blob struct {\n\t// Size is the total uncompressed size of the blob's contents.\n\tSize int64\n\t// Contents is a reader that yields the uncompressed blob contents. It\n\t// may only be read once. It may or may not implement io.ReadSeeker.\n\tContents io.Reader\n\t// contains filtered or unexported fields\n}\n```\nBlob represents a Git object of type \"blob\".\n\n```go\nfunc NewBlobFromBytes(contents []byte) *Blob\n```\nNewBlobFromBytes returns a new \\*Blob that yields the data given.\n\n```go\nfunc NewBlobFromFile(path string) (*Blob, error)\n```\nNewBlobFromFile returns a new \\*Blob that contains the contents of the file at location \"path\" on disk. NewBlobFromFile does not read the file ahead of time, and instead defers this task until encoding the blob to the object database.\n\nIf the file cannot be opened or stat(1)-ed, an error will be returned.\n\nWhen the blob receives a function call Close(), the file will also be closed, and any error encountered in doing so will be returned from Close().\n\n```go\nfunc (b *Blob) Close() error\n```\nCloses closes any resources held by the open Blob, or returns nil if there were no errors.\n\n```go\nfunc (b *Blob) Decode(r io.Reader, size int64) (n int, err error)\n```\nDecode implements Object.Decode and decodes the uncompressed blob contents being read. It returns the number of bytes that it consumed off of the stream, which is always zero.\n\nIf any errors are encountered while reading the blob, they will be returned.\n\n```go\nfunc (b *Blob) Encode(to io.Writer) (n int, err error)\n```\nEncode encodes the blob's contents to the given io.Writer, \"w\". If there was any error copying the blob's contents, that error will be returned.\n\nOtherwise, the number of bytes written will be returned.\n\n```go\nfunc (b *Blob) Equal(other *Blob) bool\n```\nEqual returns whether the receiving and given blobs are equal, or in other words, whether they are represented by the same SHA-1 when saved to the object database.\n\n```go\nfunc (b *Blob) Type() ObjectType\n```\nType implements Object.ObjectType by returning the correct object type for Blobs, BlobObjectType.\n\n```go\ntype Commit struct {\n\t// Author is the Author this commit, or the original writer of the\n\t// contents.\n\t//\n\t// NOTE: this field is stored as a string to ensure any extra \"cruft\"\n\t// bytes are preserved through migration.\n\tAuthor string\n\t// Committer is the individual or entity that added this commit to the\n\t// history.\n\t//\n\t// NOTE: this field is stored as a string to ensure any extra \"cruft\"\n\t// bytes are preserved through migration.\n\tCommitter string\n\t// ParentIDs are the IDs of all parents for which this commit is a\n\t// linear child.\n\tParentIDs [][]byte\n\t// TreeID is the root Tree associated with this commit.\n\tTreeID []byte\n\t// ExtraHeaders stores headers not listed above, for instance\n\t// \"encoding\", \"gpgsig\", or \"mergetag\" (among others).\n\tExtraHeaders []*ExtraHeader\n\t// Message is the commit message, including any signing information\n\t// associated with this commit.\n\tMessage string\n}\n```\nCommit encapsulates a Git commit entry.\n\n```go\nfunc (c *Commit) Decode(from io.Reader, size int64) (n int, err error)\n```\nDecode implements Object.Decode and decodes the uncompressed commit being read. It returns the number of uncompressed bytes being consumed off of the stream, which should be strictly equal to the size given.\n\nIf any error was encountered along the way, that will be returned, along with the number of bytes read up to that point.\n\n```go\nfunc (c *Commit) Encode(to io.Writer) (n int, err error)\n```\nEncode encodes the commit's contents to the given io.Writer, \"w\". If there was any error copying the commit's contents, that error will be returned.\n\nOtherwise, the number of bytes written will be returned.\n\n```go\nfunc (c *Commit) Equal(other *Commit) bool\n```\nEqual returns whether the receiving and given commits are equal, or in other words, whether they are represented by the same SHA-1 when saved to the object database.\n\n```go\nfunc (c *Commit) Type() ObjectType\n```\nType implements Object.ObjectType by returning the correct object type for Commits, CommitObjectType.\n\n```go\ntype ExtraHeader struct {\n\t// K is the header key, or the first run of bytes up until a ' ' (\\x20)\n\t// character.\n\tK string\n\t// V is the header value, or the remaining run of bytes in the line,\n\t// stripping off the above \"K\" field as a prefix.\n\tV string\n}\n```\nExtraHeader encapsulates a key-value pairing of header key to header value. It is stored as a struct{string, string} in memory as opposed to a map\\[string]string to maintain ordering in a byte-for-byte encode/decode round trip.\n\n```go\ntype Object interface {\n\t// Encode takes an io.Writer, \"to\", and encodes an uncompressed\n\t// Git-compatible representation of itself to that stream.\n\t//\n\t// It must return \"n\", the number of uncompressed bytes written to that\n\t// stream, along with \"err\", any error that was encountered during the\n\t// write.\n\t//\n\t// Any error that was encountered should be treated as \"fatal-local\",\n\t// meaning that a particular invocation of Encode() cannot progress, and\n\t// an accurate number \"n\" of bytes written up that point should be\n\t// returned.\n\tEncode(to io.Writer) (n int, err error)\n\n\t// Decode takes an io.Reader, \"from\" as well as a size \"size\" (the\n\t// number of uncompressed bytes on the stream that represent the object\n\t// trying to be decoded) and decodes the encoded object onto itself,\n\t// as a mutative transaction.\n\t//\n\t// It returns the number of uncompressed bytes \"n\" that an invoication\n\t// of this function has advanced the io.Reader, \"from\", as well as any\n\t// error that was encountered along the way.\n\t//\n\t// If an(y) error was encountered, it should be returned immediately,\n\t// along with the number of bytes read up to that point.\n\tDecode(from io.Reader, size int64) (n int, err error)\n\n\t// Type returns the ObjectType constant that represents an instance of\n\t// the implementing type.\n\tType() ObjectType\n}\n```\nObject is an interface satisfied by any concrete type that represents a loose Git object.\n\n```go\ntype ObjectDatabase struct {\n\t// contains filtered or unexported fields\n}\n```\nObjectDatabase enables the reading and writing of objects against a storage backend.\n\n```go\nfunc FromBackend(b storage.Backend) (*ObjectDatabase, error)\n```\n\n```go\nfunc FromFilesystem(root, tmp string) (*ObjectDatabase, error)\n```\nFromFilesystem constructs an \\*ObjectDatabase instance that is backed by a directory on the filesystem. Specifically, this should point to:\n\n\t/absolute/repo/path/.git/objects\n\n```go\nfunc FromFilesystemWithAlternates(root, tmp, alternates string) (*ObjectDatabase, error)\n```\nFromFilesystemWithAlternates constructs an \\*ObjectDatabase instance that is backed by a directory on the filesystem, optionally with one or more alternates. Specifically, this should point to:\n\n\t/absolute/repo/path/.git/objects\n\n```go\nfunc (o *ObjectDatabase) Blob(sha []byte) (*Blob, error)\n```\nBlob returns a \\*Blob as identified by the SHA given, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) Close() error\n```\nClose closes the \\*ObjectDatabase, freeing any open resources (namely: the \\`\\*git.ObjectScanner instance), and returning any errors encountered in closing them.\n\nIf Close() has already been called, this function will return an error.\n\n```go\nfunc (o *ObjectDatabase) Commit(sha []byte) (*Commit, error)\n```\nCommit returns a \\*Commit as identified by the SHA given, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) Object(sha []byte) (Object, error)\n```\nObject returns an Object (of unknown implementation) satisfying the type associated with the object named \"sha\".\n\nIf the object could not be opened, is of unknown type, or could not be decoded, than an appropriate error is returned instead.\n\n```go\nfunc (o *ObjectDatabase) Root() (string, bool)\n```\nRoot returns the filesystem root that this \\*ObjectDatabase works within, if backed by a fileStorer (constructed by FromFilesystem). If so, it returns the fully-qualified path on a disk and a value of true.\n\nOtherwise, it returns empty-string and a value of false.\n\n```go\nfunc (o *ObjectDatabase) Tag(sha []byte) (*Tag, error)\n```\nTag returns a \\*Tag as identified by the SHA given, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) Tree(sha []byte) (*Tree, error)\n```\nTree returns a \\*Tree as identified by the SHA given, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) WriteBlob(b *Blob) ([]byte, error)\n```\nWriteBlob stores a \\*Blob on disk and returns the SHA it is uniquely identified by, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) WriteCommit(c *Commit) ([]byte, error)\n```\nWriteCommit stores a \\*Commit on disk and returns the SHA it is uniquely identified by, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) WriteTag(t *Tag) ([]byte, error)\n```\nWriteTag stores a \\*Tag on disk and returns the SHA it is uniquely identified by, or an error if one was encountered.\n\n```go\nfunc (o *ObjectDatabase) WriteTree(t *Tree) ([]byte, error)\n```\nWriteTree stores a \\*Tree on disk and returns the SHA it is uniquely identified by, or an error if one was encountered.\n\n```go\ntype ObjectReader struct {\n\t// contains filtered or unexported fields\n}\n```\nObjectReader provides an io.Reader implementation that can read Git object headers, as well as provide an uncompressed view into the object contents itself.\n\n```go\nfunc NewObjectReadCloser(r io.ReadCloser) (*ObjectReader, error)\n```\nNewObjectReadCloser takes a given io.Reader that yields zlib-compressed data, and returns an \\*ObjectReader wrapping it, or an error if one occurred during construction time.\n\nIt also calls the Close() function given by the implementation \"r\" of the type io.Closer.\n\n```go\nfunc NewObjectReader(r io.Reader) (*ObjectReader, error)\n```\nNewObjectReader takes a given io.Reader that yields zlib-compressed data, and returns an \\*ObjectReader wrapping it, or an error if one occurred during construction time.\n\n```go\nfunc NewUncompressedObjectReadCloser(r io.ReadCloser) (*ObjectReader, error)\n```\nNewUncompressObjectReadCloser takes a given io.Reader that yields uncompressed data, and returns an \\*ObjectReader wrapping it, or an error if one occurred during construction time.\n\nIt also calls the Close() function given by the implementation \"r\" of the type io.Closer.\n\n```go\nfunc NewUncompressedObjectReader(r io.Reader) (*ObjectReader, error)\n```\nNewObjectReader takes a given io.Reader that yields uncompressed data and returns an \\*ObjectReader wrapping it, or an error if one occurred during construction time.\n\n```go\nfunc (r *ObjectReader) Close() error\n```\nClose frees any resources held by the ObjectReader and must be called before disposing of this instance.\n\nIt returns any error encountered by the \\*ObjectReader during close.\n\n```go\nfunc (r *ObjectReader) Header() (typ ObjectType, size int64, err error)\n```\nHeader returns information about the Object's header, or an error if one occurred while reading the data.\n\nHeader information is cached, so this function is safe to call at any point during the object read, and can be called more than once.\n\n```go\nfunc (r *ObjectReader) Read(p []byte) (n int, err error)\n```\nRead reads uncompressed bytes into the buffer \"p\", and returns the number of uncompressed bytes read. Otherwise, it returns any error encountered along the way.\n\nThis function is safe to call before reading the Header information, as any call to Read() will ensure that read has been called at least once.\n\n```go\ntype ObjectType uint8\n```\nObjectType is a constant enumeration type for identifying the kind of object type an implementing instance of the Object interface is.\n\n```go\nconst (\n\tUnknownObjectType ObjectType = iota\n\tBlobObjectType\n\tTreeObjectType\n\tCommitObjectType\n\tTagObjectType\n)\n```\n\n```go\nfunc ObjectTypeFromString(s string) ObjectType\n```\nObjectTypeFromString converts from a given string to an ObjectType enumeration instance.\n\n```go\nfunc (t ObjectType) String() string\n```\nString implements the fmt.Stringer interface and returns a string representation of the ObjectType enumeration instance.\n\n```go\ntype ObjectWriter struct {\n\t// contains filtered or unexported fields\n}\n```\nObjectWriter provides an implementation of io.Writer that compresses and writes data given to it, and keeps track of the SHA1 hash of the data as it is written.\n\n```go\nfunc NewObjectWriteCloser(w io.WriteCloser) *ObjectWriter\n```\nNewObjectWriter returns a new \\*ObjectWriter instance that drains incoming writes into the io.Writer given, \"w\".\n\nUpon closing, it calls the given Close() function of the io.WriteCloser.\n\n```go\nfunc NewObjectWriter(w io.Writer) *ObjectWriter\n```\nNewObjectWriter returns a new \\*ObjectWriter instance that drains incoming writes into the io.Writer given, \"w\".\n\n```go\nfunc (w *ObjectWriter) Close() error\n```\nClose closes the ObjectWriter and frees any resources held by it, including flushing the zlib-compressed content to the underling writer. It must be called before discarding of the Writer instance.\n\nIf any error occurred while calling close, it will be returned immediately, otherwise nil.\n\n```go\nfunc (w *ObjectWriter) Sha() []byte\n```\nSha returns the in-progress SHA1 of the compressed object contents.\n\n```go\nfunc (w *ObjectWriter) Write(p []byte) (n int, err error)\n```\nWrite writes the given buffer \"p\" of uncompressed bytes into the underlying data-stream, returning the number of uncompressed bytes written, along with any error encountered along the way.\n\nA call to WriteHeaders MUST occur before calling Write, or a panic() will occur.\n\n```go\nfunc (w *ObjectWriter) WriteHeader(typ ObjectType, len int64) (n int, err error)\n```\nWriteHeader writes object header information and returns the number of uncompressed bytes written, or any error that was encountered along the way.\n\nWriteHeader MUST be called only once, or a panic() will occur.\n\n```go\ntype Signature struct {\n\t// Name is the first and last name of the individual holding this\n\t// signature.\n\tName string\n\t// Email is the email address of the individual holding this signature.\n\tEmail string\n\t// When is the instant in time when the signature was created.\n\tWhen time.Time\n}\n```\nSignature represents a commit signature, which can represent either committership or authorship of the commit that this signature belongs to. It specifies a name, email, and time that the signature was created.\n\nNOTE: this type is \\_not\\_ used by the \\`\\*Commit\\` instance, as it does not preserve cruft bytes. It is kept as a convenience type to test with.\n\n```go\nfunc (s *Signature) String() string\n```\nString implements the fmt.Stringer interface and formats a Signature as expected in the Git commit internal object format. For instance:\n\n\tTaylor Blau \u003cttaylorr@github.com\u003e 1494258422 -0600\n\n```go\ntype SubtreeOrder []*TreeEntry\n```\nSubtreeOrder is an implementation of sort.Interface that sorts a set of \\`\\*TreeEntry\\`'s according to \"subtree\" order. This ordering is required to write trees in a correct, readable format to the Git object database.\n\nThe format is as follows: entries are sorted lexicographically in byte-order, with subtrees (entries of Type() == gitobj.TreeObjectType) being sorted as if their \\`Name\\` fields ended in a \"/\".\n\nSee: [https://github.com/git/git/blob/v2.13.0/fsck.c#L492-L525](https://github.com/git/git/blob/v2.13.0/fsck.c#L492-L525) for more details.\n\n```go\nfunc (s SubtreeOrder) Len() int\n```\nLen implements sort.Interface.Len() and return the length of the underlying slice.\n\n```go\nfunc (s SubtreeOrder) Less(i, j int) bool\n```\nLess implements sort.Interface.Less() and returns whether the element at \"i\" is compared as \"less\" than the element at \"j\". In other words, it returns if the element at \"i\" should be sorted ahead of that at \"j\".\n\nIt performs this comparison in lexicographic byte-order according to the rules above (see SubtreeOrder).\n\n```go\nfunc (s SubtreeOrder) Name(i int) string\n```\nName returns the name for a given entry indexed at \"i\", which is a C-style string ('\\\\0' terminated unless it's a subtree), optionally terminated with '/' if it's a subtree.\n\nThis is done because '/' sorts ahead of '\\\\0', and is compatible with the tree order in upstream Git.\n\n```go\nfunc (s SubtreeOrder) Swap(i, j int)\n```\nSwap implements sort.Interface.Swap() and swaps the two elements at i and j.\n\n```go\ntype Tag struct {\n\tObject     []byte\n\tObjectType ObjectType\n\tName       string\n\tTagger     string\n\n\tMessage string\n}\n```\n\n```go\nfunc (t *Tag) Decode(r io.Reader, size int64) (int, error)\n```\nDecode implements Object.Decode and decodes the uncompressed tag being read. It returns the number of uncompressed bytes being consumed off of the stream, which should be strictly equal to the size given.\n\nIf any error was encountered along the way it will be returned, and the receiving \\*Tag is considered invalid.\n\n```go\nfunc (t *Tag) Encode(w io.Writer) (int, error)\n```\nEncode encodes the Tag's contents to the given io.Writer, \"w\". If there was any error copying the Tag's contents, that error will be returned.\n\nOtherwise, the number of bytes written will be returned.\n\n```go\nfunc (t *Tag) Equal(other *Tag) bool\n```\nEqual returns whether the receiving and given Tags are equal, or in other words, whether they are represented by the same SHA-1 when saved to the object database.\n\n```go\nfunc (t *Tag) Type() ObjectType\n```\nType implements Object.ObjectType by returning the correct object type for Tags, TagObjectType.\n\n```go\ntype Tree struct {\n\t// Entries is the list of entries held by this tree.\n\tEntries []*TreeEntry\n}\n```\nTree encapsulates a Git tree object.\n\n```go\nfunc (t *Tree) Decode(from io.Reader, size int64) (n int, err error)\n```\nDecode implements Object.Decode and decodes the uncompressed tree being read. It returns the number of uncompressed bytes being consumed off of the stream, which should be strictly equal to the size given.\n\nIf any error was encountered along the way, that will be returned, along with the number of bytes read up to that point.\n\n```go\nfunc (t *Tree) Encode(to io.Writer) (n int, err error)\n```\nEncode encodes the tree's contents to the given io.Writer, \"w\". If there was any error copying the tree's contents, that error will be returned.\n\nOtherwise, the number of bytes written will be returned.\n\n```go\nfunc (t *Tree) Equal(other *Tree) bool\n```\nEqual returns whether the receiving and given trees are equal, or in other words, whether they are represented by the same SHA-1 when saved to the object database.\n\n```go\nfunc (t *Tree) Merge(others ...*TreeEntry) *Tree\n```\nMerge performs a merge operation against the given set of \\`\\*TreeEntry\\`'s by either replacing existing tree entries of the same name, or appending new entries in sub-tree order.\n\nIt returns a copy of the tree, and performs the merge in O(n\\*log(n)) time.\n\n```go\nfunc (t *Tree) Type() ObjectType\n```\nType implements Object.ObjectType by returning the correct object type for Trees, TreeObjectType.\n\n```go\ntype TreeEntry struct {\n\t// Name is the entry name relative to the tree in which this entry is\n\t// contained.\n\tName string\n\t// Oid is the object ID for this tree entry.\n\tOid []byte\n\t// Filemode is the filemode of this tree entry on disk.\n\tFilemode int32\n}\n```\nTreeEntry encapsulates information about a single tree entry in a tree listing.\n\n```go\nfunc (e *TreeEntry) Equal(other *TreeEntry) bool\n```\nEqual returns whether the receiving and given TreeEntry instances are identical in name, filemode, and OID.\n\n```go\nfunc (e *TreeEntry) Type() ObjectType\n```\nType is the type of entry (either blob: BlobObjectType, or a sub-tree: TreeObjectType).\n\n```go\ntype UnexpectedObjectType struct {\n\t// Got was the object type requested.\n\tGot ObjectType\n\t// Wanted was the object type received.\n\tWanted ObjectType\n}\n```\nUnexpectedObjectType is an error type that represents a scenario where an object was requested of a given type \"Wanted\", and received as a different \\_other\\_ type, \"Wanted\".\n\n```go\nfunc (e *UnexpectedObjectType) Error() string\n```\nError implements the error.Error() function.\n\n","path":"github.com/git-lfs/gitobj","name":"gitobj","synopsis":"","isRedistributable":true}
