Documentation
¶
Index ¶
- func ExpandPattern(pattern string, tokens map[string]string) string
- func HashFileSHA256(path string) (string, error)
- func HashReaderSHA256(r io.Reader) (string, error)
- func SafeFileName(name string) string
- func URLPathBase(u string) string
- func UniquePath(dir, base, versionHint string) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandPattern ¶
ExpandPattern replaces tokens in the form {token} with values from the map. Unknown tokens are left as-is. Nil or empty maps produce the original pattern.
func HashFileSHA256 ¶
HashFileSHA256 computes the SHA256 of a file in a streaming fashion using a 1 MiB buffer to reduce syscall overhead without large memory use.
func HashReaderSHA256 ¶
HashReaderSHA256 computes SHA256 from an io.Reader using a 1 MiB buffer.
func SafeFileName ¶
SafeFileName returns a conservative, cross-platform-safe filename. It trims spaces, preserves the extension, and replaces any rune not in [A-Za-z0-9._-] with '-'. It also collapses duplicate '-' and trims leading/trailing separators. Falls back to "download" when empty after cleaning.
func URLPathBase ¶
URLPathBase extracts the last element of the URL path, ignoring query and fragment. If parsing fails or the path is empty, it falls back to a reasonable default ("download").
func UniquePath ¶
UniquePath returns a unique path inside dir for the given base filename. If a file already exists, it first tries adding a version hint " (v<versionHint>)" before the extension (when versionHint != ""). Then it tries numeric suffixes " (2)", " (3)", etc., before the extension.
Types ¶
This section is empty.