LZMA.cs 984 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.IO;
  2. using SevenZip.Compression.LZMA;
  3. namespace MeidoPhotoStudio.Converter.Utility
  4. {
  5. internal static class LZMA
  6. {
  7. public static MemoryStream Decompress(Stream inStream)
  8. {
  9. var outStream = new MemoryStream();
  10. var properties = new byte[5];
  11. if (inStream.Read(properties, 0, 5) != 5)
  12. throw new("input .lzma is too short");
  13. var decoder = new Decoder();
  14. decoder.SetDecoderProperties(properties);
  15. var outSize = 0L;
  16. for (var i = 0; i < 8; i++)
  17. {
  18. var v = inStream.ReadByte();
  19. if (v < 0)
  20. throw new("Can't Read 1");
  21. outSize |= ((long)(byte)v) << (8 * i);
  22. }
  23. var compressedSize = inStream.Length - inStream.Position;
  24. decoder.Code(inStream, outStream, compressedSize, outSize, null);
  25. return outStream;
  26. }
  27. }
  28. }