Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="properties"></param>
        /// <param name="inputStream"></param>
        /// <param name="inputSize"></param>
        /// <param name="outputSize"></param>
        /// <param name="presetDictionary"></param>
        /// <param name="isLZMA2"></param>
        public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize,
                          Stream presetDictionary, bool isLZMA2)
        {
            Properties       = new byte[5];
            this.inputStream = inputStream;
            this.inputSize   = inputSize;
            this.outputSize  = outputSize;
            this.isLZMA2     = isLZMA2;

            if (!isLZMA2)
            {
                dictionarySize = DataConverter.LittleEndian.GetInt32(properties, 1);
                outWindow.Create(dictionarySize);
                if (presetDictionary != null)
                {
                    outWindow.Train(presetDictionary);
                }

                rangeDecoder.Init(inputStream);

                decoder = new Decoder();
                decoder.SetDecoderProperties(properties);
                Properties = 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;
                }

                Properties     = new byte[1];
                availableBytes = 0;
            }
        }
Exemplo n.º 4
0
        public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize,
                          Stream presetDictionary, bool isLzma2)
        {
            _inputStream = inputStream;
            _inputSize   = inputSize;
            _outputSize  = outputSize;
            _isLzma2     = isLzma2;

            if (!isLzma2)
            {
                _dictionarySize = DataConverter.LittleEndian.GetInt32(properties, 1);
                _outWindow.Create(_dictionarySize);
                if (presetDictionary != null)
                {
                    _outWindow.Train(presetDictionary);
                }

                _rangeDecoder.Init(inputStream);

                _decoder = new Decoder();
                _decoder.SetDecoderProperties(properties);
                Properties = 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;
                }

                Properties      = new byte[1];
                _availableBytes = 0;
            }
        }