lzma_rs/decode/
options.rs

1/// Options to tweak decompression behavior.
2#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
3pub struct Options {
4    /// Defines whether the unpacked size should be read from the header or provided.
5    ///
6    /// The default is
7    /// [`UnpackedSize::ReadFromHeader`](enum.UnpackedSize.html#variant.ReadFromHeader).
8    pub unpacked_size: UnpackedSize,
9    /// Defines whether the dictionary's dynamic size should be limited during decompression.
10    ///
11    /// The default is unlimited.
12    pub memlimit: Option<usize>,
13    /// Determines whether to bypass end of stream validation.
14    ///
15    /// This option only applies to the [`Stream`](struct.Stream.html) API.
16    ///
17    /// The default is false (always do completion check).
18    pub allow_incomplete: bool,
19}
20
21/// Alternatives for defining the unpacked size of the decoded data.
22#[derive(Clone, Copy, Debug, PartialEq, Eq)]
23pub enum UnpackedSize {
24    /// Assume that the 8 bytes used to specify the unpacked size are present in the header.
25    /// If the bytes are `0xFFFF_FFFF_FFFF_FFFF`, assume that there is an end-of-payload marker in
26    /// the file.
27    /// If not, read the 8 bytes as a little-endian encoded u64.
28    ReadFromHeader,
29    /// Assume that there are 8 bytes representing the unpacked size present in the header.
30    /// Read it, but ignore it and use the provided value instead.
31    /// If the provided value is `None`, assume that there is an end-of-payload marker in the file.
32    /// Note that this is a non-standard way of reading LZMA data,
33    /// but is used by certain libraries such as
34    /// [OpenCTM](http://openctm.sourceforge.net/).
35    ReadHeaderButUseProvided(Option<u64>),
36    /// Assume that the 8 bytes typically used to represent the unpacked size are *not* present in
37    /// the header. Use the provided value.
38    /// If the provided value is `None`, assume that there is an end-of-payload marker in the file.
39    UseProvided(Option<u64>),
40}
41
42impl Default for UnpackedSize {
43    fn default() -> UnpackedSize {
44        UnpackedSize::ReadFromHeader
45    }
46}
47
48#[cfg(test)]
49mod test {
50    use super::*;
51    #[test]
52    fn test_options() {
53        assert_eq!(
54            Options {
55                unpacked_size: UnpackedSize::ReadFromHeader,
56                memlimit: None,
57                allow_incomplete: false,
58            },
59            Options::default()
60        );
61    }
62}