StringUtils.cs 819 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Globalization;
  3. using System.IO;
  4. using System.IO.Compression;
  5. namespace TriLib
  6. {
  7. public class StringUtils
  8. {
  9. public static string GenerateUniqueName(object id)
  10. {
  11. return id.GetHashCode().ToString(CultureInfo.InvariantCulture);
  12. }
  13. public static byte[] UnZip(string value)
  14. {
  15. byte[] array = Convert.FromBase64String(value);
  16. byte[] result;
  17. using (MemoryStream memoryStream = new MemoryStream())
  18. {
  19. int num = BitConverter.ToInt32(array, 0);
  20. memoryStream.Write(array, 4, array.Length - 4);
  21. byte[] array2 = new byte[num];
  22. memoryStream.Position = 0L;
  23. using (GZipStream gzipStream = new GZipStream(memoryStream, CompressionMode.Decompress))
  24. {
  25. gzipStream.Read(array2, 0, array2.Length);
  26. }
  27. result = array2;
  28. }
  29. return result;
  30. }
  31. }
  32. }