diff --git a/README.md b/README.md index 69d8f7e..ad05b93 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,7 @@ assert_eq!(kind.extension(), "foo"); - **dcm** - `application/dicom` - **zst** - `application/zstd` - **msi** - `application/x-ole-storage` +- **cpio** - `application/x-cpio` #### Book diff --git a/src/map.rs b/src/map.rs index 1d92627..05e16a6 100644 --- a/src/map.rs +++ b/src/map.rs @@ -564,6 +564,12 @@ matcher_map!( "msi", matchers::archive::is_msi ), + ( + MatcherType::Archive, + "application/x-cpio", + "cpio", + matchers::archive::is_cpio + ), // Text ( MatcherType::Text, diff --git a/src/matchers/archive.rs b/src/matchers/archive.rs index 710ab99..3e6c53e 100644 --- a/src/matchers/archive.rs +++ b/src/matchers/archive.rs @@ -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 +} diff --git a/testdata/sample.cpio b/testdata/sample.cpio new file mode 100644 index 0000000..ea1b8bd Binary files /dev/null and b/testdata/sample.cpio differ diff --git a/tests/archive.rs b/tests/archive.rs index f2f1e1d..37c8e5a 100644 --- a/tests/archive.rs +++ b/tests/archive.rs @@ -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");