//go:build windows

package yu_deflate

// ZlibDe
//
//	@Description: Zlib 格式解压数据
//	@param buf 欲解压的数据
//	@return []byte 解压后的数据
func ZlibDe(buf []byte) []byte {
	if len(buf) == 0 {
		return nil
	}
	j_decomp := m_pool_decomp.Get().(*uintptr)
	defer m_pool_decomp.Put(j_decomp)
	j_i, j_n := 1, 0
_decompressor:
	j_buf := make([]byte, len(buf)*j_i)
	j_result, _, _ := libdeflate_zlib_decompress_ex.Call(*j_decomp, buf, len(buf), j_buf, len(j_buf), 0, &j_n)
	if j_result == 0 /* C.LIBDEFLATE_SUCCESS */ {
		return j_buf[:j_n]
	} else if j_result == 3 /* C.LIBDEFLATE_INSUFFICIENT_SPACE */ {
		j_i += 3
		goto _decompressor
	}
	return nil
}

// DeflateDe
//
//	@Description: Deflate 格式解压数据
//	@param buf 欲解压的数据
//	@return []byte 解压后的数据
func DeflateDe(buf []byte) []byte {
	if len(buf) == 0 {
		return nil
	}
	j_decomp := m_pool_decomp.Get().(*uintptr)
	defer m_pool_decomp.Put(j_decomp)
	j_i, j_n := 1, 0
_decompressor:
	j_buf := make([]byte, len(buf)*j_i)
	j_result, _, _ := libdeflate_deflate_decompress_ex.Call(*j_decomp, buf, len(buf), j_buf, len(j_buf), 0, &j_n)
	if j_result == 0 /* C.LIBDEFLATE_SUCCESS */ {
		return j_buf[:j_n]
	} else if j_result == 3 /* C.LIBDEFLATE_INSUFFICIENT_SPACE */ {
		j_i += 3
		goto _decompressor
	}
	return nil
}

// GzipDe
//
//	@Description: Gzip 格式解压数据
//	@param buf 欲解压的数据
//	@return []byte 解压后的数据
func GzipDe(buf []byte) []byte {
	if len(buf) == 0 {
		return nil
	}
	j_decomp := m_pool_decomp.Get().(*uintptr)
	defer m_pool_decomp.Put(j_decomp)
	j_i, j_n := 1, 0
_decompressor:
	j_buf := make([]byte, len(buf)*j_i)
	j_result, _, _ := libdeflate_gzip_decompress_ex.Call(*j_decomp, buf, len(buf), j_buf, len(j_buf), 0, &j_n)
	if j_result == 0 /* C.LIBDEFLATE_SUCCESS */ {
		return j_buf[:j_n]
	} else if j_result == 3 /* C.LIBDEFLATE_INSUFFICIENT_SPACE */ {
		j_i += 3
		goto _decompressor
	}
	return nil
}
