0.3.1 fix png size detection
This commit is contained in:
parent
1e8cb649fb
commit
3a665919ba
5 changed files with 9 additions and 9 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1513,7 +1513,7 @@ checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
|
|||
|
||||
[[package]]
|
||||
name = "site_icons"
|
||||
version = "0.2.1"
|
||||
version = "0.3.1"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"clap",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "site_icons"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
authors = ["Sam Denty <sam@samdenty.com>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0"
|
||||
|
|
|
@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<R: AsyncRead + Unpin>(
|
||||
|
|
|
@ -10,7 +10,7 @@ pub async fn get_png_size<R: AsyncRead + Unpin>(
|
|||
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::<BigEndian>()?;
|
||||
|
|
Reference in a new issue