コード例 #1
0
ファイル: LzmaDecoder.cs プロジェクト: WinCoder/RomVault
        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;
        }
コード例 #2
0
        public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize,
                          Stream presetDictionary, bool isLZMA2)
        {
            this.inputStream = inputStream;
            this.inputSize   = inputSize;
            this.outputSize  = outputSize;
            this.isLZMA2     = isLZMA2;

            if (!isLZMA2)
            {
                dictionarySize = BitConverter.ToInt32(properties, 1);
                outWindow.Create(dictionarySize);
                if (presetDictionary != null)
                {
                    outWindow.Train(presetDictionary);
                }

                rangeDecoder.Init(inputStream);

                decoder = new Decoder();
                decoder.SetDecoderProperties(properties);
                props = properties;

                availableBytes    = outputSize < 0 ? long.MaxValue : outputSize;
                rangeDecoderLimit = inputSize;
            }
            else
            {
                dictionarySize   = 2 | (properties[0] & 1);
                dictionarySize <<= (properties[0] >> 1) + 11;

                outWindow.Create(dictionarySize);
                if (presetDictionary != null)
                {
                    outWindow.Train(presetDictionary);
                    needDictReset = false;
                }

                props          = new byte[1];
                availableBytes = 0;
            }
        }
コード例 #3
0
        void Init(System.IO.Stream inStream, System.IO.Stream outStream)
        {
            m_RangeDecoder.Init(inStream);
            m_OutWindow.Init(outStream, _solid);

            uint i;

            for (i = 0; i < Base.kNumStates; i++)
            {
                for (uint j = 0; j <= m_PosStateMask; j++)
                {
                    uint index = (i << Base.kNumPosStatesBitsMax) + j;
                    m_IsMatchDecoders[index].Init();
                    m_IsRep0LongDecoders[index].Init();
                }
                m_IsRepDecoders[i].Init();
                m_IsRepG0Decoders[i].Init();
                m_IsRepG1Decoders[i].Init();
                m_IsRepG2Decoders[i].Init();
            }

            m_LiteralDecoder.Init();
            for (i = 0; i < Base.kNumLenToPosStates; i++)
            {
                m_PosSlotDecoder[i].Init();
            }
            // m_PosSpecDecoder.Init();
            for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)
            {
                m_PosDecoders[i].Init();
            }

            m_LenDecoder.Init();
            m_RepLenDecoder.Init();
            m_PosAlignDecoder.Init();
        }