Skip to content
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

reader: Dont return option for file #44

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions brro-compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,14 @@ fn process_directory(path: &Path, arguments: &Args) {

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

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);
}
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) = 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