26 lines
960 B
C#
26 lines
960 B
C#
namespace Млаумчерб.Клиент;
|
||
|
||
/// <summary>
|
||
/// https://gist.github.com/ststeiger/cb9750664952f775a341
|
||
/// </summary>
|
||
public static class LZMACompressor
|
||
{
|
||
public static void Decompress(Stream inputStream, Stream outputStream)
|
||
{
|
||
var decoder = new SevenZip.Compression.LZMA.Decoder();
|
||
var properties = new byte[5];
|
||
// Read decoder properties
|
||
if (inputStream.Read(properties, 0, 5) != 5)
|
||
throw new Exception("lzma stream is too short");
|
||
decoder.SetDecoderProperties(properties);
|
||
|
||
// Read decompressed data size
|
||
var fileLengthBytes = new byte[8];
|
||
if(inputStream.Read(fileLengthBytes, 0, 8) != 8)
|
||
throw new Exception("lzma stream is too short");
|
||
long fileLength = BitConverter.ToInt64(fileLengthBytes, 0);
|
||
|
||
// Decode
|
||
decoder.Code(inputStream, outputStream, -1, fileLength, null);
|
||
}
|
||
} |