Skip to content

Commit

Permalink
Merge pull request #105 from grumlimited/par2
Browse files Browse the repository at this point in the history
Par2 - added support
  • Loading branch information
bojand authored Feb 2, 2025
2 parents cba46eb + 4b58ab6 commit 6424c63
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ assert_eq!(kind.extension(), "foo");
- **lz4** - `application/x-lz4`
- **msi** - `application/x-ole-storage`
- **cpio** - `application/x-cpio`
- **par2** - `application/x-par2`

#### Book

Expand Down
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ matcher_map!(
"tar",
matchers::archive::is_tar
),
(
MatcherType::Archive,
"application/x-par2",
"par2",
matchers::archive::is_par2
),
(
MatcherType::Archive,
"application/vnd.rar",
Expand Down
12 changes: 12 additions & 0 deletions src/matchers/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ pub fn is_tar(buf: &[u8]) -> bool {
&& buf[261] == 0x72
}

pub fn is_par2(buf: &[u8]) -> bool {
buf.len() > 8
&& buf[0] == 0x50
&& buf[1] == 0x41
&& buf[2] == 0x52
&& buf[3] == 0x32
&& buf[4] == 0x00
&& buf[5] == 0x50
&& buf[6] == 0x4B
&& buf[7] == 0x54
}

/// Returns whether a buffer is a RAR archive.
pub fn is_rar(buf: &[u8]) -> bool {
buf.len() > 6
Expand Down
Binary file added testdata/sample.par2
Binary file not shown.
1 change: 1 addition & 0 deletions tests/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ test_format!(
zst_skip,
"sample.skippable.zst"
);
test_format!(Archive, "application/x-par2", "par2", par2, "sample.par2");

0 comments on commit 6424c63

Please sign in to comment.