/** *\brief does data compression * *will be called from a thread. *should not try to allocate memory. *Need not be reentrant itself as it will only run once at a time. * *\param input input buffer (holding blk_sz bytes) *\param outbuf output buffer large enough for worst case compression *\returns number of bytes written to outbuf */ size_t compress(char *input, char *outbuf) { uint32_t preset = COMPRESSION_LEVEL | (COMPRESSION_EXTREME ? LZMA_PRESET_EXTREME : 0); int r; size_t out_pos=0; lzma_check check = INTEGRITY_CHECK; r=lzma_raw_buffer_encode(lz_flt,&lzma_alc,(uint8_t*)input,blk_sz,(uint8_t*)outbuf,&out_pos,bound); // r=lzma_easy_buffer_encode(preset,check,&lzma_alc,(uint8_t*)input,blk_sz,(uint8_t*)outbuf,&out_pos,bound); assert(r == LZMA_OK); return out_pos; }
size_t fa_compress_block(fa_compression_t compression, void* out, size_t outSize, const void* in, size_t inSize) { switch (compression) { default: return inSize; case FA_COMPRESSION_FASTLZ: { if (inSize < 16) { return inSize; } return fastlz_compress_level(2, in, inSize, out); } break; #if defined(FA_ZLIB_ENABLE) case FA_COMPRESSION_DEFLATE: { uLongf destLen = outSize; if (outSize < compressBound(inSize)) { return inSize; } if (compress2(out, &destLen, in, inSize, Z_DEFAULT_COMPRESSION) != Z_OK) { return inSize; } return destLen; } break; #endif #if defined(FA_LZMA_ENABLE) case FA_COMPRESSION_LZMA2: { size_t outPos = 0; lzma_filter filters[2]; lzma_options_lzma options; if (lzma_lzma_preset(&options, 6)) { return inSize; } filters[0].id = LZMA_FILTER_LZMA2; filters[0].options = &options; filters[1].id = LZMA_VLI_UNKNOWN; lzma_ret ret = lzma_raw_buffer_encode(filters, NULL, in, inSize, out, &outPos, outSize); if (ret != LZMA_OK) { return inSize; } return outPos; } break; #endif } }