Skip to content

Commit c931ebc

Browse files
committed
Add CLI Support
1 parent 0b101b9 commit c931ebc

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

programs/fileio.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ FIO_prefs_t* FIO_createPreferences(void)
308308
ret->allowBlockDevices = 0;
309309
ret->asyncIO = AIO_supported();
310310
ret->passThrough = -1;
311+
ret->constrainWindowForProtocol = ZSTD_ConstrainWindow_auto;
311312
return ret;
312313
}
313314

@@ -490,6 +491,12 @@ void FIO_setMMapDict(FIO_prefs_t* const prefs, ZSTD_ParamSwitch_e value)
490491
prefs->mmapDict = value;
491492
}
492493

494+
void FIO_setConstrainWindowForProtocol(
495+
FIO_prefs_t* const prefs,
496+
ZSTD_ConstrainWindow_e constraint) {
497+
prefs->constrainWindowForProtocol = constraint;
498+
}
499+
493500
/* FIO_ctx_t functions */
494501

495502
void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value) {
@@ -1188,6 +1195,7 @@ static cRess_t FIO_createCResources(FIO_prefs_t* const prefs,
11881195
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_overlapLog, prefs->overlapLog) );
11891196
}
11901197
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_rsyncable, prefs->rsyncable) );
1198+
CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_c_constrainWindowForProtocol, prefs->constrainWindowForProtocol) );
11911199
#endif
11921200
/* dictionary */
11931201
if (prefs->patchFromMode) {

programs/fileio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
9191
void FIO_setLiteralCompressionMode(
9292
FIO_prefs_t* const prefs,
9393
ZSTD_ParamSwitch_e mode);
94+
void FIO_setConstrainWindowForProtocol(
95+
FIO_prefs_t* const prefs,
96+
ZSTD_ConstrainWindow_e constraint);
9497

9598
void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);
9699
void FIO_setNotificationLevel(int level);

programs/fileio_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef struct FIO_prefs_s {
5454
int srcSizeHint;
5555
int testMode;
5656
ZSTD_ParamSwitch_e literalCompressionMode;
57+
ZSTD_ConstrainWindow_e constrainWindowForProtocol;
5758

5859
/* IO preferences */
5960
int removeSrcFile;

programs/zstd.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ the last one takes effect.
232232
This parameter defines a loose target: compressed blocks will target this size "on average", but individual blocks can still be larger or smaller.
233233
Enabling this feature can decrease compression speed by up to ~10% at level 1.
234234
Higher levels will see smaller relative speed regression, becoming invisible at higher settings.
235+
* `--constrain-window={none,http-zstd,http-dcz}`:
236+
Constrains the window size to the limits set by the indicated protocol.
237+
`none` (the default) doesn't set any constraints.
238+
`http-zstd` refers to the `zstd` HTTP Content-Encoding specified by RFCs 8878 and 9659.
239+
`http-dcz` refers to the `dcz` HTTP Content-Encoding specified by the Compression Dictionary Transport draft.
235240
* `-f`, `--force`:
236241
disable input and output checks. Allows overwriting existing files, input
237242
from console, output to stdout, operating on links, block devices, etc.

programs/zstdcli.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ static void usageAdvanced(const char* programName)
244244
DISPLAYOUT(" --stream-size=# Specify size of streaming input from STDIN.\n");
245245
DISPLAYOUT(" --size-hint=# Optimize compression parameters for streaming input of approximately size #.\n");
246246
DISPLAYOUT(" --target-compressed-block-size=#\n");
247-
DISPLAYOUT(" Generate compressed blocks of approximately # size.\n\n");
247+
DISPLAYOUT(" Generate compressed blocks of approximately # size.\n");
248+
DISPLAYOUT(" --constrain-window={none,http-zstd,http-dcz}\n");
249+
DISPLAYOUT(" Constrain window size to comply with limits set by protocol. [Default: none]\n\n");
248250
DISPLAYOUT(" --no-dictID Don't write `dictID` into the header (dictionary compression only).\n");
249251
DISPLAYOUT(" --[no-]compress-literals Force (un)compressed literals.\n");
250252
DISPLAYOUT(" --[no-]row-match-finder Explicitly enable/disable the fast, row-based matchfinder for\n");
@@ -851,6 +853,7 @@ int main(int argCount, const char* argv[])
851853
removeSrcFile=0;
852854
ZSTD_ParamSwitch_e mmapDict=ZSTD_ps_auto;
853855
ZSTD_ParamSwitch_e useRowMatchFinder = ZSTD_ps_auto;
856+
ZSTD_ConstrainWindow_e constrainWindowForProtocol = ZSTD_ConstrainWindow_auto;
854857
FIO_compressionType_t cType = FIO_zstdCompression;
855858
int nbWorkers = -1; /* -1 means unset */
856859
double compressibility = -1.0; /* lorem ipsum generator */
@@ -1135,6 +1138,23 @@ int main(int argCount, const char* argv[])
11351138
continue;
11361139
}
11371140

1141+
1142+
if (longCommandWArg(&argument, "--constrain-window")) {
1143+
const char* protocol;
1144+
NEXT_FIELD(protocol);
1145+
if (!strncmp(protocol, "none", strlen("none") + 1)) {
1146+
constrainWindowForProtocol = ZSTD_ConstrainWindow_HTTP_Zstd;
1147+
} else if (!strncmp(protocol, "http-zstd", strlen("http-zstd") + 1)) {
1148+
constrainWindowForProtocol = ZSTD_ConstrainWindow_HTTP_Zstd;
1149+
} else if (!strncmp(protocol, "http-dcz", strlen("http-dcz") + 1)) {
1150+
constrainWindowForProtocol = ZSTD_ConstrainWindow_HTTP_DCZ;
1151+
} else {
1152+
badUsage(programName, originalArgument);
1153+
CLEAN_RETURN(1);
1154+
}
1155+
continue;
1156+
}
1157+
11381158
badUsage(programName, originalArgument);
11391159
CLEAN_RETURN(1);
11401160
}
@@ -1573,6 +1593,7 @@ int main(int argCount, const char* argv[])
15731593
FIO_setSrcSizeHint(prefs, srcSizeHint);
15741594
FIO_setLiteralCompressionMode(prefs, literalCompressionMode);
15751595
FIO_setSparseWrite(prefs, 0);
1596+
FIO_setConstrainWindowForProtocol(prefs, constrainWindowForProtocol);
15761597
if (adaptMin > cLevel) cLevel = adaptMin;
15771598
if (adaptMax < cLevel) cLevel = adaptMax;
15781599

@@ -1603,6 +1624,7 @@ int main(int argCount, const char* argv[])
16031624
(void)ultra; (void)cLevel; (void)ldmFlag; (void)literalCompressionMode;
16041625
(void)targetCBlockSize; (void)streamSrcSize; (void)srcSizeHint;
16051626
(void)ZSTD_strategyMap; (void)useRowMatchFinder; (void)cType;
1627+
(void)constrainWindowForProtocol;
16061628
DISPLAYLEVEL(1, "Compression not supported \n");
16071629
#endif
16081630
} else { /* decompression or test */

0 commit comments

Comments
 (0)