mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-28 17:21:52 +00:00
ad19b69bfb
* Remove deprecated use of std::u16::MAX * Use `FromStr` for fallible `&str` conversions * DRY up strings into constants * Change `as_ref().map()` into `as_deref()` * Use `Duration` for time constants and functions * Optimize `Vec` with response times * Move comments for `rustdoc` to parse
40 lines
958 B
Rust
40 lines
958 B
Rust
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<dyn Write>,
|
|
format: AudioFormat,
|
|
}
|
|
|
|
impl Open for StdoutSink {
|
|
fn open(path: Option<String>, format: AudioFormat) -> Self {
|
|
info!("Using pipe sink with format: {:?}", format);
|
|
|
|
let output: Box<dyn Write> = 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";
|
|
}
|