-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compress stream #39
Compress stream #39
Conversation
Compressor::Constant => constant(data), | ||
_ => todo!(), | ||
_ => noop(data), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo its a lot better to halt the program and say "hey that compression type isnt implemented yet" i.e. todo!()
than to silently do something incorrect. Makes debugging easier.
@@ -41,6 +41,27 @@ pub struct Files { | |||
pub names: Vec<String>, | |||
} | |||
|
|||
/// Read a file by chunks and processes the chunks | |||
pub fn process_by_chunk(file_path: &Path) -> Result<(), std::io::Error> { | |||
let mut file = match std::fs::File::open(file_path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match is effectively the same as .unwrap()
, either .unwrap()
or maybe use ?
instead to bubble up the error.
/// Gets a binary stream and generates a Compressed Stream | ||
pub fn from_bytes(data: &[u8]) -> Self { | ||
let config = BinConfig::get(); | ||
match bincode::decode_from_slice(data, config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This match is effectively the same as .unwrap()
, maybe just dobincode::decode_from_slice(data, config).unwrap().0
instead.
Or maybe let (compressed_stream, _) = bincode::decode_from_slice(data, config).unwrap();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few nits, the actual real problems here you have already marked as TODO's which is fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with all the aforementioned points
/// If a stream is provided it adds a chunk to that stream, otherwise creates a new one | ||
fn compress_file(stream: Option<CompressedStream>, wav_content: Vec<f64>) -> CompressedStream { | ||
let mut cs = match stream { | ||
Some(cs) => cs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use unwrap_or(CompressedStream::new())
instead of this match
@@ -14,4 +17,78 @@ impl CompressedStream { | |||
data_frames: Vec::new(), | |||
} | |||
} | |||
|
|||
/// Compress a chunk of data adding it as a new frame to the current stream | |||
pub fn compress_chunk(&mut self, chunk: &[f64]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not needed. Remove it, we can just pass None to the next one.
This PR adds the capacity to compress a file with proper headers and structure.
Decompression is not yet tested. That would be a next pull request