Merge pull request #905 from terrelln/skip
Allow skippable frames of any size
This commit is contained in:
commit
6d3987b93a
@ -2555,17 +2555,21 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|||||||
/* fall-through */
|
/* fall-through */
|
||||||
case zdss_load:
|
case zdss_load:
|
||||||
{ size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
|
{ size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds);
|
||||||
size_t const toLoad = neededInSize - zds->inPos; /* should always be <= remaining space within inBuff */
|
size_t const toLoad = neededInSize - zds->inPos;
|
||||||
|
int const isSkipFrame = ZSTD_isSkipFrame(zds);
|
||||||
size_t loadedSize;
|
size_t loadedSize;
|
||||||
|
if (isSkipFrame) {
|
||||||
|
loadedSize = MIN(toLoad, (size_t)(iend-ip));
|
||||||
|
} else {
|
||||||
if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */
|
if (toLoad > zds->inBuffSize - zds->inPos) return ERROR(corruption_detected); /* should never happen */
|
||||||
loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
|
loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
|
||||||
|
}
|
||||||
ip += loadedSize;
|
ip += loadedSize;
|
||||||
zds->inPos += loadedSize;
|
zds->inPos += loadedSize;
|
||||||
if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */
|
if (loadedSize < toLoad) { someMoreWork = 0; break; } /* not enough input, wait for more */
|
||||||
|
|
||||||
/* decode loaded input */
|
/* decode loaded input */
|
||||||
{ const int isSkipFrame = ZSTD_isSkipFrame(zds);
|
{ size_t const decodedSize = ZSTD_decompressContinue(zds,
|
||||||
size_t const decodedSize = ZSTD_decompressContinue(zds,
|
|
||||||
zds->outBuff + zds->outStart, zds->outBuffSize - zds->outStart,
|
zds->outBuff + zds->outStart, zds->outBuffSize - zds->outStart,
|
||||||
zds->inBuff, neededInSize);
|
zds->inBuff, neededInSize);
|
||||||
if (ZSTD_isError(decodedSize)) return decodedSize;
|
if (ZSTD_isError(decodedSize)) return decodedSize;
|
||||||
|
@ -525,7 +525,7 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
off += r;
|
off += r;
|
||||||
if (i == segs/2) {
|
if (i == segs/2) {
|
||||||
/* insert skippable frame */
|
/* insert skippable frame */
|
||||||
const U32 skipLen = 128 KB;
|
const U32 skipLen = 129 KB;
|
||||||
MEM_writeLE32((BYTE*)compressedBuffer + off, ZSTD_MAGIC_SKIPPABLE_START);
|
MEM_writeLE32((BYTE*)compressedBuffer + off, ZSTD_MAGIC_SKIPPABLE_START);
|
||||||
MEM_writeLE32((BYTE*)compressedBuffer + off + 4, skipLen);
|
MEM_writeLE32((BYTE*)compressedBuffer + off + 4, skipLen);
|
||||||
off += skipLen + ZSTD_skippableHeaderSize;
|
off += skipLen + ZSTD_skippableHeaderSize;
|
||||||
|
@ -213,7 +213,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
|
|||||||
{
|
{
|
||||||
size_t const CNBufferSize = COMPRESSIBLE_NOISE_LENGTH;
|
size_t const CNBufferSize = COMPRESSIBLE_NOISE_LENGTH;
|
||||||
void* CNBuffer = malloc(CNBufferSize);
|
void* CNBuffer = malloc(CNBufferSize);
|
||||||
size_t const skippableFrameSize = 11;
|
size_t const skippableFrameSize = 200 KB;
|
||||||
size_t const compressedBufferSize = (8 + skippableFrameSize) + ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH);
|
size_t const compressedBufferSize = (8 + skippableFrameSize) + ZSTD_compressBound(COMPRESSIBLE_NOISE_LENGTH);
|
||||||
void* compressedBuffer = malloc(compressedBufferSize);
|
void* compressedBuffer = malloc(compressedBufferSize);
|
||||||
size_t const decodedBufferSize = CNBufferSize;
|
size_t const decodedBufferSize = CNBufferSize;
|
||||||
|
Loading…
Reference in New Issue
Block a user