Merge pull request #951 from facebook/lastBlock
saves 3-bytes on small input with streaming API
This commit is contained in:
@@ -2535,7 +2535,8 @@ static size_t ZSTD_resetCStream_internal(ZSTD_CStream* zcs,
|
|||||||
|
|
||||||
zcs->inToCompress = 0;
|
zcs->inToCompress = 0;
|
||||||
zcs->inBuffPos = 0;
|
zcs->inBuffPos = 0;
|
||||||
zcs->inBuffTarget = zcs->blockSize;
|
zcs->inBuffTarget = zcs->blockSize
|
||||||
|
+ (zcs->blockSize == pledgedSrcSize); /* for small input: avoid automatic flush on reaching end of block, since it would require to add a 3-bytes null block to end frame */
|
||||||
zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0;
|
zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0;
|
||||||
zcs->streamStage = zcss_load;
|
zcs->streamStage = zcss_load;
|
||||||
zcs->frameEnded = 0;
|
zcs->frameEnded = 0;
|
||||||
@@ -2687,9 +2688,9 @@ size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|||||||
/* check expectations */
|
/* check expectations */
|
||||||
DEBUGLOG(5, "ZSTD_compressStream_generic, flush=%u", (U32)flushMode);
|
DEBUGLOG(5, "ZSTD_compressStream_generic, flush=%u", (U32)flushMode);
|
||||||
assert(zcs->inBuff != NULL);
|
assert(zcs->inBuff != NULL);
|
||||||
assert(zcs->inBuffSize>0);
|
assert(zcs->inBuffSize > 0);
|
||||||
assert(zcs->outBuff!= NULL);
|
assert(zcs->outBuff != NULL);
|
||||||
assert(zcs->outBuffSize>0);
|
assert(zcs->outBuffSize > 0);
|
||||||
assert(output->pos <= output->size);
|
assert(output->pos <= output->size);
|
||||||
assert(input->pos <= input->size);
|
assert(input->pos <= input->size);
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,10 @@ $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal
|
|||||||
fi
|
fi
|
||||||
$ECHO "test : null-length file roundtrip"
|
$ECHO "test : null-length file roundtrip"
|
||||||
$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
|
$ECHO -n '' | $ZSTD - --stdout | $ZSTD -d --stdout
|
||||||
|
$ECHO "test : ensure small file doesn't add 3-bytes null block"
|
||||||
|
./datagen -g1 > tmp1
|
||||||
|
$ZSTD tmp1 -c | wc -c | grep "14"
|
||||||
|
$ZSTD < tmp1 | wc -c | grep "14"
|
||||||
$ECHO "test : decompress file with wrong suffix (must fail)"
|
$ECHO "test : decompress file with wrong suffix (must fail)"
|
||||||
$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
|
$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
|
||||||
$ZSTD -df tmp && die "should have refused : wrong extension"
|
$ZSTD -df tmp && die "should have refused : wrong extension"
|
||||||
|
|||||||
Reference in New Issue
Block a user