]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added ability to compress without specifying out filename
authorPaul Cruz <paulcruz74@fb.com>
Sat, 8 Jul 2017 00:07:05 +0000 (17:07 -0700)
committerPaul Cruz <paulcruz74@fb.com>
Sat, 8 Jul 2017 00:07:05 +0000 (17:07 -0700)
contrib/adaptive-compression/multi.c
contrib/adaptive-compression/run.sh

index 41fd9af49835c490554da8a6c64f561b03e8bc6d..78d9ca154fc988bac9b2bab62d5c5caa1609e30e 100644 (file)
@@ -367,18 +367,28 @@ static void printStats(cStat_t stats)
     DISPLAY("# times waited on job Write: %u\n\n", stats.waitWrite);
 }
 
-static int compressFilename(const char* const srcFilename, const char* const dstFilename)
+static int compressFilename(const char* const srcFilename, const char* const dstFilenameOrNull)
 {
     BYTE* const src = malloc(FILE_CHUNK_SIZE);
     unsigned const stdinUsed = !strcmp(srcFilename, stdinmark);
     FILE* const srcFile = stdinUsed ? stdin : fopen(srcFilename, "rb");
-    const char* const outFilename = (stdinUsed && !dstFilename) ? stdoutmark : dstFilename;
+    const char* const outFilenameIntermediate = (stdinUsed && !dstFilenameOrNull) ? stdoutmark : dstFilenameOrNull;
+    const char* outFilename = outFilenameIntermediate;
+    char fileAndSuffix[MAX_PATH];
     size_t const numJobs = MAX_NUM_JOBS;
     int ret = 0;
     adaptCCtx* ctx = NULL;
     UTIL_getTime(&g_startTime);
     g_streamedSize = 0;
 
+    if (!outFilenameIntermediate) {
+        if (snprintf(fileAndSuffix, MAX_PATH, "%s.zst", srcFilename) + 1 > MAX_PATH) {
+            DISPLAY("Error: output filename is too long\n");
+            ret = 1;
+            goto cleanup;
+        }
+        outFilename = fileAndSuffix;
+    }
 
     /* checking for errors */
     if (!srcFilename || !outFilename || !src || !srcFile) {
@@ -452,15 +462,10 @@ static int compressFilenames(const char** filenameTable, unsigned numFiles, unsi
 {
     int ret = 0;
     unsigned fileNum;
-    char outFile[MAX_PATH];
     for (fileNum=0; fileNum<numFiles; fileNum++) {
         const char* filename = filenameTable[fileNum];
-        if (snprintf(outFile, MAX_PATH, "%s.zst", filename) + 1 > MAX_PATH) {
-            DISPLAY("Error: output filename is too long\n");
-            return 1;
-        }
         if (!forceStdout) {
-            ret |= compressFilename(filename, outFile);
+            ret |= compressFilename(filename, NULL);
         }
         else {
             ret |= compressFilename(filename, stdoutmark);
index 67814ec1be649c37ffe3479bc0376670fa3cc3c0..3c40969e64da750f6dbd739614ff904d0133445e 100755 (executable)
@@ -151,6 +151,12 @@ echo "Running Tests With Multiple Files > stdout"
 zstd -d tmp.zst
 rm tmp*
 
+echo "Running single test without output filename"
+./multi tests/test2048.pdf -p
+zstd -d tests/test2048.pdf.zst -o tmp
+diff tmp tests/test2048.pdf
+rm tmp*
+
 echo "finished with tests"
 
 make clean