Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = errors.New("file already exists")
ErrAlreadyExists is returned by Fetch when a file with the same name already exists in the download directory.
var ErrDuplicateContent = errors.New("duplicate content")
ErrDuplicateContent is returned by Fetch when the downloaded content has a SHA-256 hash that matches an existing file in the download directory.
Functions ¶
func BuildHashIndex ¶
BuildHashIndex scans dir for image files (.jpg, .jpeg, .png, .webp) and returns a map of hex-encoded SHA-256 hashes to true.
func InvalidateSkwdCache ¶
func InvalidateSkwdCache(path string)
InvalidateSkwdCache removes the skwd checksum file at path. If the file does not exist the call is a no-op.
Types ¶
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader manages downloading wallpapers to a directory with deduplication.
func New ¶
func New(dir string, hashIndex map[string]bool) *Downloader
New creates a Downloader that saves files to dir. hashIndex is the set of known SHA-256 hashes (hex-encoded) already present in dir; callers should build it with BuildHashIndex.
func (*Downloader) Fetch ¶
func (d *Downloader) Fetch(result source.WallpaperResult) (string, error)
Fetch downloads the wallpaper described by result into the Downloader's directory. It returns the path to the saved file. The following sentinel errors may be returned:
- ErrAlreadyExists: a file with the same name already exists.
- ErrDuplicateContent: the downloaded bytes match an existing file's hash.