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/lib.rs
Line
Count
Source
1
//! Pure-Rust codecs for LZMA, LZMA2, and XZ.
2
3
#![deny(missing_docs)]
4
#![deny(missing_debug_implementations)]
5
#![forbid(unsafe_code)]
6
7
#[macro_use]
8
mod macros;
9
10
mod decode;
11
mod encode;
12
pub mod error;
13
mod xz;
14
15
use crate::decode::lzbuffer::LzBuffer;
16
use std::io;
17
18
/// Compression helpers.
19
pub mod compress {
20
    pub use crate::encode::options::*;
21
}
22
23
/// Decompression helpers.
24
pub mod decompress {
25
    pub use crate::decode::options::*;
26
    #[cfg(feature = "stream")]
27
    pub use crate::decode::stream::Stream;
28
}
29
30
/// Decompress LZMA data with default [`Options`](decompress/struct.Options.html).
31
0
pub fn lzma_decompress<R: io::BufRead, W: io::Write>(
32
0
    input: &mut R,
33
0
    output: &mut W,
34
0
) -> error::Result<()> {
35
0
    lzma_decompress_with_options(input, output, &decompress::Options::default())
36
0
}
37
38
/// Decompress LZMA data with the provided options.
39
0
pub fn lzma_decompress_with_options<R: io::BufRead, W: io::Write>(
40
0
    input: &mut R,
41
0
    output: &mut W,
42
0
    options: &decompress::Options,
43
0
) -> error::Result<()> {
44
0
    let params = decode::lzma::LzmaParams::read_header(input, options)?;
45
0
    let mut decoder = if let Some(memlimit) = options.memlimit {
46
0
        decode::lzma::new_circular_with_memlimit(output, params, memlimit)?
47
    } else {
48
0
        decode::lzma::new_circular(output, params)?
49
    };
50
51
0
    let mut rangecoder = decode::rangecoder::RangeDecoder::new(input)
52
0
        .map_err(|e| error::Error::LzmaError(format!("LZMA stream too short: {}", e)))?;
53
0
    decoder.process(&mut rangecoder)?;
54
0
    decoder.output.finish()?;
55
0
    Ok(())
56
0
}
57
58
/// Compresses data with LZMA and default [`Options`](compress/struct.Options.html).
59
0
pub fn lzma_compress<R: io::BufRead, W: io::Write>(
60
0
    input: &mut R,
61
0
    output: &mut W,
62
0
) -> io::Result<()> {
63
0
    lzma_compress_with_options(input, output, &compress::Options::default())
64
0
}
65
66
/// Compress LZMA data with the provided options.
67
0
pub fn lzma_compress_with_options<R: io::BufRead, W: io::Write>(
68
0
    input: &mut R,
69
0
    output: &mut W,
70
0
    options: &compress::Options,
71
0
) -> io::Result<()> {
72
0
    let encoder = encode::dumbencoder::Encoder::from_stream(output, options)?;
73
0
    encoder.process(input)
74
0
}
75
76
/// Decompress LZMA2 data with default [`Options`](decompress/struct.Options.html).
77
0
pub fn lzma2_decompress<R: io::BufRead, W: io::Write>(
78
0
    input: &mut R,
79
0
    output: &mut W,
80
0
) -> error::Result<()> {
81
0
    decode::lzma2::decode_stream(input, output)
82
0
}
83
84
/// Compress data with LZMA2 and default [`Options`](compress/struct.Options.html).
85
0
pub fn lzma2_compress<R: io::BufRead, W: io::Write>(
86
0
    input: &mut R,
87
0
    output: &mut W,
88
0
) -> io::Result<()> {
89
0
    encode::lzma2::encode_stream(input, output)
90
0
}
91
92
/// Decompress XZ data with default [`Options`](decompress/struct.Options.html).
93
0
pub fn xz_decompress<R: io::BufRead, W: io::Write>(
94
0
    input: &mut R,
95
0
    output: &mut W,
96
0
) -> error::Result<()> {
97
0
    decode::xz::decode_stream(input, output)
98
0
}
99
100
/// Compress data with XZ and default [`Options`](compress/struct.Options.html).
101
0
pub fn xz_compress<R: io::BufRead, W: io::Write>(input: &mut R, output: &mut W) -> io::Result<()> {
102
0
    encode::xz::encode_stream(input, output)
103
0
}