Coverage Report

Created: 2025-11-24 07:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/image/src/io.rs
Line
Count
Source
1
//! Input and output of images.
2
3
use std::io;
4
use std::io::Read as _;
5
6
/// The decoder traits.
7
pub(crate) mod decoder;
8
/// The encoder traits.
9
pub(crate) mod encoder;
10
11
pub(crate) mod format;
12
pub(crate) mod free_functions;
13
pub(crate) mod image_reader_type;
14
pub(crate) mod limits;
15
16
#[deprecated(note = "this type has been moved and renamed to image::ImageReader")]
17
/// Deprecated re-export of `ImageReader` as `Reader`
18
pub type Reader<R> = ImageReader<R>;
19
#[deprecated(note = "this type has been moved to image::Limits")]
20
/// Deprecated re-export of `Limits`
21
pub type Limits = limits::Limits;
22
#[deprecated(note = "this type has been moved to image::LimitSupport")]
23
/// Deprecated re-export of `LimitSupport`
24
pub type LimitSupport = limits::LimitSupport;
25
26
pub(crate) use self::image_reader_type::ImageReader;
27
28
/// Adds `read_exact_vec`
29
pub(crate) trait ReadExt {
30
    fn read_exact_vec(&mut self, vec: &mut Vec<u8>, len: usize) -> io::Result<()>;
31
}
32
33
impl<R: io::Read> ReadExt for R {
34
230k
    fn read_exact_vec(&mut self, vec: &mut Vec<u8>, len: usize) -> io::Result<()> {
35
230k
        let initial_len = vec.len();
36
230k
        vec.try_reserve(len)?;
37
230k
        match self.take(len as u64).read_to_end(vec) {
38
230k
            Ok(read) if read == len => Ok(()),
39
603
            fail => {
40
603
                vec.truncate(initial_len);
41
603
                Err(fail.err().unwrap_or(io::ErrorKind::UnexpectedEof.into()))
42
            }
43
        }
44
230k
    }
45
}