Skip to content

Commit 014f9ec

Browse files
committed
Add partial support for SVG
1 parent 6579928 commit 014f9ec

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/map.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ matcher_map!(
191191
"avif",
192192
matchers::image::is_avif
193193
),
194+
(
195+
MatcherType::Image,
196+
"image/svg+xml",
197+
"svg",
198+
matchers::image::is_svg
199+
),
194200
// Video
195201
(
196202
MatcherType::Video,

src/matchers/image.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,9 @@ fn get_ftyp(buf: &[u8]) -> Option<(&[u8], &[u8], impl Iterator<Item = &[u8]>)> {
160160

161161
Some((major, minor, compatible))
162162
}
163+
164+
/// Returns whether a buffer is SVG.
165+
pub fn is_svg(buf: &[u8]) -> bool {
166+
// ref: https://stackoverflow.com/a/66975778
167+
buf.len() > 4 && buf[0] == b'<' && buf[1] == b's' && buf[2] == b'v' && buf[3] == b'g'
168+
}

testdata/sample.svg

Lines changed: 4 additions & 0 deletions
Loading

tests/image.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ test_format!(Image, "image/vnd.microsoft.icon", "ico", ico, "sample.ico");
2525
test_format!(Image, "image/heif", "heif", heif, "sample.heic");
2626

2727
test_format!(Image, "image/avif", "avif", avif, "sample.avif");
28+
29+
test_format!(Image, "image/svg+xml", "svg", svg, "sample.svg");

0 commit comments

Comments
 (0)