mlaumcherb/Млаумчерб.Клиент/LZMACompressor.cs
2024-11-04 01:45:06 +05:00

26 lines
960 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}