Add ZDICT_getHeaderSize()

This commit is contained in:
Sen Huang 2019-10-29 16:45:11 -04:00
parent 2ed5344e84
commit 3c36a7f13a
2 changed files with 13 additions and 0 deletions

View File

@ -48,6 +48,7 @@
# define ZDICT_STATIC_LINKING_ONLY
#endif
#include "zdict.h"
#include "decompress/zstd_decompress_internal.h" /* ZSTD_entropyDTables_t */
/*-*************************************
@ -99,6 +100,17 @@ unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize)
return MEM_readLE32((const char*)dictBuffer + 4);
}
size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize)
{
if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return 0;
{ ZSTD_entropyDTables_t dummyEntropyTables;
size_t headerSize;
dummyEntropyTables.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001);
headerSize = ZSTD_loadDEntropy(&dummyEntropyTables, dictBuffer, dictSize);
return ZSTD_isError(headerSize) ? 0 : headerSize;
}
}
/*-********************************************************
* Dictionary training functions

View File

@ -64,6 +64,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCap
/*====== Helper functions ======*/
ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize); /**< extracts dictID; @return zero if error (not a valid dictionary) */
ZDICTLIB_API size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize); /* returns dict header size; returns zero if error (not a valid dictionary) */
ZDICTLIB_API unsigned ZDICT_isError(size_t errorCode);
ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);