Huge refactor. Introduce anyhow for error handling.
This commit is contained in:
21
src/io.rs
21
src/io.rs
@@ -1,4 +1,5 @@
|
||||
use std::io::{self, Seek, SeekFrom};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// Get length of data stream.
|
||||
/// Physical length of data stream in bytes
|
||||
@@ -13,3 +14,23 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
|
||||
|
||||
len
|
||||
}
|
||||
|
||||
/// Generates a file path if one not provided.
|
||||
/// source_name for fallback name.
|
||||
pub fn get_path<P>(file_path: &Option<P>, source_name: &P, extension: &str) -> Option<PathBuf>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
if let Some(f) = file_path {
|
||||
return f.as_ref().to_path_buf().into();
|
||||
}
|
||||
|
||||
PathBuf::from(format!(
|
||||
"{:?}.{}",
|
||||
source_name.as_ref().to_str()?,
|
||||
extension
|
||||
))
|
||||
.as_path()
|
||||
.to_owned()
|
||||
.into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user