Ejemplo n.º 1
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (crc != null)
            {
                crc.SlurpBlock(buffer, offset, count);
            }
            if (_streamMode == StreamMode.Undefined)
            {
                _streamMode = StreamMode.Writer;
            }
            else if (_streamMode != 0)
            {
                throw new ZlibException("Cannot Write after Reading.");
            }
            if (count == 0)
            {
                return;
            }
            z.InputBuffer       = buffer;
            _z.NextIn           = offset;
            _z.AvailableBytesIn = count;
            bool flag = false;

            while (true)
            {
                _z.OutputBuffer      = workingBuffer;
                _z.NextOut           = 0;
                _z.AvailableBytesOut = _workingBuffer.Length;
                int num = (!_wantCompress) ? _z.Inflate(_flushMode) : _z.Deflate(_flushMode);
                if (num != 0 && num != 1)
                {
                    break;
                }
                _stream.Write(_workingBuffer, 0, _workingBuffer.Length - _z.AvailableBytesOut);
                flag = (_z.AvailableBytesIn == 0 && _z.AvailableBytesOut != 0);
                if (_flavor == ZlibStreamFlavor.GZIP && !_wantCompress)
                {
                    flag = (_z.AvailableBytesIn == 8 && _z.AvailableBytesOut != 0);
                }
                if (flag)
                {
                    return;
                }
            }
            throw new ZlibException(((!_wantCompress) ? "in" : "de") + "flating: " + _z.Message);
        }
Ejemplo n.º 2
0
        internal int SetParams(CompressionLevel level, CompressionStrategy strategy)
        {
            int result = 0;

            if (compressionLevel != level)
            {
                Config config = Config.Lookup(level);
                if (config.Flavor != this.config.Flavor && _codec.TotalBytesIn != 0L)
                {
                    result = _codec.Deflate(FlushType.Partial);
                }
                compressionLevel = level;
                this.config      = config;
                SetDeflater();
            }
            compressionStrategy = strategy;
            return(result);
        }