#![warn(clippy::pedantic)]
#![allow(
clippy::cast_lossless,
clippy::cast_possible_truncation,
clippy::cast_possible_wrap,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::unreadable_literal
)]
#[cfg(not(any(
feature = "gif",
feature = "isobmff",
feature = "jpeg",
feature = "png",
feature = "riff"
)))]
compile_error!("At least one format feature must be enabled for this crate to be usable.");
mod error;
mod formats;
mod utils;
pub use error::Error;
pub use formats::*;
use std::io::{BufRead, Read, Seek, Write};
pub fn read_tags(src: &mut (impl Read + BufRead + Seek)) -> Result<Option<Vec<String>>, Error> {
if let Some(format) = identify_format(src)? {
src.seek(std::io::SeekFrom::Start(0))?;
let tags = match format {
#[cfg(feature = "gif")]
Format::Gif => gif::read_tags(src)?,
#[cfg(feature = "isobmff")]
Format::Isobmff => isobmff::read_tags(src)?,
#[cfg(feature = "jpeg")]
Format::Jpeg => jpeg::read_tags(src)?,
#[cfg(feature = "png")]
Format::Png => png::read_tags(src)?,
#[cfg(feature = "riff")]
Format::Riff => riff::read_tags(src)?,
};
Ok(Some(tags))
} else {
Ok(None)
}
}
pub fn write_tags(
src: &mut (impl Read + BufRead + Seek),
dest: &mut impl Write,
tags: impl IntoIterator<Item = impl AsRef<str>>,
) -> Result<Option<()>, Error> {
if let Some(format) = identify_format(src)? {
src.seek(std::io::SeekFrom::Start(0))?;
match format {
#[cfg(feature = "gif")]
Format::Gif => gif::write_tags(src, dest, tags)?,
#[cfg(feature = "isobmff")]
Format::Isobmff => isobmff::write_tags(src, dest, tags)?,
#[cfg(feature = "jpeg")]
Format::Jpeg => jpeg::write_tags(src, dest, tags)?,
#[cfg(feature = "png")]
Format::Png => png::write_tags(src, dest, tags)?,
#[cfg(feature = "riff")]
Format::Riff => riff::write_tags(src, dest, tags)?,
};
Ok(Some(()))
} else {
Ok(None)
}
}