Coverage Report

Created: 2025-12-31 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/lzma-rs-0.2.0/src/decode/util.rs
Line
Count
Source
1
use std::hash;
2
use std::io;
3
4
0
pub fn read_tag<R: io::BufRead>(input: &mut R, tag: &[u8]) -> io::Result<bool> {
5
0
    let mut buf = vec![0; tag.len()];
6
0
    input.read_exact(buf.as_mut_slice())?;
7
0
    Ok(buf.as_slice() == tag)
8
0
}
9
10
43.7k
pub fn is_eof<R: io::BufRead>(input: &mut R) -> io::Result<bool> {
11
43.7k
    let buf = input.fill_buf()?;
12
43.7k
    Ok(buf.is_empty())
13
43.7k
}
Unexecuted instantiation: lzma_rs::decode::util::is_eof::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: lzma_rs::decode::util::is_eof::<&mut std::io::cursor::Cursor<&[u8]>>
lzma_rs::decode::util::is_eof::<std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
10
4
pub fn is_eof<R: io::BufRead>(input: &mut R) -> io::Result<bool> {
11
4
    let buf = input.fill_buf()?;
12
4
    Ok(buf.is_empty())
13
4
}
lzma_rs::decode::util::is_eof::<&mut std::io::cursor::Cursor<&[u8]>>
Line
Count
Source
10
43.7k
pub fn is_eof<R: io::BufRead>(input: &mut R) -> io::Result<bool> {
11
43.7k
    let buf = input.fill_buf()?;
12
43.7k
    Ok(buf.is_empty())
13
43.7k
}
Unexecuted instantiation: lzma_rs::decode::util::is_eof::<_>
Unexecuted instantiation: lzma_rs::decode::util::is_eof::<std::io::cursor::Cursor<&[u8]>>
Unexecuted instantiation: lzma_rs::decode::util::is_eof::<&mut std::io::cursor::Cursor<&[u8]>>
14
15
0
pub fn flush_zero_padding<R: io::BufRead>(input: &mut R) -> io::Result<bool> {
16
    loop {
17
0
        let len = {
18
0
            let buf = input.fill_buf()?;
19
0
            let len = buf.len();
20
21
0
            if len == 0 {
22
0
                return Ok(true);
23
0
            }
24
25
0
            for x in buf {
26
0
                if *x != 0u8 {
27
0
                    return Ok(false);
28
0
                }
29
            }
30
0
            len
31
        };
32
33
0
        input.consume(len);
34
    }
35
0
}
36
37
// A Read computing a digest on the bytes read.
38
pub struct HasherRead<'a, R, H>
39
where
40
    R: 'a + io::Read,
41
    H: 'a + hash::Hasher,
42
{
43
    read: &'a mut R,   // underlying reader
44
    hasher: &'a mut H, // hasher
45
}
46
47
impl<'a, R, H> HasherRead<'a, R, H>
48
where
49
    R: io::Read,
50
    H: hash::Hasher,
51
{
52
0
    pub fn new(read: &'a mut R, hasher: &'a mut H) -> Self {
53
0
        Self { read, hasher }
54
0
    }
55
}
56
57
impl<'a, R, H> io::Read for HasherRead<'a, R, H>
58
where
59
    R: io::Read,
60
    H: hash::Hasher,
61
{
62
0
    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
63
0
        let result = self.read.read(buf)?;
64
0
        self.hasher.write(&buf[..result]);
65
0
        Ok(result)
66
0
    }
67
}
68
69
// A BufRead counting the bytes read.
70
pub struct CountBufRead<'a, R>
71
where
72
    R: 'a + io::BufRead,
73
{
74
    read: &'a mut R, // underlying reader
75
    count: usize,    // number of bytes read
76
}
77
78
impl<'a, R> CountBufRead<'a, R>
79
where
80
    R: io::BufRead,
81
{
82
0
    pub fn new(read: &'a mut R) -> Self {
83
0
        Self { read, count: 0 }
84
0
    }
85
86
0
    pub fn count(&self) -> usize {
87
0
        self.count
88
0
    }
89
}
90
91
impl<'a, R> io::Read for CountBufRead<'a, R>
92
where
93
    R: io::BufRead,
94
{
95
0
    fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
96
0
        let result = self.read.read(buf)?;
97
0
        self.count += result;
98
0
        Ok(result)
99
0
    }
100
}
101
102
impl<'a, R> io::BufRead for CountBufRead<'a, R>
103
where
104
    R: io::BufRead,
105
{
106
0
    fn fill_buf(&mut self) -> io::Result<&[u8]> {
107
0
        self.read.fill_buf()
108
0
    }
109
110
0
    fn consume(&mut self, amt: usize) {
111
0
        self.read.consume(amt);
112
0
        self.count += amt;
113
0
    }
114
}