pub fn write_beside(folder: &Path, bytes: &[u8]) -> Result<PathBuf, String>Expand description
Writes an image beside music, or says why it did not.
The one place anything in this program puts a picture into somebody’s library, whether it was downloaded from the archive or pulled out of their own files. One function rather than two, because it carries two guards that would otherwise be written twice and eventually differ:
- the format is sniffed and the complete JPEG or static PNG is validated
before publication — see
write_image; - the target is checked immediately before writing, not when the caller chose it. A catalog is a snapshot and a disk is not, and this is the one moment in the program where being out of date destroys something the user made.
Never overwrites. There is no flag to make it.
And never adds a second cover to a folder that has one, whatever it is
called. Checking only the name about to be written is not enough: an
extracted cover.png and a downloaded cover.jpg are two different names
and both rank as the album’s cover, so a folder can end up holding two, with
no way to say which a player will show — and the one that wins may be the
1200 px download rather than the full-size picture that was in the files.
crate::scan::cover_in asks the question the scanner itself asks, at the
moment of writing, which is the only moment that can answer it.