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

            return(StiGZipHelper.Pack(stream));
        }
Exemplo n.º 2
0
        /// <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)));
        }
Exemplo n.º 3
0
        /// <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));
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
            }
        }
Exemplo n.º 6
0
        /// <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);
            }
        }