diff --git a/README.md b/README.md index d13f908..94cf4a9 100644 --- a/README.md +++ b/README.md @@ -218,6 +218,7 @@ assert_eq!(kind.extension(), "foo"); - **dey** - `application/vnd.android.dey` - **der** - `application/x-x509-ca-cert` - **obj** - `application/x-executable` +- **qcow2** - `application/x-qemu-disk` ## Known Issues diff --git a/src/map.rs b/src/map.rs index 4724d8f..832197f 100644 --- a/src/map.rs +++ b/src/map.rs @@ -105,6 +105,12 @@ matcher_map!( "pem", matchers::app::is_pem ), + ( + MatcherType::App, + "application/x-qemu-disk", + "qcow2", + matchers::app::is_qcow2 + ), // Book ( MatcherType::Book, diff --git a/src/matchers/app.rs b/src/matchers/app.rs index d1b8101..55f8b65 100644 --- a/src/matchers/app.rs +++ b/src/matchers/app.rs @@ -157,3 +157,9 @@ pub fn is_pem(buf: &[u8]) -> bool { && buf[9] == b'N' && buf[10] == b' ' } + +/// Returns whether a buffer is a QCOW2 disk. +pub fn is_qcow2(buf: &[u8]) -> bool { + // https://github.com/qemu/qemu/blob/master/docs/interop/qcow2.txt + buf.len() > 4 && buf[0] == b'Q' && buf[1] == b'F' && buf[2] == b'I' && buf[3] == 0xFB +} diff --git a/testdata/sample.qcow2 b/testdata/sample.qcow2 new file mode 100644 index 0000000..5c50046 Binary files /dev/null and b/testdata/sample.qcow2 differ diff --git a/tests/app.rs b/tests/app.rs index 3f71b3b..ea77483 100644 --- a/tests/app.rs +++ b/tests/app.rs @@ -49,3 +49,11 @@ test_format!(App, "application/wasm", "wasm", wasm, "sample.wasm"); test_format!(App, "application/x-x509-ca-cert", "der", der, "sample.der"); test_format!(App, "application/x-x509-ca-cert", "pem", pem, "sample.pem"); + +test_format!( + App, + "application/x-qemu-disk", + "qcow2", + qcow2, + "sample.qcow2" +);