Header related sample utility functions


   Header related sample utility functions


Header related sample utility functions.


These functions are necessary when compressing/decompressing files with buffer manipulations.

Compressed chunks need to be written to the output file in an orderly fashion.



int WriteXZipHeader(FILE* _fpOut, const int8_t _level, const uint8_t _exe_compression, const uint8_t _solid_compression, int32_t _chunk_to_process)

{

    if (!_fpOut) {

        return _LZNV_ERROR_INVALID_OUTPUT_FILE;

    }


    _putw(LZNV_LIB_HEADER_1, _fpOut);

    _putw(LZNV_LIB_HEADER_2, _fpOut);

    _putw(LZNV_LIB_HEADER_3, _fpOut);


    putc(_level, _fpOut);

    putc(_exe_compression, _fpOut);

    putc(_solid_compression, _fpOut);

    _putw(_chunk_to_process, _fpOut);


    return 0;

}


int ReadXZipHeader(FILE* _fpIn, uint8_t& _level, uint8_t& _exe_compression, uint8_t& _solid_compression, int32_t& _chunk_to_process)

{

    if (!_fpIn) {

        return _LZNV_ERROR_INVALID_INPUT_FILE;

    }


    if (LZNV_LIB_HEADER_1 != _getw(_fpIn)) {

        return _LZNV_ERROR_BAD_HEADER_INFO;

    }

    if (LZNV_LIB_HEADER_2 != _getw(_fpIn)) {

        return _LZNV_ERROR_BAD_HEADER_INFO;

    }

    if (LZNV_LIB_HEADER_3 != _getw(_fpIn)) {

        return _LZNV_ERROR_BAD_HEADER_INFO;

    }


    _level = (uint8_t)getc(_fpIn);

    _exe_compression = (uint8_t)getc(_fpIn);

    _solid_compression = (uint8_t)getc(_fpIn);

    _chunk_to_process = _getw(_fpIn);


    return 0;

}