Change name to to findFrameCompressedSize and add skippable support

This commit is contained in:
Sean Purcell 2017-02-22 12:12:32 -08:00
parent 1f3d54ddb4
commit 9050e1925e
20 changed files with 48 additions and 37 deletions

2
NEWS
View File

@ -2,7 +2,7 @@ v1.1.4
cli : new : can compress in *.gz format, using --format=gzip command, by Przemyslaw Skibinski cli : new : can compress in *.gz format, using --format=gzip command, by Przemyslaw Skibinski
cli : new : advanced benchmark command --priority=rt cli : new : advanced benchmark command --priority=rt
cli : fix : write on sparse-enabled file systems in 32-bits mode, by @ds77 cli : fix : write on sparse-enabled file systems in 32-bits mode, by @ds77
API : new : ZSTD_getFrameCompressedSize(), ZSTD_getFrameContentSize(), ZSTD_findDecompressedSize(), by Sean Purcell API : new : ZSTD_findFrameCompressedSize(), ZSTD_getFrameContentSize(), ZSTD_findDecompressedSize(), by Sean Purcell
API : change : ZSTD_compress*() with srcSize==0 create an empty-frame of known size API : change : ZSTD_compress*() with srcSize==0 create an empty-frame of known size
build:new : meson build system in contrib/meson, by Dima Krasner build:new : meson build system in contrib/meson, by Dima Krasner
doc : new : educational decoder, by Sean Purcell doc : new : educational decoder, by Sean Purcell

View File

