mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 23:07:20 +00:00
implemented clippy suggestions
This commit is contained in:
parent
e1a8e08a3f
commit
a326788819
3 changed files with 6 additions and 9 deletions
|
@ -18,7 +18,6 @@ pub(crate) fn search_for_frame_sync<R>(input: &mut R) -> std::io::Result<Option<
|
|||
where
|
||||
R: Read,
|
||||
{
|
||||
let mut index = 0u64;
|
||||
let mut iterator = input.bytes();
|
||||
let mut buffer = [0u8; 2];
|
||||
// Read the first byte, as each iteration expects that buffer 0 was set from a previous iteration.
|
||||
|
@ -29,15 +28,14 @@ where
|
|||
// create a stream of overlapping 2 byte pairs
|
||||
// example: [0x01, 0x02, 0x03, 0x04] should be analyzed as
|
||||
// [0x01, 0x02], [0x02, 0x03], [0x03, 0x04]
|
||||
while let Some(byte) = iterator.next() {
|
||||
for (index, byte) in iterator.enumerate() {
|
||||
buffer[1] = byte?;
|
||||
// check the two bytes in the buffer
|
||||
if verify_frame_sync(buffer) {
|
||||
return Ok(Some(index));
|
||||
return Ok(Some(index as u64));
|
||||
}
|
||||
// if they do not match, copy the last byte in the buffer to the front for the next iteration
|
||||
buffer[0] = buffer[1];
|
||||
index += 1;
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ where
|
|||
// seek back the length of the temporary header buffer
|
||||
// so that all bytes are included in the search for a frame sync
|
||||
let start_of_search_area =
|
||||
reader.seek(SeekFrom::Current(-1 * header.len() as i64))?;
|
||||
reader.seek(SeekFrom::Current(-(header.len() as i64)))?;
|
||||
if let Some(first_mp3_frame_start_relative) = search_for_frame_sync(reader)? {
|
||||
let first_mp3_frame_start_absolute =
|
||||
start_of_search_area + first_mp3_frame_start_relative;
|
||||
|
@ -99,10 +99,9 @@ where
|
|||
|
||||
// We have found the first frame
|
||||
break;
|
||||
} else {
|
||||
// the search for sync bits was unsuccessful
|
||||
return Err(LoftyError::Mp3("File contains an invalid frame"));
|
||||
}
|
||||
// the search for sync bits was unsuccessful
|
||||
return Err(LoftyError::Mp3("File contains an invalid frame"));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ impl<R: Read + Seek> Probe<R> {
|
|||
// potentially some junk bytes are between the ID3 block and the following MP3 block
|
||||
// search for any possible sync bits after the ID3 block
|
||||
self.inner.seek(SeekFrom::Start(position_after_id3_block))?;
|
||||
if let Some(_) = search_for_frame_sync(&mut self.inner)? {
|
||||
if search_for_frame_sync(&mut self.inner)?.is_some() {
|
||||
Ok(Some(FileType::MP3))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
|
Loading…
Add table
Reference in a new issue