Пример #1
0
 /// <summary>
 /// Decompress byte array compressed with LZMA algorithm (C# inside)
 /// </summary>
 /// <param name="data">Byte array to decompress</param>
 /// <returns>Decompressed byte array</returns>
 public static byte[] ExtractBytes(byte[] data)
 {
     using (var inStream = new MemoryStream(data))
     {
         var decoder = new Decoder();
         inStream.Seek(0, 0);
         using (var outStream = new MemoryStream())
         {
             long outSize;
             decoder.SetDecoderProperties(GetLzmaProperties(inStream, out outSize));
             decoder.Code(inStream, outStream, inStream.Length - inStream.Position, outSize, null);
             return outStream.ToArray();
         }
     }
 }
Пример #2
0
 /// <summary>
 /// Decompress the specified stream (C# inside)
 /// </summary>
 /// <param name="inStream">The source compressed stream</param>
 /// <param name="outStream">The destination uncompressed stream</param>
 /// <param name="inLength">The length of compressed data (null for inStream.Length)</param>
 /// <param name="codeProgressEvent">The event for handling the code progress</param>
 public static void DecompressStream(Stream inStream, Stream outStream, int? inLength,
                                     EventHandler<ProgressEventArgs> codeProgressEvent)
 {
     if (!inStream.CanRead || !outStream.CanWrite)
     {
         throw new ArgumentException("The specified streams are invalid.");
     }
     var decoder = new Decoder();
     long outSize, inSize = (inLength.HasValue ? inLength.Value : inStream.Length) - inStream.Position;
     decoder.SetDecoderProperties(GetLzmaProperties(inStream, out outSize));
     decoder.Code(
         inStream, outStream, inSize, outSize,
         new LzmaProgressCallback(inSize, codeProgressEvent));
 }