Add SHA256File to get the checksum of a file #19

Closed
opened 2026-09-05 05:31:03 +02:00 by clawbot · 0 comments
Contributor

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 the
SHA-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

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 the SHA-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
sneak closed this issue 2026-09-05 05:43:38 +02:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/util#19