@ -369,7 +369,7 @@ unsigned long long ZSTD_findDecompressedSize(const void* src, size_t srcSize)
totalDstSize += ret; totalDstSize += ret;
} }
{ {
size_t const frameSrcSize = ZSTD_getFrameCompressedSize(src, srcSize); size_t const frameSrcSize = ZSTD_findFrameCompressedSize(src, srcSize);
if (ZSTD_isError(frameSrcSize)) { if (ZSTD_isError(frameSrcSize)) {
return ZSTD_CONTENTSIZE_ERROR; return ZSTD_CONTENTSIZE_ERROR;
} }
@ -1437,17 +1437,20 @@ size_t ZSTD_generateNxBytes(void* dst, size_t dstCapacity, BYTE byte, size_t len
return length; return length;
} }
/** ZSTD_getFrameCompressedSize() : /** ZSTD_findFrameCompressedSize() :
* compatible with legacy mode * compatible with legacy mode
* `src` must point to the start of a ZSTD or ZSTD legacy frame * `src` must point to the start of a ZSTD or ZSTD legacy frame
* `srcSize` must be at least as large as the frame contained * `srcSize` must be at least as large as the frame contained
* @return : the compressed size of the frame starting at `src` */ * @return : the compressed size of the frame starting at `src` */
size_t ZSTD_getFrameCompressedSize(const void *src, size_t srcSize) size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
{ {
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1) #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT==1)
if (ZSTD_isLegacy(src, srcSize)) return ZSTD_getFrameCompressedSizeLegacy(src, srcSize); if (ZSTD_isLegacy(src, srcSize)) return ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
#endif #endif
{ if (srcSize >= ZSTD_skippableHeaderSize &&
(MEM_readLE32(src) & 0xFFFFFFFF0U) == ZSTD_MAGIC_SKIPPABLE_START) {
return ZSTD_skippableHeaderSize + MEM_readLE32((const BYTE*)src + 4);
} else {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
const BYTE* const ipstart = ip; const BYTE* const ipstart = ip;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;
@ -1576,7 +1579,7 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1) #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
if (ZSTD_isLegacy(src, srcSize)) { if (ZSTD_isLegacy(src, srcSize)) {
size_t const frameSize = ZSTD_getFrameCompressedSizeLegacy(src, srcSize); size_t const frameSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
size_t decodedSize; size_t decodedSize;
if (ZSTD_isError(frameSize)) return frameSize; if (ZSTD_isError(frameSize)) return frameSize;

View File

@ -123,26 +123,26 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
} }
} }
MEM_STATIC size_t ZSTD_getFrameCompressedSizeLegacy(const void *src, MEM_STATIC size_t ZSTD_findFrameCompressedSizeLegacy(const void *src,
size_t compressedSize) size_t compressedSize)
{ {
U32 const version = ZSTD_isLegacy(src, compressedSize); U32 const version = ZSTD_isLegacy(src, compressedSize);
switch(version) switch(version)
{ {
case 1 : case 1 :
return ZSTDv01_getFrameCompressedSize(src, compressedSize); return ZSTDv01_findFrameCompressedSize(src, compressedSize);
case 2 : case 2 :
return ZSTDv02_getFrameCompressedSize(src, compressedSize); return ZSTDv02_findFrameCompressedSize(src, compressedSize);
case 3 : case 3 :
return ZSTDv03_getFrameCompressedSize(src, compressedSize); return ZSTDv03_findFrameCompressedSize(src, compressedSize);
case 4 : case 4 :
return ZSTDv04_getFrameCompressedSize(src, compressedSize); return ZSTDv04_findFrameCompressedSize(src, compressedSize);
case 5 : case 5 :
return ZSTDv05_getFrameCompressedSize(src, compressedSize); return ZSTDv05_findFrameCompressedSize(src, compressedSize);
case 6 : case 6 :
return ZSTDv06_getFrameCompressedSize(src, compressedSize); return ZSTDv06_findFrameCompressedSize(src, compressedSize);
case 7 : case 7 :
return ZSTDv07_getFrameCompressedSize(src, compressedSize); return ZSTDv07_findFrameCompressedSize(src, compressedSize);
default : default :
return ERROR(prefix_unknown); return ERROR(prefix_unknown);
} }

View File

@ -1992,7 +1992,7 @@ size_t ZSTDv01_decompress(void* dst, size_t maxDstSize, const void* src, size_t
return ZSTDv01_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize); return ZSTDv01_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
} }
size_t ZSTDv01_getFrameCompressedSize(const void* src, size_t srcSize) size_t ZSTDv01_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;

View File

@ -40,7 +40,7 @@ ZSTDv01_getFrameSrcSize() : get the source length of a ZSTD frame compliant with
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv01_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
*/ */
size_t ZSTDv01_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv01_findFrameCompressedSize(const void* src, size_t compressedSize);
/** /**
ZSTDv01_isError() : tells if the result of ZSTDv01_decompress() is an error ZSTDv01_isError() : tells if the result of ZSTDv01_decompress() is an error

View File

@ -3378,7 +3378,7 @@ static size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, siz
return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize); return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
} }
static size_t ZSTD_getFrameCompressedSize(const void *src, size_t srcSize) static size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
@ -3524,9 +3524,9 @@ size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize); return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
} }
size_t ZSTDv02_getFrameCompressedSize(const void *src, size_t compressedSize) size_t ZSTDv02_findFrameCompressedSize(const void *src, size_t compressedSize)
{ {
return ZSTD_getFrameCompressedSize(src, compressedSize); return ZSTD_findFrameCompressedSize(src, compressedSize);
} }
ZSTDv02_Dctx* ZSTDv02_createDCtx(void) ZSTDv02_Dctx* ZSTDv02_createDCtx(void)

View File

@ -40,7 +40,7 @@ ZSTDv02_getFrameSrcSize() : get the source length of a ZSTD frame compliant with
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv02_isError()) or an errorCode if it fails (which can be tested using ZSTDv02_isError())
*/ */
size_t ZSTDv02_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv02_findFrameCompressedSize(const void* src, size_t compressedSize);
/** /**
ZSTDv02_isError() : tells if the result of ZSTDv02_decompress() is an error ZSTDv02_isError() : tells if the result of ZSTDv02_decompress() is an error

View File

@ -3019,7 +3019,7 @@ static size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, siz
return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize); return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
} }
static size_t ZSTD_getFrameCompressedSize(const void* src, size_t srcSize) static size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;
@ -3165,9 +3165,9 @@ size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize); return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
} }
size_t ZSTDv03_getFrameCompressedSize(const void* src, size_t srcSize) size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
return ZSTD_getFrameCompressedSize(src, srcSize); return ZSTD_findFrameCompressedSize(src, srcSize);
} }
ZSTDv03_Dctx* ZSTDv03_createDCtx(void) ZSTDv03_Dctx* ZSTDv03_createDCtx(void)

View File

@ -40,7 +40,7 @@ ZSTDv03_getFrameSrcSize() : get the source length of a ZSTD frame compliant with
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv03_isError()) or an errorCode if it fails (which can be tested using ZSTDv03_isError())
*/ */
size_t ZSTDv03_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t compressedSize);
/** /**
ZSTDv03_isError() : tells if the result of ZSTDv03_decompress() is an error ZSTDv03_isError() : tells if the result of ZSTDv03_decompress() is an error

View File

@ -3326,7 +3326,7 @@ static size_t ZSTD_decompress_usingDict(ZSTD_DCtx* ctx,
return op-ostart; return op-ostart;
} }
static size_t ZSTD_getFrameCompressedSize(const void* src, size_t srcSize) static size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;
@ -3782,9 +3782,9 @@ size_t ZSTDv04_decompress(void* dst, size_t maxDstSize, const void* src, size_t
#endif #endif
} }
size_t ZSTDv04_getFrameCompressedSize(const void* src, size_t srcSize) size_t ZSTDv04_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
return ZSTD_getFrameCompressedSize(src, srcSize); return ZSTD_findFrameCompressedSize(src, srcSize);
} }
size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx) { return ZSTD_resetDCtx(dctx); } size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx) { return ZSTD_resetDCtx(dctx); }

View File

@ -40,7 +40,7 @@ ZSTDv04_getFrameSrcSize() : get the source length of a ZSTD frame compliant with
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv04_isError()) or an errorCode if it fails (which can be tested using ZSTDv04_isError())
*/ */
size_t ZSTDv04_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv04_findFrameCompressedSize(const void* src, size_t compressedSize);
/** /**
ZSTDv04_isError() : tells if the result of ZSTDv04_decompress() is an error ZSTDv04_isError() : tells if the result of ZSTDv04_decompress() is an error

View File

@ -3583,7 +3583,7 @@ size_t ZSTDv05_decompress(void* dst, size_t maxDstSize, const void* src, size_t
#endif #endif
} }
size_t ZSTDv05_getFrameCompressedSize(const void *src, size_t srcSize) size_t ZSTDv05_findFrameCompressedSize(const void *src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;

View File

@ -38,7 +38,7 @@ ZSTDv05_getFrameSrcSize() : get the source length of a ZSTD frame
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv05_isError()) or an errorCode if it fails (which can be tested using ZSTDv05_isError())
*/ */
size_t ZSTDv05_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv05_findFrameCompressedSize(const void* src, size_t compressedSize);
/* ************************************* /* *************************************
* Helper functions * Helper functions

View File

@ -3729,7 +3729,7 @@ size_t ZSTDv06_decompress(void* dst, size_t dstCapacity, const void* src, size_t
#endif #endif
} }
size_t ZSTDv06_getFrameCompressedSize(const void* src, size_t srcSize) size_t ZSTDv06_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;

View File

@ -47,7 +47,7 @@ ZSTDv06_getFrameSrcSize() : get the source length of a ZSTD frame
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv06_isError()) or an errorCode if it fails (which can be tested using ZSTDv06_isError())
*/ */
size_t ZSTDv06_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv06_findFrameCompressedSize(const void* src, size_t compressedSize);
/* ************************************* /* *************************************
* Helper functions * Helper functions

View File

@ -3968,7 +3968,7 @@ size_t ZSTDv07_decompress(void* dst, size_t dstCapacity, const void* src, size_t
#endif #endif
} }
size_t ZSTDv07_getFrameCompressedSize(const void* src, size_t srcSize) size_t ZSTDv07_findFrameCompressedSize(const void* src, size_t srcSize)
{ {
const BYTE* ip = (const BYTE*)src; const BYTE* ip = (const BYTE*)src;
size_t remainingSize = srcSize; size_t remainingSize = srcSize;

View File

@ -54,7 +54,7 @@ ZSTDv07_getFrameSrcSize() : get the source length of a ZSTD frame
return : the number of bytes that would be read to decompress this frame return : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv07_isError()) or an errorCode if it fails (which can be tested using ZSTDv07_isError())
*/ */
size_t ZSTDv07_getFrameCompressedSize(const void* src, size_t compressedSize); size_t ZSTDv07_findFrameCompressedSize(const void* src, size_t compressedSize);
/*====== Helper functions ======*/ /*====== Helper functions ======*/
ZSTDLIBv07_API unsigned ZSTDv07_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ ZSTDLIBv07_API unsigned ZSTDv07_isError(size_t code); /*!< tells if a `size_t` function result is an error code */

