Merge pull request #951 from facebook/lastBlock

saves 3-bytes on small input with streaming API
This commit is contained in:
Yann Collet
2017-12-14 15:39:50 -08:00
committed by GitHub
2 changed files with 10 additions and 5 deletions
+2 -1
View File
@@ -2535,7 +2535,8 @@ static size_t ZSTD_resetCStream_internal(ZSTD_CStream* zcs,
zcs->inToCompress = 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->streamStage = zcss_load;
zcs->frameEnded = 0;
+4
View File
@@ -126,6 +126,10 @@ $ZSTD -d > $INTOVOID && die "should have refused : compressed data from terminal
fi
$ECHO "test : null-length file roundtrip"
$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)"
$ZSTD -d tmpCompressed && die "wrong suffix error not detected!"
$ZSTD -df tmp && die "should have refused : wrong extension"