Skip to content

Commit

Permalink
Merge pull request #44 from instaclustr/dont_return_option_for_file
Browse files Browse the repository at this point in the history
reader: Dont return option for file
NOTE: I messed up the merge, I will create a PR to fix the merge.
  • Loading branch information
cjrolo authored Oct 12, 2023
2 parents 7f95d1d + 1d8eae3 commit bba5ded
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
18 changes: 8 additions & 10 deletions brro-compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,15 @@ fn process_directory(arguments: &Args) {
}

/// Processes a single file.
fn process_single_file(arguments: &Args) {
if let Some((vec, tag)) = reader::read_file(&arguments.input).expect("Failed to read file") {
let compressed_data = compress_data(&vec, &tag, arguments);
fn process_single_file(path: &Path, arguments: &Args) {
let (vec, tag) = reader::read_file(path).expect("Failed to read file");
let compressed_data = compress_data(&vec, &tag, arguments);

if let Some(filename_osstr) = arguments.input.file_name() {
if let Some(filename_str) = filename_osstr.to_str() {
let new_filename_string =
writer::replace_extension(&filename_str.to_string(), "bin");
let new_path = arguments.input.parent().unwrap().join(new_filename_string);
write_compressed_data_to_path(&compressed_data, &new_path);
}
if let Some(filename_osstr) = path.file_name() {
if let Some(filename_str) = filename_osstr.to_str() {
let new_filename_string = writer::replace_extension(&filename_str.to_string(), "bin");
let new_path = path.parent().unwrap().join(new_filename_string);
write_compressed_data_to_path(&compressed_data, &new_path);
}
}
}
Expand Down
17 changes: 6 additions & 11 deletions brro-compressor/src/utils/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ fn process_wav_file(file_path: &Path) -> io::Result<(Vec<f64>, MetricTag)> {
}

// Function to process a RAW file
fn process_raw_file(file_path: &Path) -> io::Result<()> {
// Handle RAW file processing here (for example, decoding or encoding)
println!("Processing RAW file: {:?}", file_path);
Ok(())
fn process_raw_file(file_path: &Path) -> io::Result<(Vec<f64>, MetricTag)> {
todo!("Handle RAW file processing here (for example, decoding or encoding): {file_path:?}");
}

pub struct Files {
Expand Down Expand Up @@ -82,21 +80,18 @@ pub fn stream_reader(directory_path: &Path) -> io::Result<Files> {
}

// Check if the file is a WAV file
let res = read_file(&file_path)?;
if let Some((vec, tag)) = res { contents.push((vec, tag)) }
contents.push(read_file(&file_path)?);
}
Ok(Files {contents, names})
}

pub fn read_file(file_path: &Path) -> Result<Option<(Vec<f64>, MetricTag)>, Error> {
pub fn read_file(file_path: &Path) -> Result<(Vec<f64>, MetricTag), Error> {
if is_wav_file(file_path)? {
// If it's a WAV file, process it using the process_wav_file function
let wav_result = process_wav_file(file_path)?;
Ok(Option::from(wav_result))
process_wav_file(file_path)
} else {
// If it's not a WAV file, process it as a RAW file using the process_raw_file function
process_raw_file(file_path)?;
Ok(None)
process_raw_file(file_path)
}

}
Expand Down

0 comments on commit bba5ded

Please sign in to comment.