Add SHA256File to get the checksum of a file #19
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Checking whether a downloaded file matches a published checksum, or whether two
files differ without comparing them byte by byte, needs a digest of the file's
contents, and the version people write in a hurry reads the whole file into
memory first, which falls over on anything large. Streaming it through the hash
is five lines that are worth having written once and tested.
Definition of done:
SHA256File(path string) (string, error)returns theSHA-256 digest of the file's contents as lowercase hexadecimal, reading the file
in chunks rather than all at once, and returns the underlying error if the file
cannot be opened or read. It has a doc comment and table-driven tests covering
an empty file, a short file, a file larger than one read buffer, binary
contents, and a path that does not exist.
Model: opus-5