Skip to content

Commit

Permalink
Add type .ico (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatakeshi authored and svartalf committed May 6, 2019
1 parent 89b15f1 commit c47e373
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -37,6 +37,8 @@ pub enum Type {
Rgb,
/// FLIF (Free Lossless Image Format) files
Flif,
/// ICO files
Ico
}


Expand Down
2 changes: 2 additions & 0 deletions src/patterns.rs
Expand Up @@ -16,6 +16,7 @@ const BMP: &'static [u8] = b"BM";
const BGP: &'static [u8] = b"BPG\xfb";
const RGB: &'static [u8] = b"\x01\xda";
const FLIF: &'static [u8] = b"FLIF";
const ICO: &'static [u8] = b"\x00\x00\x01\x00";

#[inline]
fn is_pbm(ref bytes: [u8; 32]) -> bool {
Expand Down Expand Up @@ -51,6 +52,7 @@ pub fn guess(ref bytes: [u8; 32]) -> Option<Type> {
_ if &bytes[..4] == BGP => Some(Type::Bgp),
_ if &bytes[..2] == RGB => Some(Type::Rgb),
_ if &bytes[..4] == FLIF => Some(Type::Flif),
_ if &bytes[..4] == ICO => Some(Type::Ico),
_ if is_pbm(*bytes) => Some(Type::Pbm),
_ if is_pgm(*bytes) => Some(Type::Pgm),
_ if is_ppm(*bytes) => Some(Type::Ppm),
Expand Down
Binary file added tests/images/example.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/mod.rs
Expand Up @@ -99,6 +99,11 @@ fn test_flif() {
assert_result!(Some(imghdr::Type::Flif), "./tests/images/example.flif");
}

#[test]
fn test_ico() {
assert_result!(Some(imghdr::Type::Ico), "./tests/images/example.ico");
}

#[test]
fn test_not_a_image() {
assert_result!(None::<imghdr::Type>, "./tests/images/not-a-image.txt");
Expand Down

0 comments on commit c47e373

Please sign in to comment.