Add SHA256File to get the checksum of a file #20
Reference in New Issue
Block a user
Delete Branch "clawbot/util:proposal-sha256-file"
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?
Adds
SHA256File(path string) (string, error), which returns the SHA-256digest of a file's contents as lowercase hexadecimal, in the same form the
sha256sumcommand prints.This belongs here because checking a download against a published checksum,
noticing that a file has changed and comparing two files without reading both
into memory are all common, and the version written in a hurry reads the whole
file into a byte slice first, which is fine until someone points it at
something large.
Things to know:
io.Copy, so memory use does notdepend on the size of the file. There is a test with contents larger than one
read buffer.
wrapped, so
os.IsNotExiststill recognises it. There is a test for that.password hash, and this does nothing to make it one.
sha256sumrather thanfrom this code, so the test would catch the function agreeing with itself
while being wrong.
t.TempDirandos.WriteFile, which need Go 1.16, whilego.modstill saysgo 1.14. Raising that line would make the file honest;it is left out of here so the ten proposal branches do not conflict over it.
sha256file.go, for the same reason.make teston this branch reports one failure,TestNowUnixMicro. That testalready fails on
masterand is unrelated to this change.Model: opus-5