lzma-rs icon indicating copy to clipboard operation
lzma-rs copied to clipboard

How to set dictSize on lzma2_decompress

Open jimliang opened this issue 6 years ago • 7 comments

In https://mvnrepository.com/artifact/com.github.veithen.cosmos.bootstrap/org.tukaani.xz I see

package org.tukaani.xz;

public class LZMA2InputStream extends InputStream {
   
   ...
    public LZMA2InputStream(InputStream in, int dictSize) {
        this(in, dictSize, (byte[])null);
    }

dictSize is a param to construct LZMA2InputStream

jimliang avatar Oct 24 '19 03:10 jimliang

The LZMA format contains a header which specifies the dictionary size to use: https://github.com/gendx/lzma-rs/blob/master/src/decode/lzma.rs#L46

So lzma-rs just follows whatever dictionary size is written in the compressed stream, there is currently no way to override this value, nor to set limits on it.

gendx avatar Oct 24 '19 17:10 gendx

Some formats specify the properties in a different format. It would be awesome to have the "raw" function with everything as a parameter instead.

XVilka avatar Nov 13 '19 13:11 XVilka

Do you have a reference to the code and documentation for such "some formats"? Otherwise it's hard to add the feature you wish. Feel free to send a pull-request as well (with supporting references, example files, etc.).

gendx avatar Nov 14 '19 12:11 gendx

xz for java: https://tukaani.org/xz/java.html see LZMAInputStream , LZMA2InputStream @gendx

jimliang avatar Nov 15 '19 02:11 jimliang

I am working on porting libchdr to Rust, which directly interfaces with the LZMA SDK and sets the dictSize and other LZMA params explicitly.

My current solution is to vendor lzma-rs to expose the required options in Stream.

chyyran avatar Mar 18 '22 01:03 chyyran

I assume this issue is the same feature request as #72?

gendx avatar May 30 '22 20:05 gendx

#74 covers this for LZMA1, but I'm not sure how the current design of the LZMA2 decoder can take a useful dict_size parameter.

chyyran avatar Aug 05 '22 18:08 chyyran