Esempio n. 1
0
size_t fa_decompress_block(fa_compression_t compression, void* out, size_t outSize, const void* in, size_t inSize)
{
	switch (compression)
	{
		default: return 0;

		case FA_COMPRESSION_FASTLZ:
		{
			return fastlz_decompress(in, inSize, out, outSize);
		}
		break;
#if defined(FA_ZLIB_ENABLE)
		case FA_COMPRESSION_DEFLATE:
		{
			uLongf destLen = outSize;

			if (uncompress(out, &destLen, in, inSize) != Z_OK)
			{
				return 0;
			}

			return destLen;
		}
		break;
#endif

#if defined(FA_LZMA_ENABLE) 
		case FA_COMPRESSION_LZMA2:
		{
			size_t inPos = 0, outPos = 0;
			lzma_filter filters[2];
			lzma_options_lzma options;

			if (lzma_lzma_preset(&options, 6))
			{
				return 0;
			}

			filters[0].id = LZMA_FILTER_LZMA2;
			filters[0].options = &options;
			filters[1].id = LZMA_VLI_UNKNOWN;

			lzma_ret ret = lzma_raw_buffer_decode(filters, NULL, in, &inPos, inSize, out, &outPos, outSize);
			if (ret != LZMA_OK)
			{
				return 0;
			}

			return outPos; 
		}
		break;
#endif
	}
}
Esempio n. 2
0
/**
 *\brief does data decompression
 *
 *May be called from signal handler at any time, 
 *may be called from allocator on free(), 
 *but not both at the same time.
 *should not try to allocate memory. 
 *Need not be reentrant itself as it will only run once at a time, 
 *but may be concurrent with compress.
 *
 *\param input input buffer
 *\param in_sz input buffer size
 *\param outbuf output buffer
 *\returns number of bytes written to outbuf
 */
size_t uncompress(char *input, size_t in_sz, char *outbuf)
{
	int r;
	size_t in_pos=0;
	size_t out_pos=0;
	assert(in_sz!=0);
	r=lzma_raw_buffer_decode(lz_flt,&lzma_alc,(uint8_t*)input,&in_pos,in_sz,(uint8_t*)outbuf,&out_pos,blk_sz);
//	r=lzma_stream_buffer_decode(&dec_usg,0,&lzma_alc,(uint8_t*)input,&in_pos,in_sz,(uint8_t*)outbuf,&out_pos,blk_sz);
	assert(r == LZMA_OK && out_pos == blk_sz);
	return out_pos;
}