1#![cfg_attr(docsrs, feature(doc_cfg, doc_cfg_hide))]
3#![deny(missing_docs)]
4#![deny(missing_debug_implementations)]
5#![forbid(unsafe_code)]
6
7#[macro_use]
8mod macros;
9
10mod decode;
11mod encode;
12
13pub mod error;
14
15mod util;
16mod xz;
17
18use std::io;
19
20pub mod compress {
22 pub use crate::encode::options::*;
23}
24
25pub mod decompress {
27 pub use crate::decode::options::*;
28
29 #[cfg(feature = "raw_decoder")]
30 #[cfg_attr(docsrs, doc(cfg(raw_decoder)))]
31 pub mod raw {
32 pub use crate::decode::lzma::{LzmaDecoder, LzmaParams, LzmaProperties};
34 pub use crate::decode::lzma2::Lzma2Decoder;
35 }
36
37 #[cfg(feature = "stream")]
38 #[cfg_attr(docsrs, doc(cfg(stream)))]
39 pub use crate::decode::stream::Stream;
40}
41
42pub fn lzma_decompress<R: io::BufRead, W: io::Write>(
44 input: &mut R,
45 output: &mut W,
46) -> error::Result<()> {
47 lzma_decompress_with_options(input, output, &decompress::Options::default())
48}
49
50pub fn lzma_decompress_with_options<R: io::BufRead, W: io::Write>(
52 input: &mut R,
53 output: &mut W,
54 options: &decompress::Options,
55) -> error::Result<()> {
56 let params = decode::lzma::LzmaParams::read_header(input, options)?;
57 let mut decoder = decode::lzma::LzmaDecoder::new(params, options.memlimit)?;
58 decoder.decompress(input, output)
59}
60
61pub fn lzma_compress<R: io::BufRead, W: io::Write>(
63 input: &mut R,
64 output: &mut W,
65) -> io::Result<()> {
66 lzma_compress_with_options(input, output, &compress::Options::default())
67}
68
69pub fn lzma_compress_with_options<R: io::BufRead, W: io::Write>(
71 input: &mut R,
72 output: &mut W,
73 options: &compress::Options,
74) -> io::Result<()> {
75 let encoder = encode::dumbencoder::Encoder::from_stream(output, options)?;
76 encoder.process(input)
77}
78
79pub fn lzma2_decompress<R: io::BufRead, W: io::Write>(
81 input: &mut R,
82 output: &mut W,
83) -> error::Result<()> {
84 decode::lzma2::Lzma2Decoder::new().decompress(input, output)
85}
86
87pub fn lzma2_compress<R: io::BufRead, W: io::Write>(
89 input: &mut R,
90 output: &mut W,
91) -> io::Result<()> {
92 encode::lzma2::encode_stream(input, output)
93}
94
95pub fn xz_decompress<R: io::BufRead, W: io::Write>(
97 input: &mut R,
98 output: &mut W,
99) -> error::Result<()> {
100 decode::xz::decode_stream(input, output)
101}
102
103pub fn xz_compress<R: io::BufRead, W: io::Write>(input: &mut R, output: &mut W) -> io::Result<()> {
105 encode::xz::encode_stream(input, output)
106}