Exemplo n.º 1
0
		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();
			}
		}
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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)
            {
                //progress.SetProgress((Int64)nowPos64, 0);//EDHACK
                progress.SetProgress(inStream.Position, 0);
                // 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;
                    }
                }
            }
            m_OutWindow.Flush();
            m_OutWindow.ReleaseStream();
            m_RangeDecoder.ReleaseStream();
        }
Exemplo n.º 4
0
        // 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;
        }
Exemplo n.º 5
0
 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();
     }
 }