14#include "../nyx_node_internal.h"
22 if(size == 0x00 || buff == NULL)
24 if(result_size != NULL)
34 uLongf comp_size = compressBound(size);
40 int ret = compress2(comp_buff, &comp_size, buff, size, Z_BEST_COMPRESSION);
46 if(result_size != NULL)
56 if(result_size != NULL)
58 *result_size = comp_size;
70 if(result_size == NULL)
77 if(size == 0x00 || buff == NULL)
89 uLongf uncomp_size = *result_size;
95 int ret = uncompress(uncomp_buff, &uncomp_size, buff, size);
113 *result_size = uncomp_size;
125static const uint32_t ADLER_MOD = 65521u;
127static const uint32_t ADLER_N_MAX = 5552u;
131uint32_t internal_adler32(
size_t src_size,
BUFF_t src_buff)
135 const uint8_t *p = (
const uint8_t *) src_buff;
144 size_t t = ADLER_N_MAX < src_size ? ADLER_N_MAX : src_size;
148 for(; t >= 4; t -= 4)
167 return (b << 16) | (a << 0);
174 if(size == 0x00 || buff == NULL)
176 if(result_size != NULL)
186 size_t n_blocks = size > 0 ? (size + 65534u) / 65535u : 1;
188 size_t dst_size = 2 + n_blocks * 5 + size + 4;
192 const uint8_t *src = (
const uint8_t *) ( buff );
195 uint8_t *result_buff = dst;
207 size_t chunk = 65535u < rem ? 65535u : rem;
211 *dst++ = (uint8_t) (chunk == rem);
215 *dst++ = (uint8_t) (chunk & 0xFF);
216 *dst++ = (uint8_t) (chunk >> 8);
217 *dst++ = (uint8_t) ((~chunk) & 0xFF);
218 *dst++ = (uint8_t) ((~chunk) >> 8);
224 memcpy(dst, src, chunk);
235 uint32_t hash = internal_adler32(size, buff);
237 *dst++ = (uint8_t) (hash >> 24);
238 *dst++ = (uint8_t) (hash >> 16);
239 *dst++ = (uint8_t) (hash >> 8);
240 *dst++ = (uint8_t) (hash >> 0);
244 if(result_size != NULL)
246 *result_size = (size_t) (dst - result_buff);
249 return (
buff_t) result_buff;
258 if(result_size != NULL)
277 if(comp_size > 0x00 && comp_buff != NULL)
288 if(result_len != NULL)
305 if(comp_size > 0x00 && comp_buff != NULL)
316 if(result_size != NULL)
#define NYX_LOG_ERROR(fmt,...)
Logs an error message.
#define STR_t
Alias for const char *.
__NYX_NULLABLE__ buff_t nyx_memory_alloc(__NYX_ZEROABLE__ size_t size)
Similar to libc malloc except that a memory overflow causes the node to stop.
__NYX_ZEROABLE__ size_t nyx_memory_free(__NYX_NULLABLE__ buff_t buff)
Similar to libc free except that it returns the amount of memory freed.
#define buff_t
Alias for void *.
#define BUFF_t
Alias for const void *.
#define str_t
Alias for char *.
__NYX_NULLABLE__ buff_t nyx_zlib_inflate(__NYX_NOTNULL__ size_t *result_size, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Decompresses a buffer using the ZLib algorithm.
__NYX_NULLABLE__ buff_t nyx_zlib_base64_inflate(__NYX_NOTNULL__ size_t *result_size, __NYX_ZEROABLE__ size_t len, __NYX_NULLABLE__ STR_t str)
Decompresses a string using the ZLib+Base64 algorithm.
__NYX_NULLABLE__ buff_t nyx_zlib_deflate(__NYX_NULLABLE__ size_t *result_size, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Compresses a buffer using the ZLib algorithm.
__NYX_NULLABLE__ str_t nyx_base64_encode(__NYX_NULLABLE__ size_t *result_len, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Encodes a buffer using the Base64 algorithm.
__NYX_NULLABLE__ str_t nyx_zlib_base64_deflate(__NYX_NULLABLE__ size_t *result_len, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Compresses a buffer using the ZLib+Base64 algorithm.
__NYX_NULLABLE__ buff_t nyx_base64_decode(__NYX_NULLABLE__ size_t *result_size, __NYX_ZEROABLE__ size_t len, __NYX_NULLABLE__ STR_t str)
Decodes a string using the Base64 algorithm.