@@ -2233,3 +2233,213 @@ int blosc_free_resources(void)
22332233
22342234 return blosc_release_threadpool (g_global_context );
22352235}
2236+
2237+
2238+ #if defined(HAVE_LZ4 )
2239+ int compress_lz4 (const char * input , size_t input_length ,
2240+ char * output , size_t maxout , int clevel )
2241+ {
2242+ return lz4_wrap_compress (input , input_length , output , maxout , 10 - clevel );
2243+ }
2244+
2245+ int decompress_lz4 (const char * input , size_t compressed_length ,
2246+ char * output , size_t maxout )
2247+ {
2248+ size_t cbytes ;
2249+ cbytes = LZ4_decompress_safe (input , output , compressed_length , (int )maxout );
2250+ if (cbytes <= 0 ) {
2251+ return 0 ;
2252+ }
2253+ return (int )cbytes ;
2254+ //return lz4_wrap_decompress(input, compressed_length, output, maxout);
2255+ }
2256+
2257+ #endif
2258+
2259+ #if defined(HAVE_ZSTD )
2260+
2261+ int compress_zstd (const char * input , size_t input_length ,
2262+ char * output , size_t maxout , int clevel )
2263+ {
2264+ return zstd_wrap_compress (input , input_length , output , maxout , clevel );
2265+ }
2266+
2267+ int decompress_zstd (const char * input , size_t compressed_length ,
2268+ char * output , size_t maxout )
2269+ {
2270+ return zstd_wrap_decompress (input , compressed_length , output , maxout );
2271+ }
2272+
2273+ #endif
2274+
2275+ #if defined(HAVE_ZLIB )
2276+
2277+ int compress_zlib (const char * input , size_t input_length ,
2278+ char * output , size_t maxout , int clevel )
2279+ {
2280+ return zlib_wrap_compress (input , input_length , output , maxout , clevel );
2281+ }
2282+
2283+ int decompress_zlib (const char * input , size_t compressed_length ,
2284+ char * output , size_t maxout )
2285+ {
2286+ return zlib_wrap_decompress (input , compressed_length , output , maxout );
2287+ }
2288+
2289+
2290+ int compress_deflate (const char * input , size_t input_length ,
2291+ char * output , size_t maxout , int clevel )
2292+ {
2293+ z_stream strm = {0 };
2294+ strm .total_in = strm .avail_in = input_length ;
2295+ strm .total_out = strm .avail_out = maxout ;
2296+ strm .next_in = (Bytef * ) input ;
2297+ strm .next_out = (Bytef * ) output ;
2298+
2299+ strm .zalloc = Z_NULL ;
2300+ strm .zfree = Z_NULL ;
2301+ strm .opaque = Z_NULL ;
2302+
2303+ int err = -1 ;
2304+ int ret = -1 ;
2305+
2306+ err = deflateInit2 (& strm , clevel , Z_DEFLATED , -15 , 8 , Z_DEFAULT_STRATEGY );
2307+ if (err == Z_OK ) {
2308+ err = deflate (& strm , Z_FINISH );
2309+ if (err == Z_STREAM_END ) {
2310+ ret = strm .total_out ;
2311+ }
2312+ else {
2313+ deflateEnd (& strm );
2314+ return err ;
2315+ }
2316+ }
2317+ else {
2318+ deflateEnd (& strm );
2319+ return err ;
2320+ }
2321+
2322+ deflateEnd (& strm );
2323+ return ret ;
2324+ }
2325+
2326+ int decompress_deflate (const char * input , size_t compressed_length ,
2327+ char * output , size_t maxout )
2328+ {
2329+ z_stream strm = {0 };
2330+ strm .total_in = strm .avail_in = compressed_length ;
2331+ strm .total_out = strm .avail_out = maxout ;
2332+ strm .next_in = (Bytef * ) input ;
2333+ strm .next_out = (Bytef * ) output ;
2334+
2335+ strm .zalloc = Z_NULL ;
2336+ strm .zfree = Z_NULL ;
2337+ strm .opaque = Z_NULL ;
2338+
2339+ int err = -1 ;
2340+ int ret = -1 ;
2341+
2342+ err = inflateInit2 (& strm , -15 ); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
2343+ if (err == Z_OK ) {
2344+ err = inflate (& strm , Z_FINISH );
2345+ if (err == Z_STREAM_END ) {
2346+ ret = strm .total_out ;
2347+ }
2348+ else {
2349+ inflateEnd (& strm );
2350+ return err ;
2351+ }
2352+ }
2353+ else {
2354+ inflateEnd (& strm );
2355+ return err ;
2356+ }
2357+
2358+ inflateEnd (& strm );
2359+ return ret ;
2360+ }
2361+
2362+ int compress_gzip (const char * input , size_t input_length ,
2363+ char * output , size_t maxout , int clevel )
2364+ {
2365+ z_stream strm = {0 };
2366+ strm .total_in = strm .avail_in = input_length ;
2367+ strm .total_out = strm .avail_out = maxout ;
2368+ strm .next_in = (Bytef * ) input ;
2369+ strm .next_out = (Bytef * ) output ;
2370+
2371+ strm .zalloc = Z_NULL ;
2372+ strm .zfree = Z_NULL ;
2373+ strm .opaque = Z_NULL ;
2374+
2375+ int err = -1 ;
2376+ int ret = -1 ;
2377+
2378+ err = deflateInit2 (& strm , clevel , Z_DEFLATED , 15 + 16 , 8 , Z_DEFAULT_STRATEGY );
2379+ if (err == Z_OK ) {
2380+ err = deflate (& strm , Z_FINISH );
2381+ if (err == Z_STREAM_END ) {
2382+ ret = strm .total_out ;
2383+ }
2384+ else {
2385+ deflateEnd (& strm );
2386+ return err ;
2387+ }
2388+ }
2389+ else {
2390+ deflateEnd (& strm );
2391+ return err ;
2392+ }
2393+
2394+ deflateEnd (& strm );
2395+ return ret ;
2396+ }
2397+
2398+ int decompress_gzip (const char * input , size_t compressed_length ,
2399+ char * output , size_t maxout )
2400+ {
2401+ z_stream strm = {0 };
2402+ strm .total_in = strm .avail_in = compressed_length ;
2403+ strm .total_out = strm .avail_out = maxout ;
2404+ strm .next_in = (Bytef * ) input ;
2405+ strm .next_out = (Bytef * ) output ;
2406+
2407+ strm .zalloc = Z_NULL ;
2408+ strm .zfree = Z_NULL ;
2409+ strm .opaque = Z_NULL ;
2410+
2411+ int err = -1 ;
2412+ int ret = -1 ;
2413+
2414+ err = inflateInit2 (& strm , (15 + 32 )); //15 window bits, and the +32 tells zlib to to detect if using gzip or zlib
2415+ if (err == Z_OK ) {
2416+ err = inflate (& strm , Z_FINISH );
2417+ if (err == Z_STREAM_END ) {
2418+ ret = strm .total_out ;
2419+ }
2420+ else {
2421+ inflateEnd (& strm );
2422+ return err ;
2423+ }
2424+ }
2425+ else {
2426+ inflateEnd (& strm );
2427+ return err ;
2428+ }
2429+
2430+ inflateEnd (& strm );
2431+ return ret ;
2432+ }
2433+ #endif
2434+
2435+ int compress_noop (const char * input , size_t input_length ,
2436+ char * output , size_t maxout , int clevel )
2437+ {
2438+ return 0 ;
2439+ }
2440+
2441+ int decompress_noop (const char * input , size_t compressed_length ,
2442+ char * output , size_t maxout )
2443+ {
2444+ return 0 ;
2445+ }
0 commit comments