Skip to content

Commit

Permalink
Merge pull request #82 from Lynnesbian/master
Browse files Browse the repository at this point in the history
Implement CPIO archive support
  • Loading branch information
bojand committed Jan 1, 2023
2 parents 9b6d0b0 + 0e6dacb commit eb9b60e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -175,6 +175,7 @@ assert_eq!(kind.extension(), "foo");
- **dcm** - `application/dicom`
- **zst** - `application/zstd`
- **msi** - `application/x-ole-storage`
- **cpio** - `application/x-cpio`

#### Book

Expand Down
6 changes: 6 additions & 0 deletions src/map.rs
Expand Up @@ -570,6 +570,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
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
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 eb9b60e

Please sign in to comment.