Exemple #1
0
static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
{
  #ifdef USE_SUBBLOCK
  SubblockEnc_Free(&p->sb.sb);
  #endif
  if (p->lzma2)
  {
    Lzma2Enc_Destroy(p->lzma2);
    p->lzma2 = NULL;
  }
}
Exemple #2
0
static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
{
	SeqInFilter_Free(&p->filter);
	#ifdef USE_SUBBLOCK
	SbEncInStream_Free(&p->sb);
	#endif
	if (p->lzma2)
	{
	Lzma2Enc_Destroy(p->lzma2);
	p->lzma2 = NULL;
	}
}
Exemple #3
0
void CompressWithLZMA2(std::vector<unsigned char> &outBuf, const std::vector<unsigned char> &inBuf, Byte* ptrProperties)
{
	VectorInStream inStream = { &VectorInStream_Read, &inBuf, 0 };
	VectorOutStream outStream = { &VectorOutStream_Write, &outBuf };

	CLzma2EncHandle enc;
	enc = Lzma2Enc_Create(&g_Alloc, &g_BigAlloc);

	assert(enc);

	CLzma2EncProps props;
	Lzma2EncProps_Init(&props);			//Ivan need change the parameters later
	//props.lzmaProps.writeEndMark = 1; // 0 or 1
	//props.lzmaProps.level = 6;
	//props.lzmaProps.dictSize = 1 << 14;
	//props.lzmaProps.numThreads = 8;
	//props.numTotalThreads = 8;

	SRes res = Lzma2Enc_SetProps(enc, &props);
	assert(res == SZ_OK);

	outBuf.resize(1);		// no need

	outBuf[0] = Lzma2Enc_WriteProperties(enc);

	*ptrProperties = outBuf[0];		//no need this parameter.

	UInt64 resLen = inBuf.size();

	Byte header[8];
	for (int i = 0; i < 8; i++)
		header[i] = (Byte)(resLen >> (8 * i));

	res = Lzma2Enc_Encode(enc, &outStream.SeqOutStream, &inStream.SeqInStream, 0);		//res = Lzma2Enc_Encode(enc, (ISeqOutStream*)&outStream, (ISeqInStream*)&inStream, 0);

	assert(res == SZ_OK);

	Lzma2Enc_Destroy(enc);

	FILE *fout = fopen("data.dc.dat", "wb+");	//change the file name.
	
	fwrite(&outBuf[0], 1, 1, fout);
	fwrite(&header[0], 1, 8, fout);
	fwrite(&outBuf[1], 1, outBuf.size() - 1, fout);
	fclose(fout);
}
CEncoder::~CEncoder()
{
  if (_encoder != 0)
    Lzma2Enc_Destroy(_encoder);
}