1use std::io;
4use std::io::Read as _;
5
6pub(crate) mod decoder;
8pub(crate) mod encoder;
10
11pub(crate) mod format;
12pub(crate) mod free_functions;
13pub(crate) mod image_reader_type;
14pub(crate) mod limits;
15
16#[deprecated(note = "this type has been moved and renamed to image::ImageReader")]
17pub type Reader<R> = ImageReader<R>;
19#[deprecated(note = "this type has been moved to image::Limits")]
20pub type Limits = limits::Limits;
22#[deprecated(note = "this type has been moved to image::LimitSupport")]
23pub type LimitSupport = limits::LimitSupport;
25
26pub(crate) use self::image_reader_type::ImageReader;
27
28pub(crate) trait ReadExt {
30 fn read_exact_vec(&mut self, vec: &mut Vec<u8>, len: usize) -> io::Result<()>;
31}
32
33impl<R: io::Read> ReadExt for R {
34 fn read_exact_vec(&mut self, vec: &mut Vec<u8>, len: usize) -> io::Result<()> {
35 let initial_len = vec.len();
36 vec.try_reserve(len)?;
37 match self.take(len as u64).read_to_end(vec) {
38 Ok(read) if read == len => Ok(()),
39 fail => {
40 vec.truncate(initial_len);
41 Err(fail.err().unwrap_or(io::ErrorKind::UnexpectedEof.into()))
42 }
43 }
44 }
45}