Skip to content

Commit

Permalink
Add partial support for SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Aug 20, 2022
1 parent 6579928 commit 014f9ec
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ matcher_map!(
"avif",
matchers::image::is_avif
),
(
MatcherType::Image,
"image/svg+xml",
"svg",
matchers::image::is_svg
),
// Video
(
MatcherType::Video,
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,9 @@ fn get_ftyp(buf: &[u8]) -> Option<(&[u8], &[u8], impl Iterator<Item = &[u8]>)> {

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'
}
4 changes: 4 additions & 0 deletions testdata/sample.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions tests/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

0 comments on commit 014f9ec

Please sign in to comment.