示例#1
0
SRes MyLzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
                const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
                ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
{
    CLzmaEncHandle *p = (CLzmaEncHandle *)LzmaEnc_Create(alloc);
    SRes res;
    if (p == 0)
        return SZ_ERROR_MEM;

    res = LzmaEnc_SetProps(p, props);
    if (res == SZ_OK)
    {
        res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
        if (res == SZ_OK)
            res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
            writeEndMark, progress, alloc, allocBig);
    }

    LzmaEnc_Destroy(p, alloc, allocBig);
    return res;
}
示例#2
0
 size32_t compress(const void* input, size32_t inlength, void* output)
 { // returns (size32_t)-1 if cannot compress
     if (!enc) {
         enc = LzmaEnc_Create(&g_Alloc);
         if (enc == 0)
             throw MakeStringException(-1,"LzmaEnc_Create failed");
         LzmaEncProps_Init(&props);
         if (LzmaEnc_SetProps(enc, &props)!=SZ_OK) 
             throw MakeStringException(-1,"LzmaEnc_SetProps failed");
     }
     if (inlength+LZMA_PROPS_SIZE+sizeof(size32_t)<1024)
         return (size32_t)-1; // don't compress less than 1K
     SizeT propsize = LZMA_PROPS_SIZE;
     LzmaEnc_WriteProperties(enc, (byte *)output+sizeof(size32_t), &propsize);
     *(size32_t *)output = (size32_t)propsize;
     SizeT reslen = inlength-1-propsize-sizeof(size32_t);
     SRes res = LzmaEnc_MemEncode(enc, (byte *)output+propsize+sizeof(size32_t), &reslen, (const byte *)input, inlength, true, NULL, &g_Alloc, &g_Alloc);
     if (res==SZ_ERROR_OUTPUT_EOF) 
         return (size32_t)-1;
     if (res!=SZ_OK)
         throw MakeStringException(-1,"LzmaEnc_MemEncode failed(%d)",(int)res);
     return reslen+propsize+sizeof(size32_t);
 }
示例#3
0
STATIC int jffs2_lzma_compress(unsigned char *data_in, unsigned char *cpage_out,
			      uint32_t *sourcelen, uint32_t *dstlen)
{
	SizeT compress_size = (SizeT)(*dstlen);
	int ret;

	#ifdef __KERNEL__
		mutex_lock(&deflate_mutex);
	#endif

	ret = LzmaEnc_MemEncode(p, cpage_out, &compress_size, data_in, *sourcelen,
		0, NULL, &lzma_alloc, &lzma_alloc);

	#ifdef __KERNEL__
		mutex_unlock(&deflate_mutex);
	#endif

	if (ret != SZ_OK)
		return -1;

	*dstlen = (uint32_t)compress_size;

	return 0;
}