{"modulePath":"github.com/2lambda123/git-lfs","version":"v2.5.2+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package tools\n\nPackage tools contains other helper functions too small to justify their own package NOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nSet is a modification of [https://github.com/deckarep/golang-set](https://github.com/deckarep/golang-set) The MIT License (MIT) Copyright (c) 2013 Ralph Caraveo (deckarep@gmail.com)\n\n## Constants\n\n```go\nconst (\n\tBtrfsIocClone = C.BTRFS_IOC_CLONE\n)\n```\n\n## Functions\n\n```go\nfunc ClampInt(n, min, max int) int\n```\nClampInt returns the integer \"n\" bounded between \"min\" and \"max\".\n\n```go\nfunc CleanPaths(paths, delim string) (cleaned []string)\n```\nCleanPaths splits the given \\`paths\\` argument by the delimiter argument, and then \"cleans\" that path according to the path.Clean function (see [https://golang.org/pkg/path#Clean](https://golang.org/pkg/path#Clean)). Note always cleans to '/' path separators regardless of platform (git friendly)\n\n```go\nfunc CloneFile(writer io.Writer, reader io.Reader) (bool, error)\n```\n\n```go\nfunc CopyWithCallback(writer io.Writer, reader io.Reader, totalSize int64, cb CopyCallback) (int64, error)\n```\nCopyWithCallback copies reader to writer while performing a progress callback\n\n```go\nfunc DirExists(path string) bool\n```\nDirExists determines if a dir (NOT file) exists.\n\n```go\nfunc FastWalkGitRepo(rootDir string, cb FastWalkCallback)\n```\nFastWalkGitRepo is a more optimal implementation of filepath.Walk for a Git repo. The callback guaranteed to be called sequentially. The function returns once all files and errors have triggered callbacks. It differs in the following ways:\n\n  - Uses goroutines to parallelise large dirs and descent into subdirs\n  - Does not provide sorted output; parents will always be before children but there are no other guarantees. Use parentDir argument in the callback to determine absolute path rather than tracking it yourself\n  - Automatically ignores any .git directories\n  - Respects .gitignore contents and skips ignored files/dirs\n\nrootDir - Absolute path to the top of the repository working directory\n\n```go\nfunc FileExists(path string) bool\n```\nFileExists determines if a file (NOT dir) exists.\n\n```go\nfunc FileExistsOfSize(path string, sz int64) bool\n```\nFileExistsOfSize determines if a file exists and is of a specific size.\n\n```go\nfunc FileOrDirExists(path string) (exists bool, isDir bool)\n```\nFileOrDirExists determines if a file/dir exists, returns IsDir() results too.\n\n```go\nfunc Getwd() (dir string, err error)\n```\n\n```go\nfunc Indent(str string) string\n```\nIndent returns a string which prepends \"\\\\t\" TAB characters to the beginning of each line in the given string \"str\".\n\n```go\nfunc IsExpiredAtOrIn(from time.Time, until time.Duration, at time.Time, in time.Duration) (time.Time, bool)\n```\nIsExpiredAtOrIn returns whether or not the result of calling TimeAtOrIn is \"expired\" within \"until\" units of time from now.\n\n```go\nfunc Ljust(strs []string) []string\n```\nLjust returns a copied string slice where each element is left justified to match the width of the longest element in the set.\n\n```go\nfunc Longest(strs []string) string\n```\nLongest returns the longest element in the string slice in O(n) time and O(1) space. If strs is empty or nil, an empty string will be returned.\n\n```go\nfunc MaxInt(a, b int) int\n```\nMaxInt returns the greater of two \\`int\\`s, \"a\", or \"b\".\n\n```go\nfunc MaxInt64(a, b int64) int64\n```\nMaxInt64 returns the greater of two \\`int\\`s, \"a\", or \"b\".\n\n```go\nfunc MinInt(a, b int) int\n```\nMinInt returns the smaller of two \\`int\\`s, \"a\", or \"b\".\n\n```go\nfunc MinInt64(a, b int64) int64\n```\nMinInt64 returns the smaller of two \\`int\\`s, \"a\", or \"b\".\n\n```go\nfunc NewLfsContentHash() hash.Hash\n```\nGet a new Hash instance of the type used to hash LFS content\n\n```go\nfunc NewRetriableReader(r io.Reader) io.Reader\n```\n\n```go\nfunc QuotedFields(s string) []string\n```\nQuotedFields is an alternative to strings.Fields (see: [https://golang.org/pkg/strings#Fields](https://golang.org/pkg/strings#Fields)) that respects spaces between matching pairs of quotation delimeters.\n\nFor instance, the quoted fields of the string \"foo bar 'baz etc'\" would be:\n\n\t[]string{\"foo\", \"bar\", \"baz etc\"}\n\nWhereas the same argument given to strings.Fields, would return:\n\n\t[]string{\"foo\", \"bar\", \"'baz\", \"etc'\"}\n\n```go\nfunc RenameFileCopyPermissions(srcfile, destfile string) error\n```\nRenameFileCopyPermissions moves srcfile to destfile, replacing destfile if necessary and also copying the permissions of destfile if it already exists\n\n```go\nfunc ResolveSymlinks(path string) string\n```\nResolveSymlinks ensures that if the path supplied is a symlink, it is resolved to the actual concrete path\n\n```go\nfunc Rjust(strs []string) []string\n```\nRjust returns a copied string slice where each element is right justified to match the width of the longest element in the set.\n\n```go\nfunc SetFileWriteFlag(path string, writeEnabled bool) error\n```\nSetFileWriteFlag changes write permissions on a file Used to make a file read-only or not. When writeEnabled = false, the write bit is removed for all roles. When writeEnabled = true, the behaviour is different per platform: On Mac \u0026 Linux, the write bit is set only on the owner as per default umask. All other bits are unaffected. On Windows, all the write bits are set since Windows doesn't support Unix permissions.\n\n```go\nfunc Spool(to io.Writer, from io.Reader, dir string) (n int64, err error)\n```\nSpool spools the contents from 'from' to 'to' by buffering the entire contents of 'from' into a temprorary file created in the directory \"dir\". That buffer is held in memory until the file grows to larger than 'memoryBufferLimit\\`, then the remaining contents are spooled to disk.\n\nThe temporary file is cleaned up after the copy is complete.\n\nThe number of bytes written to \"to\", as well as any error encountered are returned.\n\n```go\nfunc TimeAtOrIn(from, at time.Time, in time.Duration) time.Time\n```\nTimeAtOrIn returns either \"at\", or the \"in\" duration added to the current time. TimeAtOrIn prefers to add a duration rather than return the \"at\" parameter.\n\n```go\nfunc TranslateCygwinPath(path string) (string, error)\n```\n\n```go\nfunc Undent(str string) string\n```\nUndent removes all leading tabs in the given string \"str\", line-wise.\n\n```go\nfunc VerifyFileHash(oid, path string) error\n```\nVerifyFileHash reads a file and verifies whether the SHA is correct Returns an error if there is a problem\n\n## Types\n\n```go\ntype BaseChannelWrapper struct {\n\t// contains filtered or unexported fields\n}\n```\nBase implementation of channel wrapper to just deal with errors\n\n```go\nfunc NewBaseChannelWrapper(errChan \u003c-chan error) *BaseChannelWrapper\n```\n\n```go\nfunc (w *BaseChannelWrapper) Wait() error\n```\n\n```go\ntype BodyWithCallback struct {\n\tReadSeekCloser\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewBodyWithCallback(body ReadSeekCloser, totalSize int64, cb CopyCallback) *BodyWithCallback\n```\n\n```go\nfunc NewByteBodyWithCallback(by []byte, totalSize int64, cb CopyCallback) *BodyWithCallback\n```\n\n```go\nfunc (r *BodyWithCallback) Read(p []byte) (int, error)\n```\nRead wraps the underlying Reader's \"Read\" method. It also captures the number of bytes read, and calls the callback.\n\n```go\nfunc (r *BodyWithCallback) ResetProgress() error\n```\nResetProgress calls the callback with a negative read size equal to the total number of bytes read so far, effectively \"resetting\" the progress.\n\n```go\nfunc (r *BodyWithCallback) Seek(offset int64, whence int) (int64, error)\n```\nSeek wraps the underlying Seeker's \"Seek\" method, updating the number of bytes that have been consumed by this reader.\n\n```go\ntype CallbackReader struct {\n\tC         CopyCallback\n\tTotalSize int64\n\tReadSize  int64\n\tio.Reader\n}\n```\n\n```go\nfunc (w *CallbackReader) Read(p []byte) (int, error)\n```\n\n```go\ntype ChannelWrapper interface {\n\t// Call this after processing results channel to check for async errors\n\tWait() error\n}\n```\nInterface for all types of wrapper around a channel of results and an error channel Implementors will expose a type-specific channel for results Call the Wait() function after processing the results channel to catch any errors that occurred during the async processing\n\n```go\ntype CopyCallback func(totalSize int64, readSoFar int64, readSinceLast int) error\n```\n\n```go\ntype FastWalkCallback func(parentDir string, info os.FileInfo, err error)\n```\nFastWalkCallback is the signature for the callback given to FastWalkGitRepo()\n\n```go\ntype HashingReader struct {\n\t// contains filtered or unexported fields\n}\n```\nHashingReader wraps a reader and calculates the hash of the data as it is read\n\n```go\nfunc NewHashingReader(r io.Reader) *HashingReader\n```\n\n```go\nfunc NewHashingReaderPreloadHash(r io.Reader, hash hash.Hash) *HashingReader\n```\n\n```go\nfunc (r *HashingReader) Hash() string\n```\n\n```go\nfunc (r *HashingReader) Read(b []byte) (int, error)\n```\n\n```go\ntype OrderedSet struct {\n\t// contains filtered or unexported fields\n}\n```\nOrderedSet is a unique set of strings that maintains insertion order.\n\n```go\nfunc NewOrderedSet() *OrderedSet\n```\nNewOrderedSet creates an ordered set with no values.\n\n```go\nfunc NewOrderedSetFromSlice(s []string) *OrderedSet\n```\nNewOrderedSetFromSlice returns a new ordered set with the elements given in the slice \"s\".\n\n```go\nfunc NewOrderedSetWithCapacity(capacity int) *OrderedSet\n```\nNewOrderedSetWithCapacity creates a new ordered set with no values. The returned ordered set can be appended to \"capacity\" number of times before it grows internally.\n\n```go\nfunc (s *OrderedSet) Add(i string) bool\n```\nAdd adds the given element \"i\" to the ordered set, unless the element is already present. It returns whether or not the element was added.\n\n```go\nfunc (s *OrderedSet) Cardinality() int\n```\nCardinality returns the cardinality of this set.\n\n```go\nfunc (s *OrderedSet) Clear()\n```\nClear removes all elements from this set.\n\n```go\nfunc (s *OrderedSet) Clone() *OrderedSet\n```\nClone returns a deep copy of this set.\n\n```go\nfunc (s *OrderedSet) Contains(i string) bool\n```\nContains returns whether or not the given \"i\" is contained in this ordered set. It is a constant-time operation.\n\n```go\nfunc (s *OrderedSet) ContainsAll(i ...string) bool\n```\nContainsAll returns whether or not all of the given items in \"i\" are present in the ordered set.\n\n```go\nfunc (s *OrderedSet) Difference(other *OrderedSet) *OrderedSet\n```\nDifference returns the elements that are in this set, but not included in other.\n\n```go\nfunc (s *OrderedSet) Equal(other *OrderedSet) bool\n```\nEqual returns whether this element has the same number, identity and ordering elements as given in \"other\".\n\n```go\nfunc (s *OrderedSet) Intersect(other *OrderedSet) *OrderedSet\n```\nIntersect returns the elements that are in both this set and then given \"ordered\" set. It is an O(min(n, m)) (in other words, O(n)) operation.\n\n```go\nfunc (s *OrderedSet) IsSubset(other *OrderedSet) bool\n```\nIsSubset returns whether other is a subset of this ordered set. In other words, it returns whether or not all of the elements in \"other\" are also present in this set.\n\n```go\nfunc (s *OrderedSet) IsSuperset(other *OrderedSet) bool\n```\nIsSuperset returns whether or not this set is a superset of \"other\". In other words, it returns whether or not all of the elements in this set are also in the set \"other\".\n\n```go\nfunc (s *OrderedSet) Iter() \u003c-chan string\n```\nIter returns a channel which yields the elements in this set in insertion order.\n\n```go\nfunc (s *OrderedSet) Remove(i string)\n```\nRemove removes the given element \"i\" from this set.\n\n```go\nfunc (s *OrderedSet) SymmetricDifference(other *OrderedSet) *OrderedSet\n```\nSymmetricDifference returns the elements that are not present in both sets.\n\n```go\nfunc (s *OrderedSet) Union(other *OrderedSet) *OrderedSet\n```\nUnion returns a union of this set with the given set \"other\". It returns the items that are in either set while maintaining uniqueness constraints. It preserves ordered within each set, and orders the elements in this set before the elements in \"other\".\n\nIt is an O(n+m) operation.\n\n```go\ntype ReadSeekCloser interface {\n\tio.Seeker\n\tio.ReadCloser\n}\n```\nprevent import cycle\n\n```go\nfunc NewByteBody(by []byte) ReadSeekCloser\n```\n\n```go\ntype RetriableReader struct {\n\t// contains filtered or unexported fields\n}\n```\nRetriableReader wraps a error response of reader as RetriableError()\n\n```go\nfunc (r *RetriableReader) Read(b []byte) (int, error)\n```\n\n```go\ntype StringSet map[string]struct{}\n```\nThe primary type that represents a set\n\n```go\nfunc NewStringSet() StringSet\n```\nCreates and returns a reference to an empty set.\n\n```go\nfunc NewStringSetFromSlice(s []string) StringSet\n```\nCreates and returns a reference to a set from an existing slice\n\n```go\nfunc NewStringSetWithCapacity(capacity int) StringSet\n```\nCreates and returns a reference to an empty set with a capacity.\n\n```go\nfunc (set StringSet) Add(i string) bool\n```\nAdds an item to the current set if it doesn't already exist in the set.\n\n```go\nfunc (set StringSet) Cardinality() int\n```\nCardinality returns how many items are currently in the set.\n\n```go\nfunc (set *StringSet) Clear()\n```\nClears the entire set to be the empty set.\n\n```go\nfunc (set StringSet) Clone() StringSet\n```\nReturns a clone of the set. Does NOT clone the underlying elements.\n\n```go\nfunc (set StringSet) Contains(i string) bool\n```\nDetermines if a given item is already in the set.\n\n```go\nfunc (set StringSet) ContainsAll(i ...string) bool\n```\nDetermines if the given items are all in the set\n\n```go\nfunc (set StringSet) Difference(other StringSet) StringSet\n```\nReturns a new set with items in the current set but not in the other set\n\n```go\nfunc (set StringSet) Equal(other StringSet) bool\n```\nEqual determines if two sets are equal to each other. If they both are the same size and have the same items they are considered equal. Order of items is not relevent for sets to be equal.\n\n```go\nfunc (set StringSet) Intersect(other StringSet) StringSet\n```\nReturns a new set with items that exist only in both sets.\n\n```go\nfunc (set StringSet) IsSubset(other StringSet) bool\n```\nDetermines if every item in the other set is in this set.\n\n```go\nfunc (set StringSet) IsSuperset(other StringSet) bool\n```\nDetermines if every item of this set is in the other set.\n\n```go\nfunc (set StringSet) Iter() \u003c-chan string\n```\nIter() returns a channel of type string that you can range over.\n\n```go\nfunc (set StringSet) Remove(i string)\n```\nAllows the removal of a single item in the set.\n\n```go\nfunc (set StringSet) SymmetricDifference(other StringSet) StringSet\n```\nReturns a new set with items in the current set or the other set but not in both.\n\n```go\nfunc (set StringSet) Union(other StringSet) StringSet\n```\nReturns a new set with all items in both sets.\n\n```go\ntype SyncWriter struct {\n\t// contains filtered or unexported fields\n}\n```\nSyncWriter provides a wrapper around an io.Writer that synchronizes all write after they occur, if the underlying writer supports synchronization.\n\n```go\nfunc NewSyncWriter(w io.Writer) *SyncWriter\n```\nNewSyncWriter returns a new instance of the \\*SyncWriter that sends all writes to the given io.Writer.\n\n```go\nfunc (w *SyncWriter) Close() error\n```\nClose will call Close() on the underlying file\n\n```go\nfunc (w *SyncWriter) Write(b []byte) error\n```\nWrite will write to the file and perform a Sync() if writing succeeds.\n\n","path":"github.com/2lambda123/git-lfs/tools","name":"tools","synopsis":"Package tools contains other helper functions too small to justify their own package NOTE: Subject to change, do not rely on this package from outside git-lfs source","isRedistributable":true}
