mlaumcherb/Mlaumcherb.Client.Avalonia/холопы/LZMAHelper.cs
2024-11-06 00:04:12 +05:00

26 lines
964 B
C#
Raw Permalink 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 Mlaumcherb.Client.Avalonia.холопы;
/// <summary>
/// https://gist.github.com/ststeiger/cb9750664952f775a341
/// </summary>
public static class LZMAHelper
{
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);
}
}