maraiah: fix machdr doc/naming

master
an 2019-06-23 09:20:53 -04:00
parent 9b9a484351
commit b78f6e8401
2 changed files with 15 additions and 14 deletions

View File

@ -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<R>(fp: &mut R) -> bool
/// Skips over an Apple Single header. Returns true if one was found.
pub fn skip_apple_single<R>(fp: &mut R) -> bool
where R: Read + Seek
{
let mut fp = SeekBackToStart::new(fp);
@ -53,8 +53,8 @@ pub fn check_apple_single<R>(fp: &mut R) -> bool
false
}
/// Checks for a Mac Binary II header. Returns offset to the resource fork.
pub fn check_macbin<R>(fp: &mut R) -> bool
/// Skips over a Mac Binary II header. Returns true if one was found.
pub fn skip_macbin<R>(fp: &mut R) -> bool
where R: Read + Seek
{
let mut fp = SeekBackToStart::new(fp);
@ -92,18 +92,19 @@ pub fn check_macbin<R>(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<R>(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<R>(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;
}

View File

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