/// <summary> /// 从压缩包解压某文件到内存 /// </summary> /// <param name="fileName">文件名</param> /// <param name="progress">解压进度回调对象</param> /// <returns></returns> public MemoryStream OpenFile(string fileName, ICodeProgress progress) { lock (hashTable) { MemoryStream ms = new MemoryStream(); fileStream.Position = hashTable[fileName]; LpkFileInfo fileInfo = new LpkFileInfo(fileStream); fileStream.Position = fileInfo.DataOffset; try { LZMA.LzmaHelper.Decompress(fileStream, ms, fileInfo.FileSize, fileInfo.UncompressedSize, progress); } catch (Exception ex) { Logger.Log.Error(ex); throw new Exception(string.Format("File:{1} CRC({0:X}) error, file open failed!", fileInfo.CRC, fileName)); } ms.Position = 0; uint crc = LZMA.LzmaHelper.CRC32(ms); if (fileInfo.CRC != crc) { throw new Exception(string.Format("CRC(Original:{0:X} Current:{1:X}) error, file open failed!", fileInfo.CRC, crc)); } ms.Position = 0; return(ms); } }
/// <summary> /// Decompresses the given stream and writes to the output stream. /// </summary> /// <param name="newInStream">The input stream.</param> /// <param name="newOutStream">The output stream.</param> /// <param name="progress">The progress callback, if desired.</param> public static void Decompress(Stream newInStream, Stream newOutStream, ICodeProgress progress = null) { lock (m_DecoderLock) { if (m_Decoder == null) { m_Decoder = new LzmaDecoder(); } if (m_DecoderProps == null) { m_DecoderProps = new byte[5]; } if (newInStream.Read(m_DecoderProps, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = newInStream.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } m_Decoder.SetDecoderProperties(m_DecoderProps); long compressedSize = newInStream.Length - newInStream.Position; m_Decoder.Code(newInStream, newOutStream, compressedSize, outSize, progress); } }
public void Code(Stream inStream, Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { if (_outWindow is null) { CreateDictionary(); } _outWindow.Init(outStream); if (outSize > 0) { _outWindow.SetLimit(outSize); } else { _outWindow.SetLimit(Int64.MaxValue - _outWindow._total); } RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder(); rangeDecoder.Init(inStream); Code(_dictionarySize, _outWindow, rangeDecoder); _outWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); _outWindow = null; }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { if (this.m_OutWindow == null) { this.CreateDictionary(); } this.m_OutWindow.Init(outStream); if (outSize > 0L) { this.m_OutWindow.SetLimit(outSize); } else { this.m_OutWindow.SetLimit(0x7fffffffffffffffL - this.m_OutWindow.Total); } SharpCompress.Compressor.LZMA.RangeCoder.Decoder rangeDecoder = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder(); rangeDecoder.Init(inStream); this.Code(this.m_DictionarySize, this.m_OutWindow, rangeDecoder); this.m_OutWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); if (!(rangeDecoder.IsFinished && ((inSize <= 0L) || (rangeDecoder.Total == inSize)))) { throw new DataErrorException(); } if (this.m_OutWindow.HasPending) { throw new DataErrorException(); } this.m_OutWindow = null; }
public static void Decompress(Stream newInStream, Stream newOutStream, ICodeProgress progress = null) { lock (m_DecoderLock) { if (m_Decoder == null) { m_Decoder = new LzmaDecoder(); } if (m_DecoderProps == null) { m_DecoderProps = new byte[5]; } if (newInStream.Read(m_DecoderProps, 0, 5) != 5) throw (new Exception("input .lzma is too short")); long outSize = 0; for (int i = 0; i < 8; i++) { int v = newInStream.ReadByte(); if (v < 0) throw (new Exception("Can't Read 1")); outSize |= ((long)(byte)v) << (8 * i); } m_Decoder.SetDecoderProperties(m_DecoderProps); long compressedSize = newInStream.Length - newInStream.Position; m_Decoder.Code(newInStream, newOutStream, compressedSize, outSize, progress); } }
/// <summary> /// Constructor, initializes the thread /// </summary> /// <param name="input">Input stream containing the data to be decompressed</param> /// <param name="output">Output stream the decompressed data should be written to</param> /// <param name="dataSize">Size of output data</param> /// <param name="properties">Decoder properties (read from a .7z file), or <c>null</c> if none specified</param> /// <param name="progress">An interface for reporting progress notifications</param> /// <param name="errorHandler">Handler for errors during decompression</param> public DecodingThread(Stream input, Stream output, long dataSize, byte[] properties, ICodeProgress progress, ErrorHandler errorHandler) { if (input == null) { throw new ArgumentNullException("input"); } if (output == null) { throw new ArgumentNullException("output"); } if (!input.CanRead) { throw new ArgumentException(LibraryResources.ReadableStreamRequired, "input"); } if (!output.CanWrite) { throw new ArgumentException(LibraryResources.WritableStreamRequired, "output"); } this.input = input; this.output = output; this.dataSize = dataSize; decoder = new Decoder(); if (properties != null) { decoder.SetDecoderProperties(properties); } this.progress = progress; this.errorHandler = errorHandler; }
public void Code(System.IO.Stream inStream, System.IO.Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { if (m_OutWindow == null) CreateDictionary(); m_OutWindow.Init(outStream); if (outSize > 0) m_OutWindow.SetLimit(outSize); else m_OutWindow.SetLimit(Int64.MaxValue - m_OutWindow.Total); RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder(); rangeDecoder.Init(inStream); Code(m_DictionarySize, m_OutWindow, rangeDecoder); m_OutWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); if (!rangeDecoder.IsFinished || (inSize > 0 && rangeDecoder.Total != inSize)) throw new DataErrorException(); if (m_OutWindow.HasPending) throw new DataErrorException(); m_OutWindow = null; }
public static byte[] Decompress(byte[] inputBytes, ICodeProgress progress) { MemoryStream newInStream = new MemoryStream(inputBytes); SevenZipRadical.Compression.LZMA.Decoder decoder = new SevenZipRadical.Compression.LZMA.Decoder(); newInStream.Seek(0, 0); MemoryStream newOutStream = new MemoryStream(); byte[] properties2 = new byte[5]; if (newInStream.Read(properties2, 0, 5) != 5) throw (new Exception("input .lzma is too short")); long outSize = 0; for (int i = 0; i < 8; i++) { int v = newInStream.ReadByte(); if (v < 0) throw (new Exception("Can't Read 1")); outSize |= ((long)(byte)v) << (8 * i); } decoder.SetDecoderProperties(properties2); long compressedSize = dataProcessingSize = newInStream.Length - newInStream.Position; decoder.Code(newInStream, newOutStream, compressedSize, outSize, progress); byte[] b = newOutStream.ToArray(); return b; }
public static void Decompress(Stream input, Stream output, Action <long, long> onProgress = null) { var decoder = new Decoder(); byte[] properties = new byte[5]; if (input.Read(properties, 0, 5) != 5) { throw new Exception("input .lzma is too short"); } decoder.SetDecoderProperties(properties); long fileLength = 0; for (int i = 0; i < 8; i++) { int v = input.ReadByte(); if (v < 0) { throw new Exception("Can't Read 1"); } fileLength |= ((long)(byte)v) << (8 * i); } ICodeProgress prg = null; if (onProgress != null) { prg = new DelegateCodeProgress(onProgress); } long compressedSize = input.Length - input.Position; decoder.Code(input, output, compressedSize, fileLength, prg); }
public void Code(System.IO.Stream inStream, System.IO.Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { if (m_OutWindow == null) { CreateDictionary(); } m_OutWindow.Init(outStream); if (outSize > 0) { m_OutWindow.SetLimit(outSize); } else { m_OutWindow.SetLimit(Int64.MaxValue - m_OutWindow.Total); } RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder(); rangeDecoder.Init(inStream); Code(m_DictionarySize, m_OutWindow, rangeDecoder); m_OutWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); if (!rangeDecoder.IsFinished || (inSize > 0 && rangeDecoder.Total != inSize)) { throw new DataErrorException(); } if (m_OutWindow.HasPending) { throw new DataErrorException(); } m_OutWindow = null; }
public void Code(Stream inStream, Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { if (_outWindow is null) { CreateDictionary(); } _outWindow.Init(outStream); if (outSize > 0) { _outWindow.SetLimit(outSize); } else { _outWindow.SetLimit(Int64.MaxValue - _outWindow._total); } RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder(); rangeDecoder.Init(inStream); Code(_dictionarySize, _outWindow, rangeDecoder); _outWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); if (!rangeDecoder.IsFinished || (inSize > 0 && rangeDecoder._total != inSize)) { throw new DataErrorException(); } if (_outWindow.HasPending) { throw new DataErrorException(); } _outWindow = null; }
public static void Compress(Stream inStream, Stream outStream, ICodeProgress progress) { SevenZip.Compression.LZMA.Encoder encoder = new SevenZip.Compression.LZMA.Encoder(); encoder.SetCoderProperties(propIDs, properties); //encoder.WriteCoderProperties(outStream); encoder.Code(inStream, outStream, -1, -1, progress); }
public static byte[] Decompress(byte[] inputBytes, ICodeProgress progress) { MemoryStream newInStream = new MemoryStream(inputBytes); SevenZipRadical.Compression.LZMA.Decoder decoder = new SevenZipRadical.Compression.LZMA.Decoder(); newInStream.Seek(0, 0); MemoryStream newOutStream = new MemoryStream(); byte[] properties2 = new byte[5]; if (newInStream.Read(properties2, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = newInStream.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } decoder.SetDecoderProperties(properties2); long compressedSize = dataProcessingSize = newInStream.Length - newInStream.Position; decoder.Code(newInStream, newOutStream, compressedSize, outSize, progress); byte[] b = newOutStream.ToArray(); return(b); }
public static byte[] Compress(byte[] inputBytes, ICodeProgress progress) { MemoryStream inStream = new MemoryStream(inputBytes); MemoryStream outStream = new MemoryStream(); SevenZipRadical.Compression.LZMA.Encoder encoder = new SevenZipRadical.Compression.LZMA.Encoder(); encoder.SetCoderProperties(propIDs, properties); encoder.WriteCoderProperties(outStream); long fileSize = dataProcessingSize = inStream.Length; for (int i = 0; i < 8; i++) outStream.WriteByte((Byte)(fileSize >> (8 * i))); encoder.Code(inStream, outStream, -1, -1, progress); return outStream.ToArray(); }
/// <inheritdoc /> public byte[] Compress(byte[] data, Action <double> progressFunc = null) { CoderPropID[] propIDs = { CoderPropID.DictionarySize, CoderPropID.PosStateBits, CoderPropID.LitContextBits, CoderPropID.LitPosBits, CoderPropID.Algorithm, CoderPropID.NumFastBytes, CoderPropID.MatchFinder, CoderPropID.EndMarker }; object[] properties = { 1 << 23, 2, 3, 0, 2, 128, "bt4", false }; var x = new MemoryStream(); var encoder = new Encoder(); encoder.SetCoderProperties(propIDs, properties); encoder.WriteCoderProperties(x); var length = BitConverter.GetBytes(data.Length); if (!BitConverter.IsLittleEndian) { Array.Reverse(length); } // Store 4 byte length value (little-endian) x.Write(length, 0, sizeof(int)); ICodeProgress progress = null; if (progressFunc != null) { progress = new CompressionLogger(progressFunc, data.Length); } encoder.Code(new MemoryStream(data), x, -1, -1, progress); return(x.ToArray()); }
public static void Compress(Stream input, Stream output, LzmaSpeed speed = LzmaSpeed.Fastest, DictionarySize dictionarySize = DictionarySize.VerySmall, Action <long, long> onProgress = null) { int posStateBits = 2; // default: 2 int litContextBits = 3; // 3 for normal files, 0; for 32-bit data int litPosBits = 0; // 0 for 64-bit data, 2 for 32-bit. var numFastBytes = (int)speed; string matchFinder = "BT4"; // default: BT4 bool endMarker = true; CoderPropID[] propIDs = { CoderPropID.DictionarySize, CoderPropID.PosStateBits, // (0 <= x <= 4). CoderPropID.LitContextBits, // (0 <= x <= 8). CoderPropID.LitPosBits, // (0 <= x <= 4). CoderPropID.NumFastBytes, CoderPropID.MatchFinder, // "BT2", "BT4". CoderPropID.EndMarker }; object[] properties = { (int)dictionarySize, posStateBits, litContextBits, litPosBits, numFastBytes, matchFinder, endMarker }; var lzmaEncoder = new Encoder(); lzmaEncoder.SetCoderProperties(propIDs, properties); lzmaEncoder.WriteCoderProperties(output); var fileSize = input.Length; for (int i = 0; i < 8; i++) { output.WriteByte((byte)(fileSize >> (8 * i))); } ICodeProgress prg = null; if (onProgress != null) { prg = new DelegateCodeProgress(onProgress); } lzmaEncoder.Code(input, output, -1, -1, prg); }
/// <inheritdoc /> public byte[] Compress(byte[] data, Action <double> progressFunc = null) { CoderPropID[] propIDs = { CoderPropID.DictionarySize, CoderPropID.PosStateBits, CoderPropID.LitContextBits, CoderPropID.LitPosBits, CoderPropID.Algorithm, CoderPropID.NumFastBytes, CoderPropID.MatchFinder, CoderPropID.EndMarker }; object[] properties = { 1 << 23, 2, 3, 0, 2, 128, "bt4", false }; var x = new MemoryStream(); var encoder = new Encoder(); encoder.SetCoderProperties(propIDs, properties); encoder.WriteCoderProperties(x); Int64 fileSize; fileSize = data.Length; for (var i = 0; i < 8; i++) { x.WriteByte((Byte)(fileSize >> (8 * i))); } ICodeProgress progress = null; if (progressFunc != null) { progress = new CompressionLogger(progressFunc, data.Length); } encoder.Code(new MemoryStream(data), x, -1, -1, progress); return(x.ToArray()); }
public static void Compress(Stream inStream, Stream outStream, ICodeProgress progress = null) { lock (m_EncoderLock) { if (m_Encoder == null) { m_Encoder = new LzmaEncoder(); m_Encoder.SetCoderProperties(propIDs, properties); } m_Encoder.WriteCoderProperties(outStream); long fileSize = inStream.Length; for (int i = 0; i < 8; i++) outStream.WriteByte((Byte)(fileSize >> (8 * i))); m_Encoder.Code(inStream, outStream, -1, -1, progress); } }
public static byte[] Compress(byte[] inputBytes, ICodeProgress progress) { MemoryStream inStream = new MemoryStream(inputBytes); MemoryStream outStream = new MemoryStream(); SevenZipRadical.Compression.LZMA.Encoder encoder = new SevenZipRadical.Compression.LZMA.Encoder(); encoder.SetCoderProperties(propIDs, properties); encoder.WriteCoderProperties(outStream); long fileSize = dataProcessingSize = inStream.Length; for (int i = 0; i < 8; i++) { outStream.WriteByte((Byte)(fileSize >> (8 * i))); } encoder.Code(inStream, outStream, -1, -1, progress); return(outStream.ToArray()); }
/// <summary> /// Compresses the given stream and writes to the output stream. /// </summary> /// <param name="inStream">The input stream.</param> /// <param name="outStream">The output stream.</param> /// <param name="progress">The progress callback, if desired.</param> public static void Compress(Stream inStream, Stream outStream, ICodeProgress progress = null) { lock (m_EncoderLock) { if (m_Encoder == null) { m_Encoder = new LzmaEncoder(); m_Encoder.SetCoderProperties(propIDs, properties); } m_Encoder.WriteCoderProperties(outStream); long fileSize = inStream.Length; for (int i = 0; i < 8; i++) { outStream.WriteByte((Byte)(fileSize >> (8 * i))); } m_Encoder.Code(inStream, outStream, -1, -1, progress); } }
/// <summary> /// 压缩byte[]数据,输出byte[] /// </summary> /// <param name="buff"></param> /// <param name="progress"></param> /// <returns></returns> public static byte[] Encode(byte[] buff, ICodeProgress progress = null) { //使用压缩Encoder Encoder coder = new Encoder(); using (MemoryStream instream = new MemoryStream(buff)) using (MemoryStream outstream = new MemoryStream()) { //写入5字节coder属性 coder.WriteCoderProperties(outstream); //写入4字节,压缩文件的长度 outstream.Write(BitConverter.GetBytes(buff.Length), 0, 4); //压缩数据,属性和长度可以看出没被压缩,内容才被压缩 coder.Code(instream, outstream, instream.Length, -1, progress); buff = outstream.ToArray(); outstream.Close(); } return(buff); }
private void CloseWriting7Zip(ICodeProgress p = null) { if (_compressed) { _lzmaStream.Close(); } _packStreamSize = (UInt64)_zipFs.Position - _packStreamStart; Create7ZStructure(); byte[] newHeaderByte; using (Stream headerMem = new MemoryStream()) { using (BinaryWriter headerBw = new BinaryWriter(headerMem)) { _header.WriteHeader(headerBw); newHeaderByte = new byte[headerMem.Length]; headerMem.Position = 0; headerMem.Read(newHeaderByte, 0, newHeaderByte.Length); } } CRC mainHeadercrc = new CRC(); mainHeadercrc.Update(newHeaderByte, 0, (uint)newHeaderByte.Length); UInt32 mainHeaderCRC = mainHeadercrc.GetDigest(); UInt64 headerpos = (UInt64)_zipFs.Position; BinaryWriter bw = new BinaryWriter(_zipFs); bw.Write(newHeaderByte); _signatureHeader.WriteFinal(bw, headerpos, (ulong)newHeaderByte.Length, mainHeaderCRC); WriteRomVault7Zip(bw, headerpos, (ulong)newHeaderByte.Length, mainHeaderCRC); _zipFs.Flush(); _zipFs.Close(); _zipFs.Dispose(); }
/// <summary> /// 压缩文件 /// </summary> /// <param name="buff"></param> /// <param name="progress"></param> /// <returns></returns> public static void Encode(string inFile, string outFlie, ICodeProgress progress = null) { Encoder coder = new Encoder(); using (FileStream inFileStream = new FileStream(inFile, FileMode.Open)) using (FileStream outFileStream = new FileStream(outFlie, FileMode.Create)) { //先写入压缩属性,5字节 coder.WriteCoderProperties(outFileStream); //再写入长度,4字节 byte[] buff = BitConverter.GetBytes((int)inFileStream.Length); outFileStream.Write(buff, 0, 4); //压缩文件 coder.Code(inFileStream, outFileStream, inFileStream.Length, -1, progress); //将压缩好的流转入存储文件 outFileStream.Flush(); //收尾 outFileStream.Close(); inFileStream.Close(); } }
public static void Decompress(Stream input, string dst, ICodeProgress progress) { Decoder decoder = new Decoder(); FileStream output = new FileStream(dst, FileMode.Create); byte[] byteLength = new byte[sizeof(int)]; input.Read(byteLength, 0, sizeof(int)); int lenProp = BitConverter.ToInt32(byteLength, 0); byte[] properties = new byte[lenProp]; input.Read(properties, 0, lenProp); byteLength = new byte[sizeof(long)]; input.Read(byteLength, 0, sizeof(long)); long len = BitConverter.ToInt64(byteLength, 0); decoder.SetDecoderProperties(properties); decoder.Code(input, output, input.Length, len, progress); output.Close(); }
public static byte[] Decompress(string data, ICodeProgress progress) { byte[] output = null; if(data.StartsWith("ZipStream:")) { var m = new MemoryStream(Convert.FromBase64String(data.Substring(10))); var z = new InflaterInputStream(m); var br = new BinaryReader(m); var length = br.ReadInt32(); output = new byte[length]; z.Read(output, 0, length); z.Close(); m.Close(); } else { return SevenZipRadical.Compression.LZMA.SevenZipRadicalHelper.Decompress(Convert.FromBase64String(data), progress); } return output; }
public static string Compress(byte[] data, ICodeProgress progress) { using(var m = new MemoryStream()) { switch(technique) { case "ZipStream": var br = new BinaryWriter(m); var z = new DeflaterOutputStream(m); br.Write(data.Length); z.Write(data, 0, data.Length); z.Flush(); z.Close(); break; case "7Zip": default: return Convert.ToBase64String(SevenZipRadical.Compression.LZMA.SevenZipRadicalHelper.Compress(data, progress)); } return technique + ":" + Convert.ToBase64String(m.GetBuffer()); } }
/// <summary> /// 解压byte[]数据,输出byte[] /// </summary> /// <param name="buff"></param> /// <param name="progress"></param> /// <returns></returns> public static byte[] Decode(byte[] buff, ICodeProgress progress = null) { //使用解压Decoder Decoder coder = new Decoder(); using (MemoryStream intStream = new MemoryStream(buff)) using (MemoryStream outStream = new MemoryStream()) { //先读出属性,5个字节 byte[] progressBytes = new byte[5]; intStream.Read(progressBytes, 0, 5); //再读出长度,4个字节 byte[] len = new byte[4]; intStream.Read(len, 0, 4); //设置解压属性 coder.SetDecoderProperties(progressBytes); //解压 coder.Code(intStream, outStream, intStream.Length, BitConverter.ToInt32(len, 0), progress); buff = outStream.ToArray(); outStream.Close(); intStream.Close(); } return(buff); }
/// <summary> /// 解压文件 /// </summary> /// <param name="buff"></param> /// <param name="progress"></param> /// <returns></returns> public static void Decode(string inFile, string outFlie, ICodeProgress progress = null) { Decoder coder = new Decoder(); using (FileStream inFileStream = new FileStream(inFile, FileMode.Open)) using (FileStream outFileStream = new FileStream(outFlie, FileMode.Create)) { //先读出属性,设置属性 byte[] progressBytes = new byte[5]; outFileStream.Read(progressBytes, 0, 5); coder.SetDecoderProperties(progressBytes); //再读出长度 byte[] len = new byte[4]; outFileStream.Read(len, 0, 4); //最后读出内容 coder.Code(inFileStream, outFileStream, inFileStream.Length, BitConverter.ToUInt16(len, 0), progress); //内容存到文件 outFileStream.Flush(); //收尾 outFileStream.Close(); inFileStream.Close(); } }
public void ZipFileClose(ICodeProgress p) { if (_zipOpen == ZipOpenType.Closed) { return; } if (_zipOpen == ZipOpenType.OpenRead) { ZipFileCloseReadStream(); if (_zipFs != null) { _zipFs.Close(); _zipFs.Dispose(); } _zipOpen = ZipOpenType.Closed; return; } CloseWriting7Zip(p); _zipFileInfo = new IO.FileInfo(_zipFileInfo.FullName); _zipOpen = ZipOpenType.Closed; }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { //outStream.ReadByte(); if (outSize > 0) { outStream.SetLength(outSize); } using (ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream DStream = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(inStream)) { DStream.CopyTo(outStream);// incompatibilité avec zlib } /* * System.IO.Compression.GZipStream DStream = new System.IO.Compression.GZipStream(inStream, System.IO.Compression.CompressionMode.Decompress,true); * outStream=DStream; */ }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { Init(inStream, outStream); var state = new Base.State(); state.Init(); uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; ulong nowPos64 = 0; var outSize64 = (ulong)outSize; if (nowPos64 < outSize64) { if (_mIsMatchDecoders[state.Index << Base.KNumPosStatesBitsMax].Decode(_mRangeDecoder) != 0) { throw new DataErrorException(); } state.UpdateChar(); var b = _mLiteralDecoder.DecodeNormal(_mRangeDecoder, 0, 0); _mOutWindow.PutByte(b); nowPos64++; } while (nowPos64 < outSize64) // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); // while(nowPos64 < next) { var posState = (uint)nowPos64 & _mPosStateMask; if (_mIsMatchDecoders[(state.Index << Base.KNumPosStatesBitsMax) + posState].Decode(_mRangeDecoder) == 0) { byte b; var prevByte = _mOutWindow.GetByte(0); if (!state.IsCharState()) { b = _mLiteralDecoder.DecodeWithMatchByte(_mRangeDecoder, (uint)nowPos64, prevByte, _mOutWindow.GetByte(rep0)); } else { b = _mLiteralDecoder.DecodeNormal(_mRangeDecoder, (uint)nowPos64, prevByte); } _mOutWindow.PutByte(b); state.UpdateChar(); nowPos64++; } else { uint len; if (_mIsRepDecoders[state.Index].Decode(_mRangeDecoder) == 1) { if (_mIsRepG0Decoders[state.Index].Decode(_mRangeDecoder) == 0) { if ( _mIsRep0LongDecoders[(state.Index << Base.KNumPosStatesBitsMax) + posState].Decode( _mRangeDecoder) == 0) { state.UpdateShortRep(); _mOutWindow.PutByte(_mOutWindow.GetByte(rep0)); nowPos64++; continue; } } else { uint distance; if (_mIsRepG1Decoders[state.Index].Decode(_mRangeDecoder) == 0) { distance = rep1; } else { if (_mIsRepG2Decoders[state.Index].Decode(_mRangeDecoder) == 0) { distance = rep2; } else { distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } len = _mRepLenDecoder.Decode(_mRangeDecoder, posState) + Base.KMatchMinLen; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; len = Base.KMatchMinLen + _mLenDecoder.Decode(_mRangeDecoder, posState); state.UpdateMatch(); var posSlot = _mPosSlotDecoder[Base.GetLenToPosState(len)].Decode(_mRangeDecoder); if (posSlot >= Base.KStartPosModelIndex) { var numDirectBits = (int)((posSlot >> 1) - 1); rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < Base.KEndPosModelIndex) { rep0 += BitTreeDecoder.ReverseDecode(_mPosDecoders, rep0 - posSlot - 1, _mRangeDecoder, numDirectBits); } else { rep0 += (_mRangeDecoder.DecodeDirectBits( numDirectBits - Base.KNumAlignBits) << Base.KNumAlignBits); rep0 += _mPosAlignDecoder.ReverseDecode(_mRangeDecoder); } } else { rep0 = posSlot; } } if (rep0 >= _mOutWindow.TrainSize + nowPos64 || rep0 >= _mDictionarySizeCheck) { if (rep0 == 0xFFFFFFFF) { break; } throw new DataErrorException(); } _mOutWindow.CopyBlock(rep0, len); nowPos64 += len; } } _mOutWindow.Flush(); _mOutWindow.ReleaseStream(); _mRangeDecoder.ReleaseStream(); }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { this._needReleaseMFStream = false; this._processingMode = false; try { long num; long num2; bool flag; bool flag2; this.SetStreams(inStream, outStream, inSize, outSize); goto Label_004C; Label_001E: this.CodeOneBlock(out num, out num2, out flag); if (flag) { return; } if (progress != null) { progress.SetProgress(num, num2); } Label_004C: flag2 = true; goto Label_001E; } finally { this.ReleaseStreams(); } }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { using (System.IO.Compression.DeflateStream DStream = new System.IO.Compression.DeflateStream(outStream, System.IO.Compression.CompressionLevel.Fastest, true)) { if (inSize > 0) { inStream.CopyTo(DStream, (int)inSize); } else { inStream.CopyTo(DStream); } } }
// Token: 0x06002203 RID: 8707 RVA: 0x0040482C File Offset: 0x00402A2C public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { }
public void Code(System.IO.Stream inStream, System.IO.Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { Init(inStream, outStream); Base.State state = new Base.State(); state.Init(); uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; UInt64 nowPos64 = 0; UInt64 outSize64 = (UInt64)outSize; if (nowPos64 < outSize64) { if (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0) { throw new DataErrorException(); } state.UpdateChar(); byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0); m_OutWindow.PutByte(b); nowPos64++; } while (nowPos64 < outSize64) { // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); // while(nowPos64 < next) { uint posState = (uint)nowPos64 & m_PosStateMask; if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { byte b; byte prevByte = m_OutWindow.GetByte(0); if (!state.IsCharState()) { b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, (uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0)); } else { b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte); } m_OutWindow.PutByte(b); state.UpdateChar(); nowPos64++; } else { uint len; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { if (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { state.UpdateShortRep(); m_OutWindow.PutByte(m_OutWindow.GetByte(rep0)); nowPos64++; continue; } } else { UInt32 distance; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep1; } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep2; } else { distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; len = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState); state.UpdateMatch(); uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder); if (posSlot >= Base.kStartPosModelIndex) { int numDirectBits = (int)((posSlot >> 1) - 1); rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < Base.kEndPosModelIndex) { rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders, rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); } else { rep0 += (m_RangeDecoder.DecodeDirectBits( numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits); rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } } else { rep0 = posSlot; } } if (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck) { if (rep0 == 0xFFFFFFFF) { break; } throw new DataErrorException(); } m_OutWindow.CopyBlock(rep0, len); nowPos64 += len; } if (progress != null) { progress.SetProgress((long)nowPos64, (long)inSize); } } } m_OutWindow.Flush(); m_OutWindow.ReleaseStream(); m_RangeDecoder.ReleaseStream(); }
// Token: 0x06002204 RID: 8708 RVA: 0x00404830 File Offset: 0x00402A30 public IEnumerator Decode(Stream inStream, Stream outStream, long inSize, long outSize, uint roundSize, ICodeProgress progress) { this.Init(inStream, outStream); Base.State state = default(Base.State); state.Init(); uint rep0 = 0u; uint rep = 0u; uint rep2 = 0u; uint rep3 = 0u; uint runs = 0u; ulong nowPos64 = 0UL; if (nowPos64 < (ulong)outSize) { if (this.m_IsMatchDecoders[(int)((UIntPtr)(state.Index << 4))].Decode(this.m_RangeDecoder) != 0u) { throw new DataErrorException(); } state.UpdateChar(); byte b = this.m_LiteralDecoder.DecodeNormal(this.m_RangeDecoder, 0u, 0); this.m_OutWindow.PutByte(b); nowPos64 += 1UL; } while (nowPos64 < (ulong)outSize) { runs += 1u; uint posState = (uint)nowPos64 & this.m_PosStateMask; if (this.m_IsMatchDecoders[(int)((UIntPtr)((state.Index << 4) + posState))].Decode(this.m_RangeDecoder) == 0u) { byte prevByte = this.m_OutWindow.GetByte(0u); byte b2; if (!state.IsCharState()) { b2 = this.m_LiteralDecoder.DecodeWithMatchByte(this.m_RangeDecoder, (uint)nowPos64, prevByte, this.m_OutWindow.GetByte(rep0)); } else { b2 = this.m_LiteralDecoder.DecodeNormal(this.m_RangeDecoder, (uint)nowPos64, prevByte); } this.m_OutWindow.PutByte(b2); state.UpdateChar(); nowPos64 += 1UL; } else { uint len; if (this.m_IsRepDecoders[(int)((UIntPtr)state.Index)].Decode(this.m_RangeDecoder) == 1u) { if (this.m_IsRepG0Decoders[(int)((UIntPtr)state.Index)].Decode(this.m_RangeDecoder) == 0u) { if (this.m_IsRep0LongDecoders[(int)((UIntPtr)((state.Index << 4) + posState))].Decode(this.m_RangeDecoder) == 0u) { state.UpdateShortRep(); this.m_OutWindow.PutByte(this.m_OutWindow.GetByte(rep0)); nowPos64 += 1UL; continue; } } else { uint distance; if (this.m_IsRepG1Decoders[(int)((UIntPtr)state.Index)].Decode(this.m_RangeDecoder) == 0u) { distance = rep; } else { if (this.m_IsRepG2Decoders[(int)((UIntPtr)state.Index)].Decode(this.m_RangeDecoder) == 0u) { distance = rep2; } else { distance = rep3; rep3 = rep2; } rep2 = rep; } rep = rep0; rep0 = distance; } len = this.m_RepLenDecoder.Decode(this.m_RangeDecoder, posState) + 2u; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep; rep = rep0; len = 2u + this.m_LenDecoder.Decode(this.m_RangeDecoder, posState); state.UpdateMatch(); uint posSlot = this.m_PosSlotDecoder[(int)((UIntPtr)Base.GetLenToPosState(len))].Decode(this.m_RangeDecoder); if (posSlot >= 4u) { int numDirectBits = (int)((posSlot >> 1) - 1u); rep0 = (2u | (posSlot & 1u)) << numDirectBits; if (posSlot < 14u) { rep0 += BitTreeDecoder.ReverseDecode(this.m_PosDecoders, rep0 - posSlot - 1u, this.m_RangeDecoder, numDirectBits); } else { rep0 += this.m_RangeDecoder.DecodeDirectBits(numDirectBits - 4) << 4; rep0 += this.m_PosAlignDecoder.ReverseDecode(this.m_RangeDecoder); } } else { rep0 = posSlot; } } if ((ulong)rep0 >= (ulong)this.m_OutWindow.TrainSize + nowPos64 || rep0 >= this.m_DictionarySizeCheck) { if (rep0 == 4294967295u) { break; } throw new DataErrorException(); } else { this.m_OutWindow.CopyBlock(rep0, len); nowPos64 += (ulong)len; } } if (runs > roundSize) { if (progress != null) { progress.SetProgress((long)nowPos64, outSize); } runs = 0u; yield return(null); } } this.m_OutWindow.Flush(); this.m_OutWindow.ReleaseStream(); this.m_RangeDecoder.ReleaseStream(); yield break; }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { if (this.m_OutWindow == null) { this.CreateDictionary(); } this.m_OutWindow.Init(outStream); if (outSize > 0L) { this.m_OutWindow.SetLimit(outSize); } else { this.m_OutWindow.SetLimit(0x7fffffffffffffffL - this.m_OutWindow.Total); } Decoder rangeDecoder = new Decoder(); rangeDecoder.Init(inStream); this.Code(this.m_DictionarySize, this.m_OutWindow, rangeDecoder); this.m_OutWindow.ReleaseStream(); rangeDecoder.ReleaseStream(); if (!rangeDecoder.IsFinished || ((inSize > 0L) && (rangeDecoder.Total != inSize))) { throw new DataErrorException(); } if (this.m_OutWindow.HasPending) { throw new DataErrorException(); } this.m_OutWindow = null; }
/// <summary> /// Codes a stream with LZMA algorithm to an output stream /// </summary> /// <param name="inStream">The input stream</param> /// <param name="inSize">The input size</param> /// <param name="outSize">The output size</param> /// <param name="outStream">The output stream</param> /// <param name="progress">Progress interface</param> public void Code(Stream inStream, Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { Init(inStream, outStream); var state = new Base.State(); state.Init(); uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; //Outsize == Int64.MaxValue means this is a streamed LZMA file and we don't know how much we have do. When rep0 is 0xFFFFFFFF we are done decoding. UInt64 nowPos64 = 0; var outSize64 = (UInt64)outSize; if (nowPos64 < outSize64 && outSize != -1) { if (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0) { throw new DataErrorException(); } state.UpdateChar(); byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0); m_OutWindow.PutByte(b); nowPos64++; } while (nowPos64 < outSize64 || outSize == -1) { // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); // while(nowPos64 < next) { uint posState = (uint)nowPos64 & m_PosStateMask; if ( m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { byte b; byte prevByte = m_OutWindow.GetByte(0); if (!state.IsCharState()) { b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, (uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0)); } else { b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte); } m_OutWindow.PutByte(b); state.UpdateChar(); nowPos64++; } else { uint len; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { if ( m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode( m_RangeDecoder) == 0) { state.UpdateShortRep(); m_OutWindow.PutByte(m_OutWindow.GetByte(rep0)); nowPos64++; continue; } } else { UInt32 distance; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep1; } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep2; } else { distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; len = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState); state.UpdateMatch(); uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder); if (posSlot >= Base.kStartPosModelIndex) { var numDirectBits = (int)((posSlot >> 1) - 1); rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < Base.kEndPosModelIndex) { rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders, rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); } else { rep0 += (m_RangeDecoder.DecodeDirectBits( numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits); rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } } else { rep0 = posSlot; } } if (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck) { if (rep0 == 0xFFFFFFFF) //End of file marker { HasFoundEndOfStream = true; break; } throw new DataErrorException(); } m_OutWindow.CopyBlock(rep0, len); nowPos64 += len; } } } m_OutWindow.Flush(); m_OutWindow.ReleaseStream(); m_RangeDecoder.ReleaseStream(); }
public void Code(System.IO.Stream inStream, System.IO.Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { Init(inStream, outStream); Base.State state = new Base.State(); state.Init(); uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; UInt64 nowPos64 = 0; UInt64 outSize64 = (UInt64)outSize; if (nowPos64 < outSize64) { if (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0) throw new DataErrorException(); state.UpdateChar(); byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0); m_OutWindow.PutByte(b); nowPos64++; } while (nowPos64 < outSize64) { // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); // while(nowPos64 < next) { uint posState = (uint)nowPos64 & m_PosStateMask; if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { byte b; byte prevByte = m_OutWindow.GetByte(0); if (!state.IsCharState()) b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, (uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0)); else b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte); m_OutWindow.PutByte(b); state.UpdateChar(); nowPos64++; } else { uint len; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { if (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0) { state.UpdateShortRep(); m_OutWindow.PutByte(m_OutWindow.GetByte(rep0)); nowPos64++; continue; } } else { UInt32 distance; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { distance = rep1; } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) distance = rep2; else { distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; len = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState); state.UpdateMatch(); uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder); if (posSlot >= Base.kStartPosModelIndex) { int numDirectBits = (int)((posSlot >> 1) - 1); rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < Base.kEndPosModelIndex) rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders, rep0 - posSlot - 1, m_RangeDecoder, numDirectBits); else { rep0 += (m_RangeDecoder.DecodeDirectBits( numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits); rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } } else rep0 = posSlot; } if (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck) { if (rep0 == 0xFFFFFFFF) break; throw new DataErrorException(); } m_OutWindow.CopyBlock(rep0, len); nowPos64 += len; } } } m_OutWindow.Flush(); m_OutWindow.ReleaseStream(); m_RangeDecoder.ReleaseStream(); }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { Init(inStream, outStream); Base.State state = default(Base.State); state.Init(); uint num = 0u; uint num2 = 0u; uint num3 = 0u; uint num4 = 0u; ulong num5 = 0uL; if (num5 < (ulong)outSize) { if (m_IsMatchDecoders[state.Index << 4].Decode(m_RangeDecoder) != 0) { throw new DataErrorException(); } state.UpdateChar(); byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0u, 0); m_OutWindow.PutByte(b); num5++; } while (num5 < (ulong)outSize) { uint num6 = (uint)((int)num5 & (int)m_PosStateMask); if (m_IsMatchDecoders[(state.Index << 4) + num6].Decode(m_RangeDecoder) == 0) { byte @byte = m_OutWindow.GetByte(0u); byte b2 = state.IsCharState() ? m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)num5, @byte) : m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder, (uint)num5, @byte, m_OutWindow.GetByte(num)); m_OutWindow.PutByte(b2); state.UpdateChar(); num5++; continue; } uint num8; if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1) { if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0) { if (m_IsRep0LongDecoders[(state.Index << 4) + num6].Decode(m_RangeDecoder) == 0) { state.UpdateShortRep(); m_OutWindow.PutByte(m_OutWindow.GetByte(num)); num5++; continue; } } else { uint num7; if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0) { num7 = num2; } else { if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0) { num7 = num3; } else { num7 = num4; num4 = num3; } num3 = num2; } num2 = num; num = num7; } num8 = m_RepLenDecoder.Decode(m_RangeDecoder, num6) + 2; state.UpdateRep(); } else { num4 = num3; num3 = num2; num2 = num; num8 = 2 + m_LenDecoder.Decode(m_RangeDecoder, num6); state.UpdateMatch(); uint num9 = m_PosSlotDecoder[Base.GetLenToPosState(num8)].Decode(m_RangeDecoder); if (num9 >= 4) { int num10 = (int)((num9 >> 1) - 1); num = (2 | (num9 & 1)) << num10; if (num9 < 14) { num += BitTreeDecoder.ReverseDecode(m_PosDecoders, num - num9 - 1, m_RangeDecoder, num10); } else { num += m_RangeDecoder.DecodeDirectBits(num10 - 4) << 4; num += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder); } } else { num = num9; } } if (num >= m_OutWindow.TrainSize + num5 || num >= m_DictionarySizeCheck) { if (num == uint.MaxValue) { break; } throw new DataErrorException(); } m_OutWindow.CopyBlock(num, num8); num5 += num8; } m_OutWindow.Flush(); m_OutWindow.ReleaseStream(); m_RangeDecoder.ReleaseStream(); }
public void Code(System.IO.Stream inStream, System.IO.Stream outStream, Int64 inSize, Int64 outSize, ICodeProgress progress) { _needReleaseMFStream = false; try { SetStreams(inStream, outStream, inSize, outSize); while (true) { Int64 processedInSize; Int64 processedOutSize; bool finished; CodeOneBlock(out processedInSize, out processedOutSize, out finished); if (finished) return; if (progress != null) { progress.SetProgress(processedInSize, processedOutSize); } } } finally { ReleaseStreams(); } }
public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress) { Init(inStream, outStream); var state = new Base.State(); state.Init(); uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0; ulong nowPos64 = 0; var outSize64 = (ulong) outSize; if (nowPos64 < outSize64) { if (_mIsMatchDecoders[state.Index << Base.KNumPosStatesBitsMax].Decode(_mRangeDecoder) != 0) throw new DataErrorException(); state.UpdateChar(); var b = _mLiteralDecoder.DecodeNormal(_mRangeDecoder, 0, 0); _mOutWindow.PutByte(b); nowPos64++; } while (nowPos64 < outSize64) // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64); // while(nowPos64 < next) { var posState = (uint) nowPos64 & _mPosStateMask; if (_mIsMatchDecoders[(state.Index << Base.KNumPosStatesBitsMax) + posState].Decode(_mRangeDecoder) == 0) { byte b; var prevByte = _mOutWindow.GetByte(0); if (!state.IsCharState()) b = _mLiteralDecoder.DecodeWithMatchByte(_mRangeDecoder, (uint) nowPos64, prevByte, _mOutWindow.GetByte(rep0)); else b = _mLiteralDecoder.DecodeNormal(_mRangeDecoder, (uint) nowPos64, prevByte); _mOutWindow.PutByte(b); state.UpdateChar(); nowPos64++; } else { uint len; if (_mIsRepDecoders[state.Index].Decode(_mRangeDecoder) == 1) { if (_mIsRepG0Decoders[state.Index].Decode(_mRangeDecoder) == 0) { if ( _mIsRep0LongDecoders[(state.Index << Base.KNumPosStatesBitsMax) + posState].Decode( _mRangeDecoder) == 0) { state.UpdateShortRep(); _mOutWindow.PutByte(_mOutWindow.GetByte(rep0)); nowPos64++; continue; } } else { uint distance; if (_mIsRepG1Decoders[state.Index].Decode(_mRangeDecoder) == 0) distance = rep1; else { if (_mIsRepG2Decoders[state.Index].Decode(_mRangeDecoder) == 0) distance = rep2; else { distance = rep3; rep3 = rep2; } rep2 = rep1; } rep1 = rep0; rep0 = distance; } len = _mRepLenDecoder.Decode(_mRangeDecoder, posState) + Base.KMatchMinLen; state.UpdateRep(); } else { rep3 = rep2; rep2 = rep1; rep1 = rep0; len = Base.KMatchMinLen + _mLenDecoder.Decode(_mRangeDecoder, posState); state.UpdateMatch(); var posSlot = _mPosSlotDecoder[Base.GetLenToPosState(len)].Decode(_mRangeDecoder); if (posSlot >= Base.KStartPosModelIndex) { var numDirectBits = (int) ((posSlot >> 1) - 1); rep0 = ((2 | (posSlot & 1)) << numDirectBits); if (posSlot < Base.KEndPosModelIndex) rep0 += BitTreeDecoder.ReverseDecode(_mPosDecoders, rep0 - posSlot - 1, _mRangeDecoder, numDirectBits); else { rep0 += (_mRangeDecoder.DecodeDirectBits( numDirectBits - Base.KNumAlignBits) << Base.KNumAlignBits); rep0 += _mPosAlignDecoder.ReverseDecode(_mRangeDecoder); } } else rep0 = posSlot; } if (rep0 >= _mOutWindow.TrainSize + nowPos64 || rep0 >= _mDictionarySizeCheck) { if (rep0 == 0xFFFFFFFF) break; throw new DataErrorException(); } _mOutWindow.CopyBlock(rep0, len); nowPos64 += len; } } _mOutWindow.Flush(); _mOutWindow.ReleaseStream(); _mRangeDecoder.ReleaseStream(); }