You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
776 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Web;
  6. namespace DefenseWeb.Helper
  7. {
  8. public class CompressionHelper
  9. {
  10. public static byte[] DeflateByte(byte[] str)
  11. {
  12. if (str == null)
  13. {
  14. return null;
  15. }
  16. using (var output = new MemoryStream())
  17. {
  18. using (
  19. var compressor = new Ionic.Zlib.DeflateStream(
  20. output, Ionic.Zlib.CompressionMode.Compress,
  21. Ionic.Zlib.CompressionLevel.BestSpeed))
  22. {
  23. compressor.Write(str, 0, str.Length);
  24. }
  25. return output.ToArray();
  26. }
  27. }
  28. }
  29. }