/// <summary>
        /// Decompress bytes to osd.
        /// </summary>
        /// <returns>The decompressed osd.</returns>
        /// <param name="input">Input.</param>
        public static OSD ZDecompressBytesToOsd(byte[] input)
        {
            OSD osd;

            using (MemoryStream msSinkUnCompressed = new MemoryStream ())
            {
                using (ZOutputStream zOut = new ZOutputStream (msSinkUnCompressed))
                {
                    using (Stream inMs = new MemoryStream (input))
                    {
                        CopyStream (inMs, zOut);
                        zOut.finish ();

                        osd = OSDParser.DeserializeLLSDBinary (msSinkUnCompressed.ToArray ());
                    }
                }
            }

            return osd;
        }
        /// <summary>
        /// Compress an OSD.
        /// </summary>
        /// <returns>The compressed OSD</returns>
        /// <param name="inOsd">In osd.</param>
        /// <param name="useHeader">If set to <c>true</c> use header.</param>
        public static OSD ZCompressOSD(OSD inOsd, bool useHeader)
        {
            OSD osd;

            using (MemoryStream msSinkCompressed = new MemoryStream ())
            {
                using (ZOutputStream zOut = new ZOutputStream (msSinkCompressed, zlibConst.Z_DEFAULT_COMPRESSION))
                {
                    CopyStream (new MemoryStream (OSDParser.SerializeLLSDBinary (inOsd, useHeader)), zOut);
                    zOut.finish ();

                    osd = OSD.FromBinary (msSinkCompressed.ToArray ());
                }
            }

            return osd;
        }
        /// <summary>
        /// decompresses a gzipped OSD object
        /// </summary>
        /// <param name="decodedOsd"></param> the OSD object
        /// <param name="meshBytes"></param>
        /// <returns></returns>
        static OSD DecompressOsd(byte[] meshBytes)
        {
            OSD decodedOsd = null;

            using (MemoryStream outMs = new MemoryStream())
            {
                using (ZOutputStream zOut = new ZOutputStream(outMs))
                {
                    using (Stream inMs = new MemoryStream(meshBytes))
                     {
                        byte[] readBuffer = new byte[2000];
                        int readLen;

                        while ((readLen = inMs.Read(readBuffer, 0, readBuffer.Length)) > 0)
                        {
                            zOut.Write(readBuffer, 0, readLen);
                        }
                        zOut.Flush();
                        zOut.finish();
                        //outMs.Seek(0, SeekOrigin.Begin);

                        //byte[] decompressedBuf = outMs.GetBuffer();
                        byte[] decompressedBuf = outMs.ToArray();

                        decodedOsd = OSDParser.DeserializeLLSDBinary(decompressedBuf);
                    }
                }
            }

            return decodedOsd;
        }