en_windows.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //go:build windows
  2. package yu_deflate
  3. // Zlib
  4. //
  5. // @Description: Zlib 格式压缩数据
  6. // @param buf 欲压缩的数据
  7. // @return []byte 压缩后的数据
  8. func Zlib(buf []byte) []byte {
  9. if len(buf) == 0 {
  10. return nil
  11. }
  12. j_comp := m_pool_comp.Get().(*uintptr)
  13. defer m_pool_comp.Put(j_comp)
  14. var j_buf []byte
  15. if len(buf) < 64 {
  16. j_buf = make([]byte, 64)
  17. } else {
  18. j_buf = make([]byte, len(buf))
  19. }
  20. var j_i int
  21. _compress:
  22. j_n, _, _ := libdeflate_zlib_compress.Call(*j_comp, buf, len(buf), j_buf, len(j_buf))
  23. if j_i++; j_n == 0 && j_i < 3 {
  24. j_buf = make([]byte, len(buf)*j_i)
  25. goto _compress
  26. }
  27. return j_buf[:j_n]
  28. }
  29. // Deflate
  30. //
  31. // @Description: Deflate 格式压缩数据
  32. // @param buf 欲压缩的数据
  33. // @return []byte 压缩后的数据
  34. func Deflate(buf []byte) []byte {
  35. if len(buf) == 0 {
  36. return nil
  37. }
  38. j_comp := m_pool_comp.Get().(*uintptr)
  39. defer m_pool_comp.Put(j_comp)
  40. var j_buf []byte
  41. if len(buf) < 64 {
  42. j_buf = make([]byte, 64)
  43. } else {
  44. j_buf = make([]byte, len(buf))
  45. }
  46. var j_i int
  47. _compress:
  48. j_n, _, _ := libdeflate_deflate_compress.Call(*j_comp, buf, len(buf), j_buf, len(j_buf))
  49. if j_i++; j_n == 0 && j_i < 3 {
  50. j_buf = make([]byte, len(buf)*j_i)
  51. goto _compress
  52. }
  53. return j_buf[:j_n]
  54. }
  55. // Gzip
  56. //
  57. // @Description: Gzip 格式压缩数据
  58. // @param buf 欲压缩的数据
  59. // @return []byte 压缩后的数据
  60. func Gzip(buf []byte) []byte {
  61. if len(buf) == 0 {
  62. return nil
  63. }
  64. j_comp := m_pool_comp.Get().(*uintptr)
  65. defer m_pool_comp.Put(j_comp)
  66. var j_buf []byte
  67. if len(buf) < 64 {
  68. j_buf = make([]byte, 64)
  69. } else {
  70. j_buf = make([]byte, len(buf))
  71. }
  72. var j_i int
  73. _compress:
  74. j_n, _, _ := libdeflate_gzip_compress.Call(*j_comp, buf, len(buf), j_buf, len(j_buf))
  75. if j_i++; j_n == 0 && j_i < 3 {
  76. j_buf = make([]byte, len(buf)*j_i)
  77. goto _compress
  78. }
  79. return j_buf[:j_n]
  80. }