de_windows.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //go:build windows
  2. package yu_deflate
  3. // ZlibDe
  4. //
  5. // @Description: Zlib 格式解压数据
  6. // @param buf 欲解压的数据
  7. // @return []byte 解压后的数据
  8. func ZlibDe(buf []byte) []byte {
  9. if len(buf) == 0 {
  10. return nil
  11. }
  12. j_decomp := m_pool_decomp.Get().(*uintptr)
  13. defer m_pool_decomp.Put(j_decomp)
  14. j_i, j_n := 1, 0
  15. _decompressor:
  16. j_buf := make([]byte, len(buf)*j_i)
  17. j_result, _, _ := libdeflate_zlib_decompress_ex.Call(*j_decomp, buf, len(buf), j_buf, len(j_buf), 0, &j_n)
  18. if j_result == 0 /* C.LIBDEFLATE_SUCCESS */ {
  19. return j_buf[:j_n]
  20. } else if j_result == 3 /* C.LIBDEFLATE_INSUFFICIENT_SPACE */ {
  21. j_i += 3
  22. goto _decompressor
  23. }
  24. return nil
  25. }
  26. // DeflateDe
  27. //
  28. // @Description: Deflate 格式解压数据
  29. // @param buf 欲解压的数据
  30. // @return []byte 解压后的数据
  31. func DeflateDe(buf []byte) []byte {
  32. if len(buf) == 0 {
  33. return nil
  34. }
  35. j_decomp := m_pool_decomp.Get().(*uintptr)
  36. defer m_pool_decomp.Put(j_decomp)
  37. j_i, j_n := 1, 0
  38. _decompressor:
  39. j_buf := make([]byte, len(buf)*j_i)
  40. j_result, _, _ := libdeflate_deflate_decompress_ex.Call(*j_decomp, buf, len(buf), j_buf, len(j_buf), 0, &j_n)
  41. if j_result == 0 /* C.LIBDEFLATE_SUCCESS */ {
  42. return j_buf[:j_n]
  43. } else if j_result == 3 /* C.LIBDEFLATE_INSUFFICIENT_SPACE */ {
  44. j_i += 3
  45. goto _decompressor
  46. }
  47. return nil
  48. }
  49. // GzipDe
  50. //
  51. // @Description: Gzip 格式解压数据
  52. // @param buf 欲解压的数据
  53. // @return []byte 解压后的数据
  54. func GzipDe(buf []byte) []byte {
  55. if len(buf) == 0 {
  56. return nil
  57. }
  58. j_decomp := m_pool_decomp.Get().(*uintptr)
  59. defer m_pool_decomp.Put(j_decomp)
  60. j_i, j_n := 1, 0
  61. _decompressor:
  62. j_buf := make([]byte, len(buf)*j_i)
  63. j_result, _, _ := libdeflate_gzip_decompress_ex.Call(*j_decomp, buf, len(buf), j_buf, len(j_buf), 0, &j_n)
  64. if j_result == 0 /* C.LIBDEFLATE_SUCCESS */ {
  65. return j_buf[:j_n]
  66. } else if j_result == 3 /* C.LIBDEFLATE_INSUFFICIENT_SPACE */ {
  67. j_i += 3
  68. goto _decompressor
  69. }
  70. return nil
  71. }