maraiah: add open_mac_file function

master
an 2019-06-23 09:21:49 -04:00
parent b78f6e8401
commit ad792b99d3
1 changed files with 12 additions and 3 deletions

View File

@ -1,8 +1,7 @@
//! File utilities.
use crate::err::*;
use std::fs;
use std::io::{SeekFrom, prelude::*};
use crate::{err::*, machdr};
use std::{fs, path::Path, io::{SeekFrom, prelude::*}};
/// Confirms that the path `p` is a folder.
pub fn validate_folder_path(p: &str) -> ResultS<()>
@ -15,6 +14,16 @@ pub fn validate_folder_path(p: &str) -> ResultS<()>
}
}
/// Opens the file at `path` and skips past any macintosh headers.
pub fn open_mac_file<P: AsRef<Path>>(path: P) -> ResultS<fs::File>
{
let mut fp = fs::File::open(path)?;
machdr::skip_mac_header(&mut fp);
Ok(fp)
}
impl<T> Drop for SeekBackToStart<T>
where T: Seek
{