private void ReadChunk() { long outSize; byte[] lzmaProperties; try { lzmaProperties = SevenZipExtractor.GetLzmaProperties(this._Input, out outSize); } catch (LzmaException ex) { this._Error = true; return; } if (!this._FirstChunkRead) { this._CommonProperties = lzmaProperties; } if ((int)this._CommonProperties[0] != (int)lzmaProperties[0] || (int)this._CommonProperties[1] != (int)lzmaProperties[1] || ((int)this._CommonProperties[2] != (int)lzmaProperties[2] || (int)this._CommonProperties[3] != (int)lzmaProperties[3]) || (int)this._CommonProperties[4] != (int)lzmaProperties[4]) { this._Error = true; } else { if (this._Buffer.Capacity < (int)outSize) { this._Buffer.Capacity = (int)outSize; } this._Buffer.SetLength(outSize); this._Decoder.SetDecoderProperties(lzmaProperties); this._Buffer.Position = 0L; this._Decoder.Code(this._Input, (Stream)this._Buffer, 0L, outSize, (ICodeProgress)null); this._Buffer.Position = 0L; } }
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."); } Decoder decoder = new Decoder(); long inSize = (inLength.HasValue ? (long)inLength.Value : inStream.Length) - inStream.Position; long outSize; decoder.SetDecoderProperties(SevenZipExtractor.GetLzmaProperties(inStream, out outSize)); decoder.Code(inStream, outStream, inSize, outSize, (ICodeProgress) new LzmaProgressCallback(inSize, codeProgressEvent)); }
public static byte[] ExtractBytes(byte[] data) { using (MemoryStream memoryStream1 = new MemoryStream(data)) { Decoder decoder = new Decoder(); memoryStream1.Seek(0L, SeekOrigin.Begin); using (MemoryStream memoryStream2 = new MemoryStream()) { long outSize; decoder.SetDecoderProperties(SevenZipExtractor.GetLzmaProperties((Stream)memoryStream1, out outSize)); decoder.Code((Stream)memoryStream1, (Stream)memoryStream2, memoryStream1.Length - memoryStream1.Position, outSize, (ICodeProgress)null); return(memoryStream2.ToArray()); } } }