Added buffered IO

And updated tests to reflect this
This commit is contained in:
Jamie Hardt
2021-01-02 12:23:08 -08:00
parent b7f82a9d63
commit 634c21dc9a
4 changed files with 25 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ use super::chunks::ReadBWaveChunks;
use super::cue::Cue;
use std::io::Cursor;
use std::io::{Read, Seek};
use std::io::{Read, Seek, BufReader};
@@ -68,13 +68,22 @@ pub struct WaveReader<R: Read + Seek> {
pub inner: R,
}
impl WaveReader<BufReader<File>> {
pub fn open(path: &str) -> Result<Self, ParserError> {
let f = File::open(path)?;
let inner = BufReader::new(f);
Ok( Self::new(inner)? )
}
}
impl WaveReader<File> {
/// Open a file for reading.
/// Open a file for reading with unbuffered IO.
///
/// A convenience that opens `path` and calls `Self::new()`
pub fn open(path: &str) -> Result<Self, ParserError> {
pub fn open_unbuffered(path: &str) -> Result<Self, ParserError> {
let inner = File::open(path)?;
return Ok( Self::new(inner)? )
}

View File

@@ -1,5 +1,5 @@
use std::fs::File;
use std::io::{Write,Seek,SeekFrom,Cursor};
use std::io::{Write,Seek,SeekFrom,Cursor,BufWriter};
use super::Error;
use super::fourcc::{FourCC, WriteFourCC, RIFF_SIG, RF64_SIG, DS64_SIG,
@@ -209,10 +209,19 @@ pub struct WaveWriter<W> where W: Write + Seek {
const DS64_RESERVATION_LENGTH : u32 = 96;
impl WaveWriter<File> {
impl WaveWriter<BufWriter<File>> {
/// Create a new Wave file at `path`.
pub fn create(path : &str, format : WaveFmt) -> Result<Self, Error> {
let f = File::create(path)?;
let b = BufWriter::new(f);
Ok( Self::new(b, format)? )
}
}
impl WaveWriter<File> {
/// Creare a new Wave file with unbuffered IO at `path`
pub fn create_unbuffered(path : &str, format : WaveFmt) -> Result<Self, Error> {
let f = File::create(path)?;
Ok( Self::new(f, format)? )
}