Skip to content

Commit 01bdb18

Browse files
committed
CPIO support
1 parent 84d6e80 commit 01bdb18

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/map.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ matcher_map!(
564564
"msi",
565565
matchers::archive::is_msi
566566
),
567+
(
568+
MatcherType::Archive,
569+
"application/x-cpio",
570+
"cpio",
571+
matchers::archive::is_cpio
572+
),
567573
// Text
568574
(
569575
MatcherType::Text,

src/matchers/archive.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,17 @@ pub fn is_msi(buf: &[u8]) -> bool {
216216
&& buf[6] == 0x1A
217217
&& buf[7] == 0xE1
218218
}
219+
220+
/// Returns whether a buffer is a CPIO archive.
221+
pub fn is_cpio(buf: &[u8]) -> bool {
222+
(buf.len() > 1
223+
&& ((buf[0] == 0xC7 && buf[1] == 0x71) // little endian, old format
224+
|| (buf[0] == 0x71 && buf[1] == 0xC7))) // big endian, old format
225+
|| (buf.len() > 6
226+
&& buf[0] == 0x30
227+
&& buf[1] == 0x37
228+
&& buf[2] == 0x30
229+
&& buf[3] == 0x37
230+
&& buf[4] == 0x30
231+
&& buf[5] == 0x31) // newc format
232+
}

testdata/sample.cpio

1 KB
Binary file not shown.

tests/archive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ test_format!(
99
);
1010

1111
test_format!(Archive, "application/zstd", "zst", zst, "sample.tar.zst");
12+
13+
test_format!(Archive, "application/x-cpio", "cpio", cpio, "sample.cpio");

0 commit comments

Comments
 (0)