SHA256File returns the SHA-256 digest of a file's contents as lowercase
hexadecimal, copying the file through the hash in chunks so its size does not
matter. Comes with a doc comment and table-driven tests. (closes#19)
Model: opus-5
AtomicWriteFile writes to a temporary file in the same directory, flushes it,
sets the mode and renames it over the target, so a reader never sees a
half-written file and a failure leaves the old one untouched. Comes with a doc
comment and table-driven tests. (closes#17)
Model: opus-5
FileExists reports whether a path holds a regular file and DirExists whether it
holds a directory, both answering false for anything they cannot look at.
Comes with doc comments and table-driven tests. (closes#15)
Model: opus-5
RandomHexString returns the requested number of bytes from crypto/rand as
lowercase hexadecimal, so callers reaching for a token do not end up using the
predictable math/rand instead. Comes with a doc comment and table-driven tests.
(closes#13)
Model: opus-5
HumanBytes turns a byte count into a short string using powers of 1024, with
whole bytes below the first threshold and one decimal place above it. Comes
with a doc comment and table-driven tests. (closes#11)
Model: opus-5
Slugify lowercases text and keeps only ASCII letters and digits, turning every
run of other characters into a single hyphen with none left at either end.
Comes with a doc comment and table-driven tests. (closes#9)
Model: opus-5
CollapseWhitespace turns every run of whitespace into a single space and
trims the ends, so a block of text becomes one tidy line. Comes with a doc
comment and table-driven tests. (closes#7)
Model: opus-5
TruncateString returns at most the requested number of characters from the
start of a string, counting characters rather than bytes so a multi-byte
character is never cut in half. Comes with a doc comment and table-driven
tests. (closes#5)
Model: opus-5