Ejemplo n.º 1
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 );
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Release inflater instance
 /// </summary>
 public static void ReleaseInflater()
 {
     if (_inflater != null)
     {
         _inflater.DataAvailable -= ZLibWrapper.WriteInOutputBuffer;
         _inflater.Dispose();
         _inflater = null;
     }
 }
Ejemplo n.º 3
0
 public void Inflate_Init()
 {
     using (Inflater inf = new Inflater())
     {
     }
 }
Ejemplo n.º 4
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);
                }
            }
        }