コード例 #1
0
ファイル: LzmaStream.cs プロジェクト: nickchal/pash
        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;
            }
        }
コード例 #2
0
ファイル: LzmaStream.cs プロジェクト: modulexcite/pash-1
        private void decodeChunkHeader()
        {
            int control = inputStream.ReadByte();

            inputPosition++;

            if (control == 0x00)
            {
                endReached = true;
                return;
            }

            if (control >= 0xE0 || control == 0x01)
            {
                needProps     = true;
                needDictReset = false;
                outWindow.Reset();
            }
            else if (needDictReset)
            {
                throw new DataErrorException();
            }

            if (control >= 0x80)
            {
                uncompressedChunk = false;

                availableBytes  = (control & 0x1F) << 16;
                availableBytes += (inputStream.ReadByte() << 8) + inputStream.ReadByte() + 1;
                inputPosition  += 2;

                rangeDecoderLimit = (inputStream.ReadByte() << 8) + inputStream.ReadByte() + 1;
                inputPosition    += 2;

                if (control >= 0xC0)
                {
                    needProps = false;
                    props[0]  = (byte)inputStream.ReadByte();
                    inputPosition++;

                    decoder = new Decoder();
                    decoder.SetDecoderProperties(props);
                }
                else if (needProps)
                {
                    throw new DataErrorException();
                }
                else if (control >= 0xA0)
                {
                    decoder = new Decoder();
                    decoder.SetDecoderProperties(props);
                }

                rangeDecoder.Init(inputStream);
            }
            else if (control > 0x02)
            {
                throw new DataErrorException();
            }
            else
            {
                uncompressedChunk = true;
                availableBytes    = (inputStream.ReadByte() << 8) + inputStream.ReadByte() + 1;
                inputPosition    += 2;
            }
        }
コード例 #3
0
ファイル: LzmaStream.cs プロジェクト: nickchal/pash
        private void decodeChunkHeader()
        {
            int control = inputStream.ReadByte();
            inputPosition++;

            if (control == 0x00)
            {
                endReached = true;
                return;
            }

            if (control >= 0xE0 || control == 0x01)
            {
                needProps = true;
                needDictReset = false;
                outWindow.Reset();
            }
            else if (needDictReset)
                throw new DataErrorException();

            if (control >= 0x80)
            {
                uncompressedChunk = false;

                availableBytes = (control & 0x1F) << 16;
                availableBytes += (inputStream.ReadByte() << 8) + inputStream.ReadByte() + 1;
                inputPosition += 2;

                rangeDecoderLimit = (inputStream.ReadByte() << 8) + inputStream.ReadByte() + 1;
                inputPosition += 2;

                if (control >= 0xC0)
                {
                    needProps = false;
                    props[0] = (byte)inputStream.ReadByte();
                    inputPosition++;

                    decoder = new Decoder();
                    decoder.SetDecoderProperties(props);
                }
                else if (needProps)
                    throw new DataErrorException();
                else if (control >= 0xA0)
                {
                    decoder = new Decoder();
                    decoder.SetDecoderProperties(props);
                }

                rangeDecoder.Init(inputStream);
            }
            else if (control > 0x02)
                throw new DataErrorException();
            else
            {
                uncompressedChunk = true;
                availableBytes = (inputStream.ReadByte() << 8) + inputStream.ReadByte() + 1;
                inputPosition += 2;
            }
        }
コード例 #4
0
        private void decodeChunkHeader()
        {
            int num = this.inputStream.ReadByte();

            this.inputPosition += 1L;
            if (num == 0)
            {
                this.endReached = true;
            }
            else
            {
                if ((num >= 0xe0) || (num == 1))
                {
                    this.needProps     = true;
                    this.needDictReset = false;
                    this.outWindow.Reset();
                }
                else if (this.needDictReset)
                {
                    throw new DataErrorException();
                }
                if (num < 0x80)
                {
                    if (num > 2)
                    {
                        throw new DataErrorException();
                    }
                    this.uncompressedChunk = true;
                    this.availableBytes    = ((this.inputStream.ReadByte() << 8) + this.inputStream.ReadByte()) + 1;
                    this.inputPosition    += 2L;
                }
                else
                {
                    this.uncompressedChunk = false;
                    this.availableBytes    = (num & 0x1f) << 0x10;
                    this.availableBytes   += ((this.inputStream.ReadByte() << 8) + this.inputStream.ReadByte()) + 1;
                    this.inputPosition    += 2L;
                    this.rangeDecoderLimit = ((this.inputStream.ReadByte() << 8) + this.inputStream.ReadByte()) + 1;
                    this.inputPosition    += 2L;
                    if (num >= 0xc0)
                    {
                        this.needProps      = false;
                        this.props[0]       = (byte)this.inputStream.ReadByte();
                        this.inputPosition += 1L;
                        this.decoder        = new Decoder();
                        this.decoder.SetDecoderProperties(this.props);
                    }
                    else
                    {
                        if (this.needProps)
                        {
                            throw new DataErrorException();
                        }
                        if (num >= 160)
                        {
                            this.decoder = new Decoder();
                            this.decoder.SetDecoderProperties(this.props);
                        }
                    }
                    this.rangeDecoder.Init(this.inputStream);
                }
            }
        }