util

package
v0.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandPattern

func ExpandPattern(pattern string, tokens map[string]string) string

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

func HashFileSHA256(path string) (string, error)

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

func HashReaderSHA256(r io.Reader) (string, error)

HashReaderSHA256 computes SHA256 from an io.Reader using a 1 MiB buffer.

func SafeFileName

func SafeFileName(name string) string

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

func URLPathBase(u string) string

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

func UniquePath(dir, base, versionHint string) (string, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL