Skip to content

Commit 51d4a37

Browse files
committed
feat(archive): Add bzip3 support
1 parent 66c1890 commit 51d4a37

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ assert_eq!(kind.extension(), "foo");
157157
- **rar** - `application/vnd.rar`
158158
- **gz** - `application/gzip`
159159
- **bz2** - `application/x-bzip2`
160+
- **bz3** - `application/vnd.bzip3`
160161
- **7z** - `application/x-7z-compressed`
161162
- **xz** - `application/x-xz`
162163
- **pdf** - `application/pdf`

src/map.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,12 @@ matcher_map!(
462462
"bz2",
463463
matchers::archive::is_bz2
464464
),
465+
(
466+
MatcherType::Archive,
467+
"application/vnd.bzip3",
468+
"bz3",
469+
matchers::archive::is_bz3
470+
),
465471
(
466472
MatcherType::Archive,
467473
"application/x-7z-compressed",

src/matchers/archive.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,21 @@ pub fn is_gz(buf: &[u8]) -> bool {
5252
buf.len() > 2 && buf[0] == 0x1F && buf[1] == 0x8B && buf[2] == 0x8
5353
}
5454

55-
/// Returns whether a buffer is a bzip archive.
55+
/// Returns whether a buffer is a bzip2 archive.
5656
pub fn is_bz2(buf: &[u8]) -> bool {
5757
buf.len() > 2 && buf[0] == 0x42 && buf[1] == 0x5A && buf[2] == 0x68
5858
}
5959

60+
/// Returns whether a buffer is a bzip3 archive.
61+
pub fn is_bz3(buf: &[u8]) -> bool {
62+
buf.len() > 4
63+
&& buf[0] == b'B'
64+
&& buf[1] == b'Z'
65+
&& buf[2] == b'3'
66+
&& buf[3] == b'v'
67+
&& buf[4] == b'1'
68+
}
69+
6070
/// Returns whether a buffer is a 7z archive.
6171
pub fn is_7z(buf: &[u8]) -> bool {
6272
buf.len() > 5

testdata/sample.tar.bz3

127 Bytes
Binary file not shown.

tests/archive.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
mod common;
22

3+
test_format!(
4+
Archive,
5+
"application/vnd.bzip3",
6+
"bz3",
7+
bz3,
8+
"sample.tar.bz3"
9+
);
310
test_format!(
411
Archive,
512
"application/vnd.sqlite3",

0 commit comments

Comments
 (0)