Trying to get LZMA mainstream 😜
A Stream
that works exactly as you would expect: read from it and unpack or write to it and pack (the same way you would do with GZipStream
)
To decompress data:
// packedStream is the LZMA packed source stream
using (var lzmaStream = new LzmaStream(packedStream, CompressionMode.Decompress))
{
lzmaStream.CopyTo(unpackTarget);
// or
// lzmaStream.Read(unpackData, 0, unpackData.Length);
}
… And to compress it:
// packedStream is a stream receiving packed data
using (var lzmaStream = new LzmaStream(packedStream, CompressionMode.Compress))
// or
// using (var lzmaStream = new LzmaStream(rawStream, LzmaCompressionParameters.Defaut /* or .Optimal or .Fast or custom… */))
{
// copy from an unpacked stream to LZMA output
rawStream.CopyTo(lzmaStream);
// or
// lzmaStream.Write(rawData, 0, rawData.Length);
}
This library uses unmodified source code from https://www.7-zip.org/sdk.html (from another repository)