Documentation ¶
Overview ¶
Package checksum provides functions for working with checksums. It uses crc32 for the checksum algorithm, resulting in checksum values like "3af3aaad".
Index ¶
- func Rand() string
- func Read(r io.Reader) (map[string]Checksum, error)
- func ReadFile(path string) (map[string]Checksum, error)
- func Sum(b []byte) string
- func SumAll[T ~string](a T, b ...T) string
- func Write(w io.Writer, sum Checksum, name string) error
- func WriteFile(path string, sum Checksum, name string) error
- type Checksum
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Read ¶
Read reads checksums lines from r, returning a map of checksums keyed by name. Empty lines, and lines beginning with "#" (comments) are ignored. This function is the inverse of Write.
Types ¶
type Checksum ¶
type Checksum string
Checksum is a checksum value.
func ForFile ¶
ForFile returns a checksum of the file at path. The checksum is based on the file's name, size, mode, and modification time. File contents are not read.
func ForHTTPHeader
deprecated
ForHTTPHeader returns a checksum generated from URL u and the contents of header. If the header contains an Etag, that is used as the primary element. Otherwise, other values such as Content-Length and Last-Modified are considered.
Deprecated: use ForHTTPResponse instead.
func ForHTTPResponse ¶
ForHTTPResponse returns a checksum generated from the response's request URL and the contents of the response's header. If the header contains an Etag, that is used as the primary element. Otherwise, other values such as Content-Length and Last-Modified are considered.
There's some trickiness with Etag. Note that by default, stdlib http.Client will set sneakily set the "Accept-Encoding: gzip" header on GET requests. However, this doesn't happen for HEAD requests. So, comparing a GET and HEAD response for the same URL may result in different checksums, because the server will likely return a different Etag for the gzipped response.
# With gzip Etag: "069dbf690a12d5eb853feb8e04aeb49e-ssl-df" # Without gzip Etag: "069dbf690a12d5eb853feb8e04aeb49e-ssl"
Note the "-ssl-df" suffix on the gzipped response. The "df" suffix is for "deflate".
The solution here might be to always explicitly set the gzip header on all requests. However, when gzip is not explicitly set, the stdlib client transparently handles gzip compression, including on the body read end. So, ideally, we wouldn't change that part, so that we don't have to code for both compressed and uncompressed responses.
Our hack for now it to trim the "-df" suffix from the Etag.
REVISIT: ForHTTPResponse is no longer used. It should be removed.