diff --git a/maraiah/machdr.rs b/maraiah/machdr.rs index 69e8139..e0c4f6c 100644 --- a/maraiah/machdr.rs +++ b/maraiah/machdr.rs @@ -3,8 +3,8 @@ use crate::file::SeekBackToStart; use std::io::{SeekFrom, prelude::*}; -/// Checks for an Apple Single header. Returns offset to the resource fork. -pub fn check_apple_single(fp: &mut R) -> bool +/// Skips over an Apple Single header. Returns true if one was found. +pub fn skip_apple_single(fp: &mut R) -> bool where R: Read + Seek { let mut fp = SeekBackToStart::new(fp); @@ -53,8 +53,8 @@ pub fn check_apple_single(fp: &mut R) -> bool false } -/// Checks for a Mac Binary II header. Returns offset to the resource fork. -pub fn check_macbin(fp: &mut R) -> bool +/// Skips over a Mac Binary II header. Returns true if one was found. +pub fn skip_macbin(fp: &mut R) -> bool where R: Read + Seek { let mut fp = SeekBackToStart::new(fp); @@ -92,18 +92,19 @@ pub fn check_macbin(fp: &mut R) -> bool } } -/// Reads a `MacBin` or `AppleSingle` header if there is one and returns the -/// offset from the start of the header to the resource fork (if one is found.) -pub fn try_mac_header(fp: &mut R) -> bool +/// Reads a `MacBin` or `AppleSingle` header if there is one and skips past it +/// from the start of the header to the resource fork (if one is found.) Returns +/// true if either one was found. +pub fn skip_mac_header(fp: &mut R) -> bool where R: Read + Seek { - if check_macbin(fp) { + if skip_macbin(fp) { return true; } let _ = fp.seek(SeekFrom::Start(0)); - if check_apple_single(fp) { + if skip_apple_single(fp) { return true; } diff --git a/tests/misc.rs b/tests/misc.rs index 8bbf01e..448025d 100644 --- a/tests/misc.rs +++ b/tests/misc.rs @@ -9,8 +9,8 @@ fn machdr_must_process() let mut inp = std::io::Cursor::new(INPUT); - assert_eq!(machdr::check_macbin(&mut inp), true); - assert_eq!(machdr::try_mac_header(&mut inp), true); + assert_eq!(machdr::skip_macbin(&mut inp), true); + assert_eq!(machdr::skip_mac_header(&mut inp), true); // FIXME: missing test data for applesingle } @@ -20,9 +20,9 @@ fn machdr_must_not_process() { for rinp in &RANDOM { let mut inp = std::io::Cursor::new(rinp); - assert_eq!(machdr::check_macbin(&mut inp), false); - assert_eq!(machdr::check_apple_single(&mut inp), false); - assert_eq!(machdr::try_mac_header(&mut inp), false); + assert_eq!(machdr::skip_macbin(&mut inp), false); + assert_eq!(machdr::skip_apple_single(&mut inp), false); + assert_eq!(machdr::skip_mac_header(&mut inp), false); } }