From 3a665919ba9ee98efb3ff54834bee7ca41f6c643 Mon Sep 17 00:00:00 2001 From: Sam Denty Date: Sat, 8 Oct 2022 13:46:45 +0100 Subject: [PATCH] 0.3.1 fix png size detection --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/icon_info.rs | 10 +++++----- src/icon_size/jpeg.rs | 2 +- src/icon_size/png.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afc848c..4e223ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1513,7 +1513,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" [[package]] name = "site_icons" -version = "0.2.1" +version = "0.3.1" dependencies = [ "byteorder", "clap", diff --git a/Cargo.toml b/Cargo.toml index 9cb71bd..2bcbeb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "site_icons" -version = "0.3.0" +version = "0.3.1" authors = ["Sam Denty "] edition = "2018" license = "GPL-3.0" diff --git a/src/icon_info.rs b/src/icon_info.rs index b46c91d..b1096ba 100644 --- a/src/icon_info.rs +++ b/src/icon_info.rs @@ -37,20 +37,20 @@ impl IconInfo { let mut header = [0; 2]; reader.read_exact(&mut header).await?; - match (kind, header) { - (Some(IconKind::PNG), _) | (_, [0xC2, 0x89]) => { + match (kind, &header) { + (Some(IconKind::PNG), _) | (_, b"\x89P") => { let size = get_png_size(reader).await?; Ok(IconInfo::PNG { size }) } - (Some(IconKind::ICO), _) | (_, [0x00, 0x00]) => { + (Some(IconKind::ICO), _) | (_, &[0x00, 0x00]) => { let sizes = get_ico_sizes(reader).await?; Ok(IconInfo::ICO { sizes }) } - (Some(IconKind::JPEG), _) | (_, [0xFF, 0xD8]) => { + (Some(IconKind::JPEG), _) | (_, &[0xFF, 0xD8]) => { let size = get_jpeg_size(reader).await?; Ok(IconInfo::JPEG { size }) } - _ => Err("unknown icon type".into()), + _ => Err(format!("unknown icon type ({:?})", header).into()), } } diff --git a/src/icon_size/jpeg.rs b/src/icon_size/jpeg.rs index 7bd22ff..1f2194b 100644 --- a/src/icon_size/jpeg.rs +++ b/src/icon_size/jpeg.rs @@ -1,7 +1,7 @@ use super::IconSize; use byteorder::BigEndian; use futures::prelude::*; -use std::{error::Error, io::Cursor}; +use std::error::Error; use tokio_futures_byteorder::AsyncReadBytesExt; pub async fn get_jpeg_size( diff --git a/src/icon_size/png.rs b/src/icon_size/png.rs index 2f80831..42f0d8f 100644 --- a/src/icon_size/png.rs +++ b/src/icon_size/png.rs @@ -10,7 +10,7 @@ pub async fn get_png_size( reader.read_exact(&mut header).await?; let header = &mut Cursor::new(header); - assert_slice_eq!(header, 0, b"PNG\r\n\x1a\n", "bad header"); + assert_slice_eq!(header, 0, b"NG\r\n\x1a\n", "bad header"); assert_slice_eq!(header, 10, b"IHDR", "bad header"); let width = header.read_u32::()?;