Compressing a file using LZNV COM
8.2.1.2 Using the LZNV COM Object
8.2.1.2 Using the LZNV COM Object
This sample source code is available in LZNV_COM_Obj_Client_Tester.cpp [Project VC++CmdLineClient_for_LZNV_COM Client Project files]
#import <LZNV_COM_x64.tlb>
static const uint32_t _tbl_size_to_process[_LZNV_MAX_BUFFER_SIZE_INDX] = { 256 << 10, 512 << 10, 1 << 20, 2 << 20, 4 << 20, 8 << 20, 16 << 20 };
int _process_encode_file(LZNV_COM_Obj::ILZNV_COM_ObjPtr pLZNV_COM_Object_obj, const int32_t _lz_method, const int32_t _memory_level, const wchar_t* _wchr_file_in, const wchar_t* _wchr_file_out)
{
HRESULT _hres = 0;
ASSERT(pLZNV_COM_Object_obj);
if (pLZNV_COM_Object_obj == nullptr) {
return 0;
}
switch (_lz_method)
{
case _LZNV_ULTRAFAST_COMPRESSION: wprintf(L"\n Encoding w/ultrafast ");
break;
case _LZNV_SUPERFAST_COMPRESSION: wprintf(L"\n Encoding w/superfast ");
break;
case _LZNV_FAST_COMPRESSION: wprintf(L"\n Encoding w/fast ");
break;
case _LZNV_NORMAL_COMPRESSION: wprintf(L"\n Encoding w/normal ");
break;
case _LZNV_BETTER_COMPRESSION: wprintf(L"\n Encoding w/better ");
break;
}
int32_t _res = 0;
uint64_t fileSize = _get_wfile_size(_wchr_file_in);
int32_t _chunk_to_process = _tbl_size_to_process[_memory_level];
ASSERT(_chunk_to_process < ((64 << 20) + 1)); // 64MB Table Size MAX
if (_chunk_to_process > (64 << 20)) // 64MB Table Size MAX
{
return _LZNV_ERROR_INVALID_BUFFER_SIZE; // bad header info on chunk size
}
wprintf(L"\n Compressing %s [ %lld bytes] | _chunk_to_process: %d", _wchr_file_in, fileSize, _chunk_to_process);
LZNV_FILE_COMMAND_PARAMS _com_obj_file_cmd_struct = {0};
{
_com_obj_file_cmd_struct._cpu_priority_level = _LZNV_NORMAL_PRIORITY_CLASS;
_com_obj_file_cmd_struct._internal_verification = _LZNV_SET_INTERNAL_VERIFICATION_ON;
_com_obj_file_cmd_struct._command_to_execute = _LZNV_COMMAND_ENCODE;
ASSERT((_memory_level >= _LZNV_BUFFER_SIZE_256KB_INDX) && (_memory_level < _LZNV_MAX_BUFFER_SIZE_INDX));
if((_memory_level >= _LZNV_BUFFER_SIZE_256KB_INDX) && (_memory_level < _LZNV_MAX_BUFFER_SIZE_INDX))
{
_com_obj_file_cmd_struct._memory_level = _memory_level;
}
_com_obj_file_cmd_struct._encoding_method = _lz_method;
wcsncpy_s(_com_obj_file_cmd_struct._source_file_path, _LZNV_MAXPATH_, _wchr_file_in, _LZNV_MAXPATH_);
wcsncpy_s(_com_obj_file_cmd_struct._target_file_path, _LZNV_MAXPATH_, _wchr_file_out, _LZNV_MAXPATH_);
if (pLZNV_COM_Object_obj)
{
_hres = pLZNV_COM_Object_obj->LZNV_Main_((LZNV_COM_Obj::_LZNV_FILE_PARAM_TYPE*)&_com_obj_file_cmd_struct); //"->" overloading in action
}
}
// print stats
// ...
return _hres;
}