adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.28k stars 480 forks source link

Are there any examples on how to use LzmaStream to compress and decompress a stream? #424

Open natiki opened 6 years ago

natiki commented 6 years ago

Hi,

public Stream Compress(Stream aDataToCompress)
{
    MemoryStream result = new MemoryStream();
    using (new OzCsMaintainStreamPosition(result))
    {
        using (new OzCsMaintainStreamPosition(aDataToCompress))
        {
            using (LzmaStream lzmaStream = new LzmaStream(new LzmaEncoderProperties(), true, result))
            {
                aDataToCompress.CopyTo(lzmaStream);
                lzmaStream.Close();
            }
        }
    }

    return result;
}

I am getting a "Not Implemented" exception when I attempt to instantiate a LzmaStream.

hopperpl commented 5 years ago

LZMA2 is not supported. Use false for the 2nd parameter in the LzmaStream constructor.

new LzmaStream(new LzmaEncoderProperties(), false, result)

Had the same problem a moment ago.

adamhathcock commented 5 years ago

LZMA2 is supported - https://github.com/adamhathcock/sharpcompress/blob/master/FORMATS.md

The internals aren’t straight forward but looking at the tests can give you some help. I’m on vacation for a few weeks with only a phone so I can’t offer more at the moment

natiki commented 5 years ago

@adamhathcock Had a look at the tests and still not having any luck. When you are back from vacation would appreciate it, if you could have a look.

adamhathcock commented 5 years ago

Using LZMA or LZMA2 directly requires creating a byte array of properties. I recognize this isn't easy to use but I haven't put a pretty interface on LzmaStream directly as it's intended to be used with an archive format.

Please read the readme for recommendations and links and not just blindly use "LZMA2" because people say it's always better

https://github.com/adamhathcock/sharpcompress#recommended-formats https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm#LZMA2_format

natiki commented 5 years ago

Thanks.... Building up a suite here for internal use.