Compressing a file with LZNV DLL
6.1 Compressing a file with LZNV DLL
6.1 Compressing (encoding) a file using the LZNV DLL
The code is available in function _loadDLL from LZNV_DLL_Tester.cpp
#include <LZNV_Defines.h> // load header file from predefined include paths
/// \brief LZNV_Encode_File performs a straight forward file compression without the need of any prior buffer manipulation.
/// \note The function performs internal buffering. If you want to perform your own buffering, please use LZNV_Encode_File_wBuffer.
/// \param[in] _encoding_method One of the methods _LZNV_ULTRAFAST_COMPRESSION to _LZNV_BETTER_COMPRESSION or _LZNV_COMPRESSION_STORE to _LZNV_RLE64_COMPRESSION.
/// \param[in] _memory_level The working size of the LZ algorithm. _LZNV_BUFFER_SIZE_256KB_INDX to _LZNV_BUFFER_SIZE_16MB_INDX.
/// \param[in] _wchr_filename_to_compress Input file path to compress. Unicode WCHAR.
/// \param[in] _wchr_output_filename Output file path to compress. Unicode WCHAR.
/// \return returns NO_ERROR (0) in case of no errors or one of the error codes defined in LZNV_Defines.h header file
/// other possible values:
/// - _LZNV_ERROR_INVALID_COMPRESSION_METHOD
/// - _LZNV_ERROR_INVALID_BUFFER_SIZE
/// - _LZNV_ERROR_EXPORTED_MAIN_FUNC_NOT_FOUND
/// - _LZNV_ERROR_INVALID_PROCESS_SIZE
///
int32_t LZNV_Encode_File(const uint8_t _encoding_method, const uint32_t _memory_level, // chunk_size == 0 -> read whole file in memory
const wchar_t* _wchr_filename_to_compress, const wchar_t* _wchr_output_filename)
{
int32_t _res = _LZNV_NO_ERROR_;
ASSERT(_p_LZNV_DLL_Main_File_funct);
if (!_p_LZNV_DLL_Main_File_funct) {
wprintf(L"\n LZNV DLL Not Loaded? Aborting...\n\n");
return 1;
}
ASSERT(_wchr_output_filename);
ASSERT(_wchr_filename_to_compress);
if((!_wchr_filename_to_compress) || (!_wchr_output_filename))
{
wprintf(L"\n LZNV DLL passed NULL parameters..\n\n");
return 1;
}
ASSERT(_memory_level < _LZNV_MAX_BUFFER_SIZE_INDX);
ASSERT(((_encoding_method >= _LZNV_ULTRAFAST_COMPRESSION) && (_encoding_method < _LZNV_MAX_LZ_ALGORITHMS)) ||
((_encoding_method >= _LZNV_COMPRESSION_STORE) && (_encoding_method < _LZNV_MAX_ENTROPY_ALGORITHMS)));
if (!(((_encoding_method >= _LZNV_ULTRAFAST_COMPRESSION) && (_encoding_method < _LZNV_MAX_LZ_ALGORITHMS)) ||
((_encoding_method >= _LZNV_COMPRESSION_STORE) && (_encoding_method < _LZNV_MAX_ENTROPY_ALGORITHMS))))
{
return _LZNV_ERROR_INVALID_COMPRESSION_METHOD;
}
{
LZNV_FILE_COMMAND_PARAMS _lznv_file_command = { 0 };
_lznv_file_command._encoding_method = _encoding_method;
_lznv_file_command._memory_level = _LZNV_BUFFER_SIZE_1MB_INDX;
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))
{
_lznv_file_command._memory_level = _memory_level; // _LZNV_BUFFER_SIZE_4MB;
}
_lznv_file_command._command_to_execute = _LZNV_COMMAND_ENCODE;
_lznv_file_command._cpu_priority_level = _LZNV_NORMAL_PRIORITY_CLASS;
ASSERT(_wchr_filename_to_compress);
wcsncpy_s(_lznv_file_command._source_file_path, _wchr_filename_to_compress, _LZNV_MAXPATH_);
ASSERT(_wchr_output_filename);
wcsncpy_s(_lznv_file_command._target_file_path, _wchr_output_filename, _LZNV_MAXPATH_);
int64_t s = _get_ms(); // use a high performance counter
_res = (*_p_LZNV_DLL_Main_File_funct)(_lznv_file_command);
int64_t e = _get_ms();
// Show Stats ...
}
return _res;
}