use super::{Open, Sink, SinkAsBytes}; use crate::config::AudioFormat; use crate::convert::Converter; use crate::decoder::AudioPacket; use std::fs::OpenOptions; use std::io::{self, Write}; pub struct StdoutSink { output: Box, format: AudioFormat, } impl Open for StdoutSink { fn open(path: Option, format: AudioFormat) -> Self { info!("Using pipe sink with format: {:?}", format); let output: Box = match path { Some(path) => Box::new(OpenOptions::new().write(true).open(path).unwrap()), _ => Box::new(io::stdout()), }; Self { output, format } } } impl Sink for StdoutSink { sink_as_bytes!(); } impl SinkAsBytes for StdoutSink { fn write_bytes(&mut self, data: &[u8]) -> io::Result<()> { self.output.write_all(data)?; self.output.flush()?; Ok(()) } } impl StdoutSink { pub const NAME: &'static str = "pipe"; }