MP4: Add Atom::push_data

This commit is contained in:
Serial 2022-07-30 19:47:47 -04:00
parent c4fa8f99d8
commit 390512bda3
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
6 changed files with 16 additions and 7 deletions

View file

@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- With the new `lofty_attr` crate, file creation has been simplified significantly.
It is available for both internal and external usage.
- **ID3v2**: Exposed internal functions `id3::v2::util::{synch_u32, unsynch_u32}`
- **MP4**: `Atom::push_data`
### Changed
- **TaggedFile**: `tag{_mut}` no longer takes a reference to `TagType`

View file

@ -39,5 +39,5 @@ fn zero_size_id3v2() {
let mut f = Cursor::new(std::fs::read("tests/tags/assets/id3v2/zero.id3v2").unwrap());
let header = read_id3v2_header(&mut f).unwrap();
assert!(parse_id3v2(&mut f, header).is_ok());
parse_id3v2(&mut f, header).unwrap();
}

View file

@ -1013,7 +1013,7 @@ mod tests {
let mut reader = &mut &writer[..];
let header = read_id3v2_header(&mut reader).unwrap();
assert!(crate::id3::v2::read::parse_id3v2(reader, header).is_ok());
crate::id3::v2::read::parse_id3v2(reader, header).unwrap();
assert_eq!(writer[3..10], writer[writer.len() - 7..])
}

View file

@ -96,6 +96,6 @@ mod tests {
0xFF, 0xE0, 0x00, 0xFF, 0x12, 0xB0, 0x05, 0xFF, 0x00, 0x50, 0x01,
];
assert!(super::unsynch_content(invalid_unsynch.as_slice()).is_err());
super::unsynch_content(invalid_unsynch.as_slice()).unwrap_err();
}
}

View file

@ -117,6 +117,16 @@ impl Atom {
(&self.data).into_iter()
}
/// Append a value to the atom
pub fn push_data(&mut self, data: AtomData) {
match self.data {
AtomDataStorage::Single(ref s) => {
self.data = AtomDataStorage::Multiple(vec![s.clone(), data])
},
AtomDataStorage::Multiple(ref mut m) => m.push(data),
}
}
// Used internally, has no correctness checks
pub(crate) fn unknown_implicit(ident: AtomIdent, data: Vec<u8>) -> Self {
Self {
@ -131,8 +141,6 @@ impl Atom {
data: AtomDataStorage::Single(AtomData::UTF8(data)),
}
}
// TODO: push_data
}
impl Debug for Atom {

View file

@ -732,7 +732,7 @@ mod tests {
const PADDING_SIZE: usize = 990;
let file_bytes = read_path("tests/files/assets/ilst_trailing_padding.m4a");
assert!(Mp4File::read_from(&mut Cursor::new(&file_bytes), false).is_ok());
Mp4File::read_from(&mut Cursor::new(&file_bytes), false).unwrap();
let mut ilst;
let old_free_size;
@ -778,7 +778,7 @@ mod tests {
// Verify we can re-read the file
file.rewind().unwrap();
assert!(Mp4File::read_from(&mut file, false).is_ok());
Mp4File::read_from(&mut file, false).unwrap();
}
#[test]