Skip to content

Commit c496fd2

Browse files
author
Bimba Shrestha
authored
Merge pull request #2206 from bimbashrestha/stream-size
[cli] Allowing stdin on --patch-from using --stream-size
2 parents 4f59be7 + de48f35 commit c496fd2

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

programs/fileio.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ static void FIO_adjustMemLimitForPatchFromMode(FIO_prefs_t* const prefs,
772772
{
773773
unsigned long long maxSize = MAX(prefs->memLimit, MAX(dictSize, maxSrcFileSize));
774774
unsigned const maxWindowSize = (1U << ZSTD_WINDOWLOG_MAX);
775+
if (maxSize == UTIL_FILESIZE_UNKNOWN)
776+
EXM_THROW(42, "Using --patch-from with stdin requires --stream-size");
775777
assert(maxSize != UTIL_FILESIZE_UNKNOWN);
776778
if (maxSize > maxWindowSize)
777779
EXM_THROW(42, "Can't handle files larger than %u GB\n", maxWindowSize/(1 GB));
@@ -839,8 +841,10 @@ static cRess_t FIO_createCResources(FIO_prefs_t* const prefs,
839841

840842
/* need to update memLimit before calling createDictBuffer
841843
* because of memLimit check inside it */
842-
if (prefs->patchFromMode)
843-
FIO_adjustParamsForPatchFromMode(prefs, &comprParams, UTIL_getFileSize(dictFileName), maxSrcFileSize, cLevel);
844+
if (prefs->patchFromMode) {
845+
unsigned long long const ssSize = (unsigned long long)prefs->streamSrcSize;
846+
FIO_adjustParamsForPatchFromMode(prefs, &comprParams, UTIL_getFileSize(dictFileName), ssSize > 0 ? ssSize : maxSrcFileSize, cLevel);
847+
}
844848
ress.dstBuffer = malloc(ress.dstBufferSize);
845849
ress.dictBufferSize = FIO_createDictBuffer(&ress.dictBuffer, dictFileName, prefs); /* works with dictFileName==NULL */
846850
if (!ress.srcBuffer || !ress.dstBuffer)

tests/playTests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,13 @@ datagen -g5000000 > tmp_patch
13041304
zstd -15 --patch-from=tmp_dict tmp_patch 2>&1 | grep "long mode automatically triggered"
13051305
rm -rf tmp*
13061306

1307+
println "\n===> patch-from --stream-size test"
1308+
datagen -g1000 -P50 > tmp_dict
1309+
datagen -g1000 -P10 > tmp_patch
1310+
cat tmp_patch | zstd -f --patch-from=tmp_dict -c -o tmp_patch_diff && die
1311+
cat tmp_patch | zstd -f --patch-from=tmp_dict --stream-size=1000 -c -o tmp_patch_diff
1312+
rm -rf tmp*
1313+
13071314
println "\n===> large files tests "
13081315

13091316
roundTripTest -g270000000 1

0 commit comments

Comments
 (0)