Exemplo n.º 1
0
        /// <summary>
        /// 	* Inflates either zlib or gzip deflated memory. The inflated memory is
        ///	* expected to be freed by the caller.
        ///	*
        ///	* It will allocate 256k for the destination buffer. If it is not enought it will multiply the previous buffer size per 2, until there is enough memory.
        ///	* @returns the length of the deflated buffer
        ///	*
        ///	@since v0.8.1
        /// </summary>
        /// <param name="parameterin"></param>
        /// <param name="inLength"></param>
        /// <param name="parameterout"></param>
        /// <returns></returns>
        public static int InflateMemory(byte[] parameterin, uint inLength, byte[] parameterout)
        {
            MemoryStream ms = new MemoryStream(parameterout, true);
            try
            {
                GZipStream gs = new GZipStream(new MemoryStream(parameterin, false)); // , CompressionMode.Decompress, false);
#if XBOX
                byte[] b = new byte[8096];
                while (gs.CanRead)
                {
                    int amt = gs.Read(b, 0, b.Length);
                    if (amt <= 0)
                    {
                        break;
                    }
                    ms.Write(b, 0, amt);
                }
#else
                gs.CopyTo(ms);
#endif
                return ((int)ms.Length);
            }
            catch (Exception)
            {
                // Nog a gzip stream, could be zlib stream
            }
            return (0);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 	* Inflates either zlib or gzip deflated memory. The inflated memory is
 ///	* expected to be freed by the caller.
 ///	*
 ///	* It will allocate 256k for the destination buffer. If it is not enought it will multiply the previous buffer size per 2, until there is enough memory.
 ///	* @returns the length of the deflated buffer
 ///	*
 ///	@since v0.8.1
 /// </summary>
 /// <param name="parameterin"></param>
 /// <param name="inLength"></param>
 /// <param name="parameterout"></param>
 /// <returns></returns>
 public static int InflateMemory(byte[] parameterin, uint inLength, byte[] parameterout)
 {
     MemoryStream ms = new MemoryStream(parameterout, true);
     try
     {
         GZipStream gs = new GZipStream(new MemoryStream(parameterin, false)); // , CompressionMode.Decompress, false);
         gs.CopyTo(ms);
         return ((int)ms.Length);
     }
     catch (Exception)
     {
         // Nog a gzip stream, could be zlib stream
     }
     return (0);
 }