Documentation ¶
Index ¶
- func AppendNewline(s *string) string
- func AppendOrReplaceInFileMust(path string, toAppend string, delim string) bool
- func AppendOrReplaceInText(orig string, toAppend string, delim string) string
- func BrCompressData(d []byte, level int) ([]byte, error)
- func BrCompressDataBest(d []byte) ([]byte, error)
- func BrCompressDataDefault(d []byte) ([]byte, error)
- func BrCompressFile(dstPath string, path string, level int) error
- func BrCompressFileBest(dstPath string, path string) error
- func BrCompressFileDefault(dstPath string, path string) error
- func BrDecompressData(d []byte) ([]byte, error)
- func BrReadFile(path string) ([]byte, error)
- func Capitalize(s string) string
- func CloseNoError(f io.Closer)
- func CollapseMultipleNewlines(s string) string
- func CopyFile(dst string, src string) error
- func CreateZipFile(dst string, baseDir string, toZip ...string)
- func CreateZipWithDirContent(zipFilePath, dirToZip string) error
- func DataSha1Hex(d []byte) string
- func DirExists(path string) bool
- func ExpandTildeInPath(s string) string
- func ExtEqualFold(s string, ext string) bool
- func FileExists(path string) bool
- func FileLineCount(path string) (int, error)
- func FileSha1Hex(path string) (string, error)
- func FileSize(path string) int64
- func FormatDuration(d time.Duration) string
- func FormatSize(n int64) string
- func FsFileExists(fsys fs.FS, path string) bool
- func GetCallstack(skipFrames int) string
- func GetCallstackFrames(skipFrames int) []string
- func GetErr(errs ...error) error
- func GzipCompressData(d []byte) ([]byte, error)
- func GzipCompressFile(dstPath, srcPath string) error
- func GzipDecompressData(d []byte) ([]byte, error)
- func GzipReadFile(path string) ([]byte, error)
- func IsLinux() bool
- func IsMac() bool
- func IsWinOrMac() bool
- func IsWindows() bool
- func IterDir(dir string, cb func(path string, de fs.DirEntry) (bool, error)) error
- func IterReadDirFS(fsys fs.ReadDirFS, startDir string, cb func(string, fs.DirEntry) error) error
- func IterZipData(zipData []byte, cb func(f *zip.File, data []byte) error) error
- func IterZipReader(r *zip.Reader, cb func(f *zip.File, data []byte) error) error
- func MaybeSync(w io.Writer) error
- func MimeTypeFromFileName(path string) string
- func Must(err error)
- func Must2[T any](x T, err error) T
- func NormalizeNewlines(d []byte) []byte
- func NormalizeNewlinesInPlace(d []byte) []byte
- func OpenBrowser(url string)
- func OpenFileMaybeCompressed(path string) (io.ReadCloser, error)
- func PanicIf(cond bool, args ...interface{})
- func PanicIfErr(err error, args ...interface{})
- func ParseEnvMust(d []byte) map[string]string
- func PathExists(path string) bool
- func PathIsDir(path string) (isDir bool, err error)
- func Percent(total, sub int64) float64
- func PrintLineStats(stats *LineStats)
- func Push[S ~[]E, E any](s *S, els ...E)
- func ReadFileMaybeCompressed(path string) ([]byte, error)
- func ReadLines(filePath string) ([]string, error)
- func ReadLinesFromReader(r io.Reader) ([]string, error)
- func ReadZipData(zipData []byte) (map[string][]byte, error)
- func ReadZipFile(path string) (map[string][]byte, error)
- func ReadZipFileMust(path string) map[string][]byte
- func RunLoggedInDir(dir string, exe string, args ...string) error
- func RunLoggedInDirMust(dir string, exe string, args ...string)
- func RunLoggedMust(exe string, args ...string) string
- func RunMust(exe string, args ...string) string
- func SliceLimit[S ~[]E, E any](s S, max int) S
- func Slug(s string) string
- func SlugNoLowerCase(s string) string
- func ToTrimmedLines(d []byte) []string
- func TrimExt(s string) string
- func TrimPrefix(s string, prefix string) (string, bool)
- func UnzipDataToDir(zipData []byte, dir string) error
- func WinmergeDiffPreview()
- func WriteFileGzipped(path string, data []byte) error
- func ZipDir(dirToZip string) ([]byte, error)
- func ZipDirToWriter(w io.Writer, dirToZip string) error
- func ZstdCompressData(d []byte, level zstd.EncoderLevel) ([]byte, error)
- func ZstdCompressDataBest(d []byte) ([]byte, error)
- func ZstdCompressDataDefault(d []byte) ([]byte, error)
- func ZstdCompressFile(dst string, src string, level zstd.EncoderLevel) error
- func ZstdCompressFileBest(dst string, src string) error
- func ZstdCompressFileDefault(dst string, src string) error
- func ZstdDecompressData(d []byte) ([]byte, error)
- func ZstdReadFile(path string) ([]byte, error)
- type FilterFunc
- type FormattedDuration
- type LineCount
- type LineStats
- type MemoryFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendNewline ¶
func AppendOrReplaceInText ¶
func BrCompressDataBest ¶
func BrCompressDataDefault ¶
func BrCompressFileBest ¶
func BrCompressFileDefault ¶
func BrDecompressData ¶
func BrReadFile ¶
func CloseNoError ¶
CloseNoError is like io.Closer Close() but ignores an error use as: defer CloseNoError(f)
func CopyFile ¶
CopyFile copies a file from src to dst It'll create destination directory if necessary
func CreateZipFile ¶
toZip is a list of files and directories in baseDir Directories are added recursively
func CreateZipWithDirContent ¶
CreateZipWithDirContent creates a zip file with the content of a directory. The names of files inside the zip file are relatitve to dirToZip e.g. if dirToZip is foo and there is a file foo/bar.txt, the name in the zip will be bar.txt
func DataSha1Hex ¶
func ExpandTildeInPath ¶
func ExtEqualFold ¶
ExtEqualFold returns true if s ends with extension (e.g. ".html") case-insensitive
func FileExists ¶
FileExists returns true if path exists and is a regular file
func FileLineCount ¶
FileLineCount returns number of lines in a file
func FileSha1Hex ¶
func FormatDuration ¶
Formats duration in a more human friendly way than time.Duration.String()
func FormatSize ¶
FormatSize formats a number in a human-readable form e.g. 1.24 kB
func GetCallstack ¶
func GetCallstackFrames ¶
func GzipCompressData ¶
func GzipCompressFile ¶
func GzipDecompressData ¶
func GzipReadFile ¶
func IsWinOrMac ¶
func IsWinOrMac() bool
func IterReadDirFS ¶
call cb on each file in fsys startDir should be ". for root directory, "" and "/" do not work
func IterZipReader ¶
func MimeTypeFromFileName ¶
func NormalizeNewlines ¶
NormalizeNewlines is like NormalizeNewlinesInPlace but slower because it makes a copy of data
func NormalizeNewlinesInPlace ¶
NormalizeNewlinesInPlace changes CRLF (Windows) and CR (Mac) to LF (Unix) Optimized for speed, modifies data in place
func OpenBrowser ¶
func OpenBrowser(url string)
func OpenFileMaybeCompressed ¶
func OpenFileMaybeCompressed(path string) (io.ReadCloser, error)
OpenFileMaybeCompressed opens a file that might be compressed with gzip or bzip2 or zstd or brotli TODO: could sniff file content instead of checking file extension
func PanicIfErr ¶
func PanicIfErr(err error, args ...interface{})
func ParseEnvMust ¶
func PathIsDir ¶
PathIsDir returns true if a path exists and is a directory Returns false, nil if a path exists and is not a directory (e.g. a file) Returns undefined, error if there was an error e.g. because a path doesn't exists
func Percent ¶
Percent returns how many percent of total is sub 100% means total == sub, 50% means sub = total / 2
func PrintLineStats ¶
func PrintLineStats(stats *LineStats)
func ReadFileMaybeCompressed ¶
ReadFileMaybeCompressed reads file. Ungzips if it's gzipped.
func ReadLinesFromReader ¶
ReadLinesFromReader reads lines from io.Reader
func ReadZipFileMust ¶
func RunLoggedInDirMust ¶
func RunLoggedMust ¶
func SliceLimit ¶
func SlugNoLowerCase ¶
func ToTrimmedLines ¶
func TrimPrefix ¶
TrimPrefix is like strings.TrimPrefix but also returns a bool indicating that the string was trimmed
func UnzipDataToDir ¶
func WinmergeDiffPreview ¶
func WinmergeDiffPreview()
func WriteFileGzipped ¶
WriteFileGzipped writes data to a path, using best gzip compression
func ZstdCompressData ¶
func ZstdCompressData(d []byte, level zstd.EncoderLevel) ([]byte, error)
func ZstdCompressDataBest ¶
func ZstdCompressDataDefault ¶
func ZstdCompressFile ¶
func ZstdCompressFile(dst string, src string, level zstd.EncoderLevel) error
func ZstdCompressFileBest ¶
func ZstdCompressFileDefault ¶
func ZstdDecompressData ¶
func ZstdReadFile ¶
Types ¶
type FilterFunc ¶
func MakeAllowedFileFilterForExts ¶
func MakeAllowedFileFilterForExts(exts ...string) FilterFunc
func MakeExcludeDirsFilter ¶
func MakeExcludeDirsFilter(dirs ...string) FilterFunc
func MakeFilterAnd ¶
func MakeFilterAnd(filters ...FilterFunc) FilterFunc
func MakeFilterOr ¶
func MakeFilterOr(filters ...FilterFunc) FilterFunc
type FormattedDuration ¶
time.Duration with a better string representation
func (FormattedDuration) String ¶
func (d FormattedDuration) String() string
type MemoryFS ¶
type MemoryFS struct {
// contains filtered or unexported fields
}
MemoryFS is a custom file system that uses a map to store file data.