Skip to content

Commit

Permalink
CPIO support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lynnesbian committed Nov 21, 2022
1 parent 84d6e80 commit 01bdb18
Show file tree
Hide file tree
Showing 4 changed files with 22 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 @@ -564,6 +564,12 @@ matcher_map!(
"msi",
matchers::archive::is_msi
),
(
MatcherType::Archive,
"application/x-cpio",
"cpio",
matchers::archive::is_cpio
),
// Text
(
MatcherType::Text,
Expand Down
14 changes: 14 additions & 0 deletions src/matchers/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,17 @@ pub fn is_msi(buf: &[u8]) -> bool {
&& buf[6] == 0x1A
&& buf[7] == 0xE1
}

/// Returns whether a buffer is a CPIO archive.
pub fn is_cpio(buf: &[u8]) -> bool {
(buf.len() > 1
&& ((buf[0] == 0xC7 && buf[1] == 0x71) // little endian, old format
|| (buf[0] == 0x71 && buf[1] == 0xC7))) // big endian, old format
|| (buf.len() > 6
&& buf[0] == 0x30
&& buf[1] == 0x37
&& buf[2] == 0x30
&& buf[3] == 0x37
&& buf[4] == 0x30
&& buf[5] == 0x31) // newc format
}
Binary file added testdata/sample.cpio
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, "application/x-cpio", "cpio", cpio, "sample.cpio");

0 comments on commit 01bdb18

Please sign in to comment.