/// <summary> /// 将传入字符串以GZip算法压缩后,返回byte[] /// </summary> /// <param name="toZipString">需要压缩的字符串</param> /// <returns>压缩后的byte[]</returns> public static byte[] Compress2ByteArr(string toZipString) { if (toZipString.IsNullOrWhiteSpace() == true) { return(null); } else { byte[] toZipByteArr = System.Text.Encoding.UTF8.GetBytes(toZipString); return(GZipUtils.Compress(toZipByteArr)); } }
/// <summary> /// 将传入字符串以GZip算法压缩后,返回Base64Str /// </summary> /// <param name="toZipString">需要压缩的字符串</param> /// <returns>压缩后的Base64Str</returns> public static string Compress2String(string toZipString) { if (toZipString.IsNullOrWhiteSpace() == true) { return(string.Empty); } else { byte[] toZipByteArr = System.Text.Encoding.UTF8.GetBytes(toZipString); byte[] zippedByteArr = GZipUtils.Compress(toZipByteArr); return(Convert.ToBase64String(zippedByteArr)); } }