CLeanup, and get domain overlap and mapping adjustment working.
This commit is contained in:
20
src/io.rs
20
src/io.rs
@@ -1,6 +1,8 @@
|
||||
use std::io::{self, Seek, SeekFrom};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Context;
|
||||
|
||||
/// Get length of data stream.
|
||||
/// Physical length of data stream in bytes
|
||||
/// (multiple of sector_size, rather than actual).
|
||||
@@ -17,20 +19,26 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
|
||||
|
||||
/// 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>
|
||||
pub fn get_path<P>(
|
||||
file_path: &Option<P>,
|
||||
source_name: &P,
|
||||
extension: &str,
|
||||
) -> anyhow::Result<PathBuf>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
if let Some(f) = file_path {
|
||||
return f.as_ref().to_path_buf().into();
|
||||
return Ok(f.as_ref().to_path_buf());
|
||||
}
|
||||
|
||||
PathBuf::from(format!(
|
||||
Ok(PathBuf::from(format!(
|
||||
"{:?}.{}",
|
||||
source_name.as_ref().to_str()?,
|
||||
source_name
|
||||
.as_ref()
|
||||
.to_str()
|
||||
.context("source_name path was not UTF-8 valid.")?,
|
||||
extension
|
||||
))
|
||||
.as_path()
|
||||
.to_owned()
|
||||
.into()
|
||||
.to_owned())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user