WAV: Properly capitalize RIFFInfoList

This commit is contained in:
Serial 2022-06-26 11:51:52 -04:00
parent 5a30964228
commit f8b011bbba
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
10 changed files with 37 additions and 36 deletions

View file

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **MP4**: `Ilst::track_number` has been moved to the `Accessor::track` implementation
- **Tag**: Renamed `Tag::get_texts` to `Tag::get_strings`
- **AIFF**: Renamed `AiffTextChunks` -> `AIFFTextChunks`
- **WAV**: Renamed `RiffInfoList` -> `RIFFInfoList`
### Fixed
- **AIFF**: Fixed division by zero panic during property reading ([issue](https://github.com/Serial-ATA/lofty-rs/issues/56))

View file

@ -1,7 +1,7 @@
use lofty::ape::ApeTag;
use lofty::id3::v1::ID3v1Tag;
use lofty::id3::v2::ID3v2Tag;
use lofty::iff::{AIFFTextChunks, RiffInfoList};
use lofty::iff::{AIFFTextChunks, RIFFInfoList};
use lofty::mp4::Ilst;
use lofty::ogg::VorbisComments;
use lofty::{Accessor, TagExt};
@ -27,7 +27,7 @@ bench_tag_write!(ape, ApeTag);
bench_tag_write!(id3v2, ID3v2Tag);
bench_tag_write!(id3v1, ID3v1Tag);
bench_tag_write!(ilst, Ilst);
bench_tag_write!(riff_info, RiffInfoList);
bench_tag_write!(riff_info, RIFFInfoList);
bench_tag_write!(vorbis_comments, VorbisComments);
fn bench_write(c: &mut Criterion) {

View file

@ -17,6 +17,6 @@ cfg_if::cfg_if! {
cfg_if::cfg_if! {
if #[cfg(feature = "riff_info_list")] {
pub use wav::tag::RiffInfoList;
pub use wav::tag::RIFFInfoList;
}
}

View file

@ -14,7 +14,7 @@ use std::io::{Read, Seek};
cfg_if::cfg_if! {
if #[cfg(feature = "riff_info_list")] {
pub(crate) mod tag;
use tag::RiffInfoList;
use tag::RIFFInfoList;
}
}
@ -25,7 +25,7 @@ pub use crate::iff::wav::properties::{WavFormat, WavProperties};
pub struct WavFile {
#[cfg(feature = "riff_info_list")]
/// A RIFF INFO LIST
pub(crate) riff_info: Option<RiffInfoList>,
pub(crate) riff_info: Option<RIFFInfoList>,
#[cfg(feature = "id3v2")]
/// An ID3v2 tag
pub(crate) id3v2_tag: Option<ID3v2Tag>,
@ -94,6 +94,6 @@ impl WavFile {
id3v2_tag, ID3v2Tag;
#[cfg(feature = "riff_info_list")]
riff_info, RiffInfoList
riff_info, RIFFInfoList
}
}

View file

@ -1,6 +1,6 @@
use super::properties::WavProperties;
#[cfg(feature = "riff_info_list")]
use super::tag::RiffInfoList;
use super::tag::RIFFInfoList;
use super::WavFile;
use crate::error::{FileDecodingError, Result};
use crate::file::FileType;
@ -47,7 +47,7 @@ where
let mut fmt = Vec::new();
#[cfg(feature = "riff_info_list")]
let mut riff_info = RiffInfoList::default();
let mut riff_info = RIFFInfoList::default();
#[cfg(feature = "id3v2")]
let mut id3v2_tag: Option<ID3v2Tag> = None;

View file

@ -45,12 +45,12 @@ macro_rules! impl_accessor {
///
/// * The [`TagItem`] has a value other than [`ItemValue::Binary`](crate::ItemValue::Binary)
/// * It has a key that is 4 bytes in length and within the ASCII range
pub struct RiffInfoList {
pub struct RIFFInfoList {
/// A collection of chunk-value pairs
pub(crate) items: Vec<(String, String)>,
}
impl RiffInfoList {
impl RIFFInfoList {
/// Get an item by key
pub fn get(&self, key: &str) -> Option<&str> {
self.items
@ -90,7 +90,7 @@ impl RiffInfoList {
}
}
impl Accessor for RiffInfoList {
impl Accessor for RIFFInfoList {
impl_accessor!(
artist => "IART";
title => "INAM";
@ -132,7 +132,7 @@ impl Accessor for RiffInfoList {
}
}
impl TagExt for RiffInfoList {
impl TagExt for RIFFInfoList {
type Err = LoftyError;
fn is_empty(&self) -> bool {
@ -144,12 +144,12 @@ impl TagExt for RiffInfoList {
}
fn save_to(&self, file: &mut File) -> std::result::Result<(), Self::Err> {
RiffInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
RIFFInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
.write_to(file)
}
fn dump_to<W: Write>(&self, writer: &mut W) -> std::result::Result<(), Self::Err> {
RiffInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
RIFFInfoListRef::new(self.items.iter().map(|(k, v)| (k.as_str(), v.as_str())))
.dump_to(writer)
}
@ -166,8 +166,8 @@ impl TagExt for RiffInfoList {
}
}
impl From<RiffInfoList> for Tag {
fn from(input: RiffInfoList) -> Self {
impl From<RIFFInfoList> for Tag {
fn from(input: RIFFInfoList) -> Self {
let mut tag = Tag::new(TagType::RIFFInfo);
for (k, v) in input.items {
@ -183,9 +183,9 @@ impl From<RiffInfoList> for Tag {
}
}
impl From<Tag> for RiffInfoList {
impl From<Tag> for RIFFInfoList {
fn from(input: Tag) -> Self {
let mut riff_info = RiffInfoList::default();
let mut riff_info = RIFFInfoList::default();
for item in input.items {
if let ItemValue::Text(val) | ItemValue::Locator(val) = item.item_value {
@ -208,19 +208,19 @@ impl From<Tag> for RiffInfoList {
}
}
pub(crate) struct RiffInfoListRef<'a, I>
pub(crate) struct RIFFInfoListRef<'a, I>
where
I: Iterator<Item = (&'a str, &'a str)>,
{
pub(crate) items: I,
}
impl<'a, I> RiffInfoListRef<'a, I>
impl<'a, I> RIFFInfoListRef<'a, I>
where
I: Iterator<Item = (&'a str, &'a str)>,
{
pub(crate) fn new(items: I) -> RiffInfoListRef<'a, I> {
RiffInfoListRef { items }
pub(crate) fn new(items: I) -> RIFFInfoListRef<'a, I> {
RIFFInfoListRef { items }
}
pub(crate) fn write_to(&mut self, file: &mut File) -> Result<()> {
@ -254,7 +254,7 @@ pub(crate) fn tagitems_into_riff(items: &[TagItem]) -> impl Iterator<Item = (&st
#[cfg(test)]
mod tests {
use crate::iff::RiffInfoList;
use crate::iff::RIFFInfoList;
use crate::{Tag, TagExt, TagType};
use crate::iff::chunk::Chunks;
@ -263,7 +263,7 @@ mod tests {
#[test]
fn parse_riff_info() {
let mut expected_tag = RiffInfoList::default();
let mut expected_tag = RIFFInfoList::default();
expected_tag.insert(String::from("IART"), String::from("Bar artist"));
expected_tag.insert(String::from("ICMT"), String::from("Qux comment"));
@ -273,7 +273,7 @@ mod tests {
expected_tag.insert(String::from("IPRT"), String::from("1"));
let tag = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
let mut parsed_tag = RiffInfoList::default();
let mut parsed_tag = RIFFInfoList::default();
super::read::parse_riff_info(
&mut Cursor::new(&tag[..]),
@ -289,7 +289,7 @@ mod tests {
#[test]
fn riff_info_re_read() {
let tag = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
let mut parsed_tag = RiffInfoList::default();
let mut parsed_tag = RIFFInfoList::default();
super::read::parse_riff_info(
&mut Cursor::new(&tag[..]),
@ -302,7 +302,7 @@ mod tests {
let mut writer = Vec::new();
parsed_tag.dump_to(&mut writer).unwrap();
let mut temp_parsed_tag = RiffInfoList::default();
let mut temp_parsed_tag = RIFFInfoList::default();
// Remove the LIST....INFO from the tag
super::read::parse_riff_info(
@ -321,7 +321,7 @@ mod tests {
let tag_bytes = crate::tag::utils::test_utils::read_path("tests/tags/assets/test.riff");
let mut reader = std::io::Cursor::new(&tag_bytes[..]);
let mut riff_info = RiffInfoList::default();
let mut riff_info = RIFFInfoList::default();
super::read::parse_riff_info(
&mut reader,
@ -340,7 +340,7 @@ mod tests {
fn tag_to_riff_info() {
let tag = crate::tag::utils::test_utils::create_tag(TagType::RIFFInfo);
let riff_info: RiffInfoList = tag.into();
let riff_info: RIFFInfoList = tag.into();
assert_eq!(riff_info.get("INAM"), Some("Foo title"));
assert_eq!(riff_info.get("IART"), Some("Bar artist"));

View file

@ -1,4 +1,4 @@
use super::RiffInfoList;
use super::RIFFInfoList;
use crate::error::{FileDecodingError, Result};
use crate::file::FileType;
use crate::iff::chunk::Chunks;
@ -11,7 +11,7 @@ pub(in crate::iff::wav) fn parse_riff_info<R>(
data: &mut R,
chunks: &mut Chunks<LittleEndian>,
end: u64,
tag: &mut RiffInfoList,
tag: &mut RIFFInfoList,
) -> Result<()>
where
R: Read + Seek,

View file

@ -1,4 +1,4 @@
use super::RiffInfoListRef;
use super::RIFFInfoListRef;
use crate::error::{ErrorKind, LoftyError, Result};
use crate::iff::chunk::Chunks;
use crate::iff::wav::read::verify_wav;
@ -10,7 +10,7 @@ use byteorder::{LittleEndian, WriteBytesExt};
pub(in crate::iff::wav) fn write_riff_info<'a, I>(
data: &mut File,
tag: &mut RiffInfoListRef<'a, I>,
tag: &mut RIFFInfoListRef<'a, I>,
) -> Result<()>
where
I: Iterator<Item = (&'a str, &'a str)>,

View file

@ -11,7 +11,7 @@ pub(crate) fn write_to(data: &mut File, tag: &Tag) -> Result<()> {
match tag.tag_type() {
#[cfg(feature = "riff_info_list")]
TagType::RIFFInfo => {
super::tag::RiffInfoListRef::new(super::tag::tagitems_into_riff(tag.items()))
super::tag::RIFFInfoListRef::new(super::tag::tagitems_into_riff(tag.items()))
.write_to(data)
},
#[cfg(feature = "id3v2")]

View file

@ -16,7 +16,7 @@ use ape::tag::ApeTagRef;
#[cfg(feature = "aiff_text_chunks")]
use iff::aiff::tag::AiffTextChunksRef;
#[cfg(feature = "riff_info_list")]
use iff::wav::tag::RiffInfoListRef;
use iff::wav::tag::RIFFInfoListRef;
use std::fs::File;
use std::io::Write;
@ -72,7 +72,7 @@ pub(crate) fn dump_tag<W: Write>(tag: &Tag, writer: &mut W) -> Result<()> {
.dump_to(writer)
},
#[cfg(feature = "riff_info_list")]
TagType::RIFFInfo => RiffInfoListRef {
TagType::RIFFInfo => RIFFInfoListRef {
items: iff::wav::tag::tagitems_into_riff(tag.items()),
}
.dump_to(writer),