Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add partial support for SVG #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");