Giter Club home page Giter Club logo

Comments (10)

gendx avatar gendx commented on July 21, 2024 1

Would #17 (or a variant of it) work for this use case?

from lzma-rs.

gendx avatar gendx commented on July 21, 2024

Do you have a reference to the code or documentation, and example files to test this? Otherwise it will be hard to add support for this use case. Feel free to send a pull request as well!

from lzma-rs.

XVilka avatar XVilka commented on July 21, 2024

Yes, see how it is done https://github.com/XVilka/ocaml-lzma_7z/blob/master/lzma.ml#L387

One of the cases it was used - very old 7Zip SDK, which was used in the modified CramFS version that used LZMA:

Note how it is used 32bit ints for outsize:

from lzma-rs.

XVilka avatar XVilka commented on July 21, 2024

Yes, ability to form the header manually is good enough, thanks!

from lzma-rs.

gendx avatar gendx commented on July 21, 2024

The implementation in #17 only supports a 64-bit or 0-bit field for the unpacked size though. So I assume it wouldn't work for a 32-bit unpacked size out-of-the-box.

from lzma-rs.

XVilka avatar XVilka commented on July 21, 2024

@gendx someone also needs this feature it seems, not only me: https://users.rust-lang.org/t/extract-lzma-file/24793/5

from lzma-rs.

gendx avatar gendx commented on July 21, 2024

@gendx someone is also needs this feature it seems, not only me: https://users.rust-lang.org/t/extract-lzma-file/24793/5

Thanks for the pointer. I don't have a lot of time for implementing it at the moment, nor files from the old SDK to test with.

But feel free to send a pull request, I'll be happy to take a look!

from lzma-rs.

chyyran avatar chyyran commented on July 21, 2024

If the unpacked_size is known beforehand, #74 should cover most of this use case, except for reading the 13-byte header. You would have to read the header manually then construct the decoder with the params.

from lzma-rs.

gauravsaini avatar gauravsaini commented on July 21, 2024

Will this do ?
`impl LzmaParams {
// Other methods omitted for brevity

/// Read LZMA parameters from the LZMA stream header.
pub fn read_header<R>(input: &mut R, options: &Options) -> error::Result<LzmaParams>
where
    R: io::BufRead,
{
    // Properties
    let props = input.read_u8().map_err(error::Error::HeaderTooShort)?;

    let mut pb = props as u32;
    if pb == 0xFF {
        return Err(error::Error::InvalidLzmaProperties);
    }
    pb = pb % 9;

    let mut lp = (props / 9) as u32;
    if lp == 0xFF {
        return Err(error::Error::InvalidLzmaProperties);
    }
    lp = lp % 5;

    let mut lc = (props / (9 * 5)) as u32;
    if lc == 0xFF {
        return Err(error::Error::InvalidLzmaProperties);
    }
    lc = lc % 9;

    let properties = LzmaProperties { lc, lp, pb };

    // Dictionary size
    let mut dict_size = [0u8; 4];
    input
        .read_exact(&mut dict_size)
        .map_err(error::Error::HeaderTooShort)?;
    let dict_size = u32::from_le_bytes(dict_size) as usize;

    // Unpacked size
    let mut unpacked_size = [0u8; 8];
    input
        .read_exact(&mut unpacked_size[0..4])
        .map_err(error::Error::HeaderTooShort)?;
    let unpacked_size = u32::from_le_bytes(unpacked_size[0..4]) as usize;

    Ok(Self {
        properties,
        dict_size,
        unpacked_size,
    })
}

}
`

from lzma-rs.

gauravsaini avatar gauravsaini commented on July 21, 2024

Tests will look as follows
`
#[test]
fn test_lzma_params_read_header() {
// Test reading LZMA params from a valid stream header
let mut input = Cursor::new(b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_ok());
let params = params.unwrap();
assert_eq!(params.properties.lc, 0);
assert_eq!(params.properties.lp, 0);
assert_eq!(params.properties.pb, 1);
assert_eq!(params.dict_size, 1);
assert_eq!(params.unpacked_size, None);

// Test reading LZMA params from a stream header with unpacked size
let mut input = Cursor::new(b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_ok());
let params = params.unwrap();
assert_eq!(params.properties.lc, 0);
assert_eq!(params.properties.lp, 0);
assert_eq!(params.properties.pb, 1);
assert_eq!(params.dict_size, 1);
assert_eq!(params.unpacked_size, Some(100));

// Test reading LZMA params from a stream header with invalid properties
let mut input = Cursor::new(b"\xFF\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_err());

// Test reading LZMA params from a stream header with too few bytes
let mut input = Cursor::new(b"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00");
let options = Options::default();
let params = LzmaParams::read_header(&mut input, &options);
assert!(params.is_err());

}

`

from lzma-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.