/// <summary>
        /// Packs the stream.
        /// </summary>
        public static Stream Pack(Stream stream)
        {
            if (stream == null || stream.Length == 0 || !AllowPacking)
            {
                return(stream);
            }

            return(StiGZipHelper.Pack(stream));
        }
        /// <summary>
        /// Packs the byte array.
        /// </summary>
        public static byte[] Pack(byte[] bytes)
        {
            if (bytes == null || bytes.Length == 0 || !AllowPacking)
            {
                return(bytes);
            }

            return(AddZipSignature(StiGZipHelper.Pack(bytes)));
        }
        /// <summary>
        /// Unpacks byte array and convert it to string.
        /// </summary>
        public static string UnpackToString(byte[] bytes)
        {
            if (bytes == null || bytes.Length == 0)
            {
                return(null);
            }

            bytes = Unpack(bytes);

            return(StiGZipHelper.ConvertByteArrayToString(bytes));
        }
        /// <summary>
        /// Packs string and convert it to byte array.
        /// </summary>
        public static byte[] PackToBytes(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }

            var bytes = StiGZipHelper.ConvertStringToByteArray(str);

            if (bytes != null && bytes.Length != 0 && AllowPacking)
            {
                bytes = AddZipSignature(StiGZipHelper.Pack(bytes));
            }

            return(bytes);
        }
        /// <summary>
        /// Unpacks stream.
        /// </summary>
        public static Stream Unpack(Stream stream)
        {
            if (stream == null || stream.Length == 0 || !IsPacked(stream))
            {
                return(stream);
            }

            try
            {
                return(StiGZipHelper.Unpack(stream));
            }
            catch (InvalidDataException)//Bad unpacking
            {
                return(stream);
            }
        }
        /// <summary>
        /// Unpacks byte array.
        /// </summary>
        public static byte[] Unpack(byte[] bytes)
        {
            if (bytes == null || bytes.Length == 0 || !IsPacked(bytes))
            {
                return(bytes);
            }

            try
            {
                Array.Resize(ref bytes, bytes.Length - 3);
                return(StiGZipHelper.Unpack(bytes));
            }
            catch (InvalidDataException)//Bad unpacking
            {
                return(bytes);
            }
        }