pile-audio refactor
Some checks failed
CI / Typos (push) Successful in 17s
CI / Clippy (push) Has been cancelled
CI / Build and test (push) Has been cancelled

This commit is contained in:
2026-02-21 19:14:52 -08:00
parent 5aab61bd1b
commit 4b41467cc2
35 changed files with 1968 additions and 3366 deletions

View File

@@ -0,0 +1,53 @@
use std::{fmt::Debug, io::Read};
use super::{FlacMetablockDecode, FlacMetablockEncode, FlacMetablockHeader, FlacMetablockType};
use crate::{FlacDecodeError, FlacEncodeError};
/// A padding block in a FLAC file.
#[derive(Debug)]
pub struct FlacPaddingBlock {
/// The length of this padding, in bytes.
pub size: u32,
}
impl FlacMetablockDecode for FlacPaddingBlock {
#[expect(clippy::expect_used)]
fn decode(data: &[u8]) -> Result<Self, FlacDecodeError> {
if data.iter().any(|x| *x != 0u8) {
return Err(FlacDecodeError::MalformedBlock);
}
Ok(Self {
size: data
.len()
.try_into()
.expect("padding size does not fit into u32"),
})
}
}
impl FlacMetablockEncode for FlacPaddingBlock {
fn get_len(&self) -> u32 {
self.size
}
fn encode(
&self,
is_last: bool,
with_header: bool,
target: &mut impl std::io::Write,
) -> Result<(), FlacEncodeError> {
if with_header {
let header = FlacMetablockHeader {
block_type: FlacMetablockType::Padding,
length: self.get_len(),
is_last,
};
header.encode(target)?;
}
std::io::copy(&mut std::io::repeat(0u8).take(self.size.into()), target)?;
return Ok(());
}
}