From 989e0f0cee41727a76087a323dadc93561297250 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 21 Oct 2019 14:33:50 -0700 Subject: [PATCH] Added --output-dir-flat= which is a preferred construction when applicable. Also, added --output-dir-flat into man page. --- programs/zstd.1 | 4 ++++ programs/zstd.1.md | 7 +++++++ programs/zstdcli.c | 7 ++++--- tests/playTests.sh | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/programs/zstd.1 b/programs/zstd.1 index 1072c323..fef0e76e 100644 --- a/programs/zstd.1 +++ b/programs/zstd.1 @@ -175,6 +175,10 @@ keep source file(s) after successful compression or decompression\. This is the operate recursively on directories . .TP +\fB\-\-output\-dir\-flat[=dir]\fR +resulting files are stored into target \fBdir\fR directory, instead of same directory as origin file\. Be aware that this command can introduce name collision issues, if multiple files, from different directories, end up having the same name\. Collision resolution ensures first file with a given name will be present in \fBdir\fR, while in combination with \fB\-f\fR, the last file will be present instead\. +. +.TP \fB\-\-format=FORMAT\fR compress and decompress in other formats\. If compiled with support, zstd can compress to or decompress from other compression algorithm formats\. Possibly available options are \fBzstd\fR, \fBgzip\fR, \fBxz\fR, \fBlzma\fR, and \fBlz4\fR\. If no such format is provided, \fBzstd\fR is the default\. . diff --git a/programs/zstd.1.md b/programs/zstd.1.md index c1f321bc..e3daa4c8 100644 --- a/programs/zstd.1.md +++ b/programs/zstd.1.md @@ -191,6 +191,13 @@ the last one takes effect. This is the default behavior. * `-r`: operate recursively on directories +* `--output-dir-flat[=dir]`: + resulting files are stored into target `dir` directory, + instead of same directory as origin file. + Be aware that this command can introduce name collision issues, + if multiple files, from different directories, end up having the same name. + Collision resolution ensures first file with a given name will be present in `dir`, + while in combination with `-f`, the last file will be present instead. * `--format=FORMAT`: compress and decompress in other formats. If compiled with support, zstd can compress to or decompress from other compression algorithm diff --git a/programs/zstdcli.c b/programs/zstdcli.c index aed9ee86..803c5037 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -136,11 +136,10 @@ static int usage_advanced(const char* programName) DISPLAY( " -q : suppress warnings; specify twice to suppress errors too\n"); DISPLAY( " -c : force write to standard output, even if it is the console\n"); DISPLAY( " -l : print information about zstd compressed files \n"); - DISPLAY( " --output-dir-flat directory: results stored into `directory`. Filename collisions mean first file will be compressed. With -f, the last file will be compressed.\n"); #ifndef ZSTD_NOCOMPRESS DISPLAY( "--ultra : enable levels beyond %i, up to %i (requires more memory)\n", ZSTDCLI_CLEVEL_MAX, ZSTD_maxCLevel()); DISPLAY( "--long[=#]: enable long distance matching with given window log (default: %u)\n", g_defaultMaxWindowLog); - DISPLAY( "--fast[=#]: switch to ultra fast compression level (default: %u)\n", 1); + DISPLAY( "--fast[=#]: switch to very fast compression levels (default: %u)\n", 1); DISPLAY( "--adapt : dynamically adapt compression level to I/O conditions \n"); DISPLAY( "--stream-size=# : optimize compression parameters for streaming input of given number of bytes \n"); DISPLAY( "--size-hint=# optimize compression parameters for streaming input of approximately this size\n"); @@ -148,7 +147,7 @@ static int usage_advanced(const char* programName) #ifdef ZSTD_MULTITHREAD DISPLAY( " -T# : spawns # compression threads (default: 1, 0==# cores) \n"); DISPLAY( " -B# : select size of each job (default: 0==automatic) \n"); - DISPLAY( " --rsyncable : compress using a rsync-friendly method (-B sets block size) \n"); + DISPLAY( "--rsyncable : compress using a rsync-friendly method (-B sets block size) \n"); #endif DISPLAY( "--no-dictID : don't write dictID into header (dictionary compression)\n"); DISPLAY( "--[no-]check : integrity check (default: enabled) \n"); @@ -156,6 +155,7 @@ static int usage_advanced(const char* programName) #endif #ifdef UTIL_HAS_CREATEFILELIST DISPLAY( " -r : operate recursively on directories \n"); + DISPLAY( "--output-dir-flat[=directory]: all resulting files stored into `directory`. \n"); #endif DISPLAY( "--format=zstd : compress files to the .zst format (default) \n"); #ifdef ZSTD_GZCOMPRESS @@ -756,6 +756,7 @@ int main(int argCount, const char* argv[]) if (longCommandWArg(&argument, "--stream-size=")) { streamSrcSize = readU32FromChar(&argument); continue; } if (longCommandWArg(&argument, "--target-compressed-block-size=")) { targetCBlockSize = readU32FromChar(&argument); continue; } if (longCommandWArg(&argument, "--size-hint=")) { srcSizeHint = readU32FromChar(&argument); continue; } + if (longCommandWArg(&argument, "--output-dir-flat=")) { outDirName = argument; continue; } if (longCommandWArg(&argument, "--long")) { unsigned ldmWindowLog = 0; ldmFlag = 1; diff --git a/tests/playTests.sh b/tests/playTests.sh index c74d548b..796a5bde 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -287,6 +287,10 @@ mkdir tmpOutDirDecomp $ZSTD tmpOutDir -r -d --output-dir-flat tmpOutDirDecomp test -f tmpOutDirDecomp/tmp2 test -f tmpOutDirDecomp/tmp1 +rm -f tmpOutDirDecomp/* +$ZSTD tmpOutDir -r -d --output-dir-flat=tmpOutDirDecomp +test -f tmpOutDirDecomp/tmp2 +test -f tmpOutDirDecomp/tmp1 rm -rf tmp* println "\n===> Advanced compression parameters "