Skip to content

Commit

Permalink
feat: add support for OpenRaster (ora) format
Browse files Browse the repository at this point in the history
  • Loading branch information
chrsmth committed Nov 19, 2022
1 parent 84d6e80 commit 3a989e4
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ matcher_map!(
"epub",
matchers::archive::is_epub
),
(
MatcherType::Archive,
"image/openraster",
"ora",
matchers::archive::is_ora
),
(
MatcherType::Archive,
"application/zip",
Expand Down
32 changes: 32 additions & 0 deletions src/matchers/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@ pub fn is_epub(buf: &[u8]) -> bool {
crate::book::is_epub(buf)
}

pub fn is_ora(buf: &[u8]) -> bool {
buf.len() > 57
&& buf[0] == 0x50
&& buf[1] == 0x4B
&& buf[2] == 0x3
&& buf[3] == 0x4
&& buf[30] == 0x6D
&& buf[31] == 0x69
&& buf[32] == 0x6D
&& buf[33] == 0x65
&& buf[34] == 0x74
&& buf[35] == 0x79
&& buf[36] == 0x70
&& buf[37] == 0x65
&& buf[38] == 0x69
&& buf[39] == 0x6D
&& buf[40] == 0x61
&& buf[41] == 0x67
&& buf[42] == 0x65
&& buf[43] == 0x2F
&& buf[44] == 0x6F
&& buf[45] == 0x70
&& buf[46] == 0x65
&& buf[47] == 0x6E
&& buf[48] == 0x72
&& buf[49] == 0x61
&& buf[50] == 0x73
&& buf[51] == 0x74
&& buf[52] == 0x65
&& buf[53] == 0x72
}

/// Returns whether a buffer is a zip archive.
pub fn is_zip(buf: &[u8]) -> bool {
buf.len() > 3
Expand Down
Binary file added testdata/sample.ora
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ test_format!(
);

test_format!(Archive, "application/zstd", "zst", zst, "sample.tar.zst");

test_format!(Archive, "image/openraster", "ora", ora, "sample.ora");

0 comments on commit 3a989e4

Please sign in to comment.