diff --git a/src/map.rs b/src/map.rs index f1a2f42..c3bd333 100644 --- a/src/map.rs +++ b/src/map.rs @@ -191,6 +191,12 @@ matcher_map!( "avif", matchers::image::is_avif ), + ( + MatcherType::Image, + "image/svg+xml", + "svg", + matchers::image::is_svg + ), // Video ( MatcherType::Video, diff --git a/src/matchers/image.rs b/src/matchers/image.rs index 0196cad..3175663 100644 --- a/src/matchers/image.rs +++ b/src/matchers/image.rs @@ -160,3 +160,9 @@ fn get_ftyp(buf: &[u8]) -> Option<(&[u8], &[u8], impl Iterator)> { Some((major, minor, compatible)) } + +/// Returns whether a buffer is SVG. +pub fn is_svg(buf: &[u8]) -> bool { + // ref: https://stackoverflow.com/a/66975778 + buf.len() > 4 && buf[0] == b'<' && buf[1] == b's' && buf[2] == b'v' && buf[3] == b'g' +} diff --git a/testdata/sample.svg b/testdata/sample.svg new file mode 100644 index 0000000..c094ee9 --- /dev/null +++ b/testdata/sample.svg @@ -0,0 +1,4 @@ + + + + diff --git a/tests/image.rs b/tests/image.rs index a1dcfcd..08e9350 100644 --- a/tests/image.rs +++ b/tests/image.rs @@ -25,3 +25,5 @@ test_format!(Image, "image/vnd.microsoft.icon", "ico", ico, "sample.ico"); test_format!(Image, "image/heif", "heif", heif, "sample.heic"); test_format!(Image, "image/avif", "avif", avif, "sample.avif"); + +test_format!(Image, "image/svg+xml", "svg", svg, "sample.svg"); \ No newline at end of file