Test new ZSTD_findFrameCompressedSize and update documentation
This commit is contained in:
parent
8cd423a659
commit
19b75b6ecb
@ -242,6 +242,17 @@ typedef struct {
|
||||
U32 longLengthPos;
|
||||
} seqStore_t;
|
||||
|
||||
/**
|
||||
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
||||
* Note: before using `compressedSize` you must check for errors using ZSTD_isError().
|
||||
* similarly, before using `decompressedBound`, you must check for errors using:
|
||||
* `decompressedBound` != ZSTD_CONTENTSIZE_ERROR
|
||||
*/
|
||||
typedef struct {
|
||||
size_t compressedSize;
|
||||
unsigned long long decompressedBound;
|
||||
} ZSTD_frameSizeInfo;
|
||||
|
||||
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
||||
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
||||
|
||||
|
@ -20,7 +20,7 @@ extern "C" {
|
||||
***************************************/
|
||||
#include "mem.h" /* MEM_STATIC */
|
||||
#include "error_private.h" /* ERROR */
|
||||
#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer */
|
||||
#include "zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
|
||||
|
||||
#if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
|
||||
# undef ZSTD_LEGACY_SUPPORT
|
||||
@ -178,12 +178,6 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
|
||||
}
|
||||
}
|
||||
|
||||
MEM_STATIC void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
|
||||
{
|
||||
*cSize = ret;
|
||||
*dBound = ZSTD_CONTENTSIZE_ERROR;
|
||||
}
|
||||
|
||||
MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size_t srcSize)
|
||||
{
|
||||
U32 const version = ZSTD_isLegacy(src, srcSize);
|
||||
@ -234,8 +228,8 @@ MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size
|
||||
break;
|
||||
#endif
|
||||
default :
|
||||
ZSTD_errorFrameSizeInfoLegacy(&frameSizeInfo.compressedSize,
|
||||
&frameSizeInfo.decompressedBound, ERROR(prefix_unknown));
|
||||
frameSizeInfo.compressedSize = ERROR(prefix_unknown);
|
||||
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||
break;
|
||||
}
|
||||
return frameSizeInfo;
|
||||
|
@ -36,10 +36,12 @@ size_t ZSTDv01_decompress( void* dst, size_t maxOriginalSize,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv01_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.1.x format
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv01_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.1.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv01_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
@ -36,10 +36,12 @@ size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv02_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.2.x format
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv02_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.2.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv02_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
@ -36,10 +36,12 @@ size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv03_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.3.x format
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv03_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.3.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv03_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
@ -36,10 +36,12 @@ size_t ZSTDv04_decompress( void* dst, size_t maxOriginalSize,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv04_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.4.x format
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv04_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.4.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
@ -34,10 +34,12 @@ size_t ZSTDv05_decompress( void* dst, size_t dstCapacity,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv05_getFrameSrcSize() : get the source length of a ZSTD frame
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv05_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.5.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
@ -43,10 +43,12 @@ ZSTDLIBv06_API size_t ZSTDv06_decompress( void* dst, size_t dstCapacity,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv06_getFrameSrcSize() : get the source length of a ZSTD frame
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv06_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.6.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
@ -50,10 +50,12 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress( void* dst, size_t dstCapacity,
|
||||
const void* src, size_t compressedSize);
|
||||
|
||||
/**
|
||||
ZSTDv07_getFrameSrcSize() : get the source length of a ZSTD frame
|
||||
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
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())
|
||||
ZSTDv07_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.7.x format
|
||||
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
||||
cSize (output parameter) : 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())
|
||||
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
|
||||
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
||||
*/
|
||||
void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
||||
size_t* cSize, unsigned long long* dBound);
|
||||
|
11
lib/zstd.h
11
lib/zstd.h
@ -1085,17 +1085,6 @@ typedef enum {
|
||||
* Frame size functions
|
||||
***************************************/
|
||||
|
||||
/**
|
||||
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
||||
* Note: before using `compressedSize` you must check for errors using ZSTD_isError().
|
||||
* similarly, before using `decompressedBound`, you must check for errors using:
|
||||
* `decompressedBound` != ZSTD_CONTENTSIZE_ERROR
|
||||
*/
|
||||
typedef struct {
|
||||
size_t compressedSize;
|
||||
unsigned long long decompressedBound;
|
||||
} ZSTD_frameSizeInfo;
|
||||
|
||||
/*! ZSTD_findDecompressedSize() :
|
||||
* `src` should point to the start of a series of ZSTD encoded and/or skippable frames
|
||||
* `srcSize` must be the _exact_ size of this series
|
||||
|
@ -137,6 +137,23 @@ static int testFrameDecoding(void)
|
||||
DISPLAY("ERROR: ZSTD_decompressBound: decompressed bound too small\n");
|
||||
return 1;
|
||||
}
|
||||
{ const char* ip = COMPRESSED;
|
||||
size_t remainingSize = COMPRESSED_SIZE;
|
||||
while (1) {
|
||||
size_t frameSize = ZSTD_findFrameCompressedSize(ip, remainingSize);
|
||||
if (ZSTD_isError(frameSize)) {
|
||||
DISPLAY("ERROR: ZSTD_findFrameCompressedSize: %s\n", ZSTD_getErrorName(frameSize));
|
||||
return 1;
|
||||
}
|
||||
if (frameSize > remainingSize) {
|
||||
DISPLAY("ERROR: ZSTD_findFrameCompressedSize: expected frameSize to align with src buffer");
|
||||
return 1;
|
||||
}
|
||||
ip += frameSize;
|
||||
remainingSize -= frameSize;
|
||||
if (remainingSize == 0) break;
|
||||
}
|
||||
}
|
||||
DISPLAY("Frame Decoding OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user