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;
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
        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;
        }
Exemplo n.º 5
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            if (endReached)
            {
                return(0);
            }

            int total = 0;

            while (total < count)
            {
                if (availableBytes == 0)
                {
                    if (isLZMA2)
                    {
                        decodeChunkHeader();
                    }
                    else
                    {
                        endReached = true;
                    }
                    if (endReached)
                    {
                        break;
                    }
                }

                int toProcess = count - total;
                if (toProcess > availableBytes)
                {
                    toProcess = (int)availableBytes;
                }

                outWindow.SetLimit(toProcess);
                if (uncompressedChunk)
                {
                    inputPosition += outWindow.CopyStream(inputStream, toProcess);
                }
                else if (decoder.Code(dictionarySize, outWindow, rangeDecoder) &&
                         outputSize < 0)
                {
                    availableBytes = outWindow.AvailableBytes;
                }

                int read = outWindow.Read(buffer, offset, toProcess);
                total          += read;
                offset         += read;
                position       += read;
                availableBytes -= read;

                if (availableBytes == 0 && !uncompressedChunk)
                {
                    rangeDecoder.ReleaseStream();
                    if (!rangeDecoder.IsFinished || (rangeDecoderLimit >= 0 && rangeDecoder.Total != rangeDecoderLimit))
                    {
                        throw new DataErrorException();
                    }
                    inputPosition += rangeDecoder.Total;
                    if (outWindow.HasPending)
                    {
                        throw new DataErrorException();
                    }
                }
            }

            if (endReached)
            {
                if (inputSize >= 0 && inputPosition != inputSize)
                {
                    throw new DataErrorException();
                }
                if (outputSize >= 0 && position != outputSize)
                {
                    throw new DataErrorException();
                }
            }

            return(total);
        }