View File

@ -400,12 +400,12 @@ typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; v
* Compressed size functions * Compressed size functions
***************************************/ ***************************************/
/*! ZSTD_getFrameCompressedSize() : /*! ZSTD_findFrameCompressedSize() :
* `src` should point to the start of a ZSTD encoded frame * `src` should point to the start of a ZSTD encoded frame
* `srcSize` must be at least as large as the frame * `srcSize` must be at least as large as the frame
* @return : the compressed size of the frame pointed to by `src`, suitable to pass to * @return : the compressed size of the frame pointed to by `src`, suitable to pass to
* `ZSTD_decompress` or similar, or an error code if given invalid input. */ * `ZSTD_decompress` or similar, or an error code if given invalid input. */
ZSTDLIB_API size_t ZSTD_getFrameCompressedSize(const void* src, size_t srcSize); ZSTDLIB_API size_t ZSTD_findFrameCompressedSize(const void* src, size_t srcSize);
/*************************************** /***************************************
* Decompressed size functions * Decompressed size functions

View File

@ -545,6 +545,13 @@ static int basicUnitTests(U32 seed, double compressibility)
if (r != _3BYTESTESTLENGTH) goto _output_error; } if (r != _3BYTESTESTLENGTH) goto _output_error; }
DISPLAYLEVEL(4, "OK \n"); DISPLAYLEVEL(4, "OK \n");
/* findFrameCompressedSize on skippable frames */
DISPLAYLEVEL(4, "test%3i : frame compressed size of skippable frame : ", testNb++);
{ const char* frame = "\x50\x2a\x4d\x18\x05\x0\x0\0abcde";
size_t const frameSrcSize = 13;
if (ZSTD_findFrameCompressedSize(frame, frameSrcSize) != frameSrcSize) goto _output_error; }
DISPLAYLEVEL(4, "OK \n");
/* error string tests */ /* error string tests */
DISPLAYLEVEL(4, "test%3i : testing ZSTD error code strings : ", testNb++); DISPLAYLEVEL(4, "test%3i : testing ZSTD error code strings : ", testNb++);
if (strcmp("No error detected", ZSTD_getErrorName((ZSTD_ErrorCode)(0-ZSTD_error_no_error))) != 0) goto _output_error; if (strcmp("No error detected", ZSTD_getErrorName((ZSTD_ErrorCode)(0-ZSTD_error_no_error))) != 0) goto _output_error;

View File

@ -16,6 +16,7 @@ static const void *symbols[] = {
&ZSTD_decompress, &ZSTD_decompress,
&ZSTD_getDecompressedSize, &ZSTD_getDecompressedSize,
&ZSTD_findDecompressedSize, &ZSTD_findDecompressedSize,
&ZSTD_findFrameCompressedSize,
&ZSTD_getFrameContentSize, &ZSTD_getFrameContentSize,
&ZSTD_maxCLevel, &ZSTD_maxCLevel,
&ZSTD_compressBound, &ZSTD_compressBound,