STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *coderProps, UInt32 numProps) { CLzma2EncProps lzma2Props; Lzma2EncProps_Init(&lzma2Props); for (UInt32 i = 0; i < numProps; i++) { RINOK(SetLzma2Prop(propIDs[i], coderProps[i], lzma2Props)); } return SResToHRESULT(Lzma2Enc_SetProps(_encoder, &lzma2Props)); }
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); }