示例#1
0
 public virtual void End()
 {
     lock (this)
     {
         inflater.Finish();
     }
 }
示例#2
0
 /// <summary>Release an inflater previously obtained from this cache.</summary>
 /// <remarks>Release an inflater previously obtained from this cache.</remarks>
 /// <param name="i">
 /// the inflater to return. May be null, in which case this method
 /// does nothing.
 /// </param>
 public static void Release(Inflater i)
 {
     if (i != null)
     {
         i.Reset();
         if (ReleaseImpl(i))
         {
             i.Finish();
         }
     }
 }
示例#3
0
        public void Inflate_Expand()
        {
            uncompressedData.Clear();

            using (Inflater inf = new Inflater())
            {
                inf.DataAvailable += new DataAvailableHandler(DDataAvail);
                inf.Add((byte[])compressedData.ToArray(typeof(byte)));
                inf.Finish();
                adler2 = inf.Checksum;
            }
            Assert.AreEqual(adler1, adler2);
        }
        /// <exception cref="System.IO.IOException"></exception>
        public DeflateInputStream(InputStream wrapped)
        {
            byte[] peeked = new byte[6];
            PushbackInputStream pushback = new PushbackInputStream(wrapped, peeked.Length);
            int headerLength             = pushback.Read(peeked);

            if (headerLength == -1)
            {
                throw new IOException("Unable to read the response");
            }
            byte[]   dummy = new byte[1];
            Inflater inf   = new Inflater();

            try
            {
                int n;
                while ((n = inf.Inflate(dummy)) == 0)
                {
                    if (inf.IsFinished)
                    {
                        throw new IOException("Unable to read the response");
                    }
                    if (inf.NeedsDictionary())
                    {
                        break;
                    }
                    if (inf.IsNeedingInput)
                    {
                        inf.SetInput(peeked);
                    }
                }
                if (n == -1)
                {
                    throw new IOException("Unable to read the response");
                }
                pushback.Unread(peeked, 0, headerLength);
                sourceStream = new DeflateInputStream.DeflateStream(pushback, new Inflater());
            }
            catch (SharpZipBaseException)
            {
                pushback.Unread(peeked, 0, headerLength);
                sourceStream = new DeflateInputStream.DeflateStream(pushback, new Inflater(true));
            }
            finally
            {
                inf.Finish();
            }
        }
示例#5
0
        /// <summary>
        /// Decompress a stream with ZLib
        /// </summary>
        /// <param name="compressLevel">Compression level of stream</param>
        /// <param name="expectedSize">Expected size</param>
        public static void Decompress(out CompressLevel compressLevel, int expectedSize = 0)
        {
            uint numBytesAddressing = ZLibWrapper.InputBufferLength;

            compressLevel = CompressLevel.None;

            try
            {
                ZLibWrapper.Position(0, ZLibBufferType.InputBuffer);
                compressLevel = RetrieveCompressionLevel();
                ZLibWrapper.Position(0, ZLibBufferType.InputBuffer);

                if (expectedSize == 0)
                {
                    // no decompression. copy input buffer in output buffer
                    ZLibWrapper.CopyInputBufferToOutputBuffer(8);
                    compressLevel = CompressLevel.None; // for compression
                }
                else
                {
                    if (_inflater == null)
                    {
                        _inflater = new Inflater();
                        _inflater.DataAvailable += ZLibWrapper.WriteInOutputBuffer;
                    }

                    while (numBytesAddressing > 0u)
                    {
                        uint numBytes = Math.Min(numBytesAddressing, 8192u); //8192u); 65536u
                        _inflater.Add(ZLibWrapper.ReadBytes((int)numBytes, ZLibBufferType.InputBuffer));
                        numBytesAddressing -= numBytes;
                    }

                    string inflateErrorMsg = _inflater._ztream.msg;
                    if (!string.IsNullOrWhiteSpace(inflateErrorMsg))
                    {
                        MessageBox.Show(string.Format("ZLib.Decompress: {0}", inflateErrorMsg),
                                        TranslateUI.TranslateUiGlobalization.ResManager.GetString("ZLib_Error"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }

                    _inflater.Finish(); //flush zlib buffer
                }
                ZLibWrapper.Position(0, ZLibBufferType.OutputBuffer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    string.Format(TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "MSG_ErrorWithNewLine"), ex),
                    TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Decompress"),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (ZLibWrapper.OutputBufferLength == 0)
                {
                    MessageBox.Show(
                        TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_OutputBufferEmpty"),
                        TranslateUI.TranslateUiGlobalization.ResManager.GetString(name: "ZLib_Decompress"),
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }