diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2020-02-08 02:49:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-08 02:49:24 (GMT) |
commit | 9f3ee5522312162acebb6c893dc77b5e0632f2ee (patch) | |
tree | a5adfc467c04e690b25303f8cffb5a1e86adf566 | |
parent | 8372862e0f7e072cb206e96c70f6e1a796b66fe6 (diff) | |
parent | 3f53227b9652acf012df63e577758534b5a4b9a3 (diff) | |
download | lz4-9f3ee5522312162acebb6c893dc77b5e0632f2ee.zip lz4-9f3ee5522312162acebb6c893dc77b5e0632f2ee.tar.gz lz4-9f3ee5522312162acebb6c893dc77b5e0632f2ee.tar.bz2 |
Merge pull request #843 from filipecalasans/multiples-files-with-legacy
Implement -m option with legacy format on cli
-rw-r--r-- | programs/lz4cli.c | 11 | ||||
-rw-r--r-- | programs/lz4io.c | 51 | ||||
-rw-r--r-- | tests/Makefile | 40 |
3 files changed, 97 insertions, 5 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c index aadccab..67dcaa1 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -94,7 +94,10 @@ static unsigned displayLevel = 2; /* 0 : no display ; 1: errors only ; 2 : dow #define DEFAULT_COMPRESSOR LZ4IO_compressFilename #define DEFAULT_DECOMPRESSOR LZ4IO_decompressFilename int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs, const char* input_filename, const char* output_filename, int compressionlevel); /* hidden function */ - +int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs, + const char** inFileNamesTable, int ifntSize, + const char* suffix, + int compressionLevel); /*-*************************** * Functions @@ -754,7 +757,11 @@ int main(int argc, const char** argv) } else { /* compression is default action */ if (legacy_format) { DISPLAYLEVEL(3, "! Generating LZ4 Legacy format (deprecated) ! \n"); - LZ4IO_compressFilename_Legacy(prefs, input_filename, output_filename, cLevel); + if(multiple_inputs){ + LZ4IO_compressMultipleFilenames_Legacy(prefs, inFileNames, (int)ifnIdx, !strcmp(output_filename,stdoutmark) ? stdoutmark : LZ4_EXTENSION, cLevel); + } else { + LZ4IO_compressFilename_Legacy(prefs, input_filename, output_filename, cLevel); + } } else { if (multiple_inputs) { assert(ifnIdx <= INT_MAX); diff --git a/programs/lz4io.c b/programs/lz4io.c index ec6dc7f..7926b20 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -470,11 +470,59 @@ int LZ4IO_compressFilename_Legacy(LZ4IO_prefs_t* const prefs, const char* input_ free(in_buff); free(out_buff); fclose(finput); - fclose(foutput); + if (strcmp(output_filename,stdoutmark)) fclose(foutput); /* do not close stdout */ return 0; } +#define FNSPACE 30 +/* LZ4IO_compressMultipleFilenames_Legacy : + * This function is intentionally "hidden" (not published in .h) + * It generates multiple compressed streams using the old 'legacy' format */ +int LZ4IO_compressMultipleFilenames_Legacy(LZ4IO_prefs_t* const prefs, + const char** inFileNamesTable, int ifntSize, + const char* suffix, + int compressionLevel) +{ + int i; + int missed_files = 0; + char* dstFileName = (char*)malloc(FNSPACE); + size_t ofnSize = FNSPACE; + const size_t suffixSize = strlen(suffix); + + if (dstFileName == NULL) return ifntSize; /* not enough memory */ + + /* loop on each file */ + for (i=0; i<ifntSize; i++) { + size_t const ifnSize = strlen(inFileNamesTable[i]); + if (!strcmp(suffix, stdoutmark)) { + missed_files += LZ4IO_compressFilename_Legacy(prefs, + inFileNamesTable[i], stdoutmark, + compressionLevel); + continue; + } + + if (ofnSize <= ifnSize+suffixSize+1) { + free(dstFileName); + ofnSize = ifnSize + 20; + dstFileName = (char*)malloc(ofnSize); + if (dstFileName==NULL) { + return ifntSize; + } } + strcpy(dstFileName, inFileNamesTable[i]); + strcat(dstFileName, suffix); + + missed_files += LZ4IO_compressFilename_Legacy(prefs, + inFileNamesTable[i], dstFileName, + compressionLevel); + } + + /* Close & Free */ + free(dstFileName); + + return missed_files; +} + /********************************************* * Compression using Frame format @@ -749,7 +797,6 @@ int LZ4IO_compressFilename(LZ4IO_prefs_t* const prefs, const char* srcFileName, } -#define FNSPACE 30 int LZ4IO_compressMultipleFilenames(LZ4IO_prefs_t* const prefs, const char** inFileNamesTable, int ifntSize, const char* suffix, diff --git a/tests/Makefile b/tests/Makefile index 422baba..1f8321c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -259,6 +259,44 @@ test-lz4-multiple: lz4 datagen ! $(LZ4) -f -m tmp-tlm-concat1 notHere tmp-tlm-concat2 # must fail : notHere not present @$(RM) tmp-tlm* +test-lz4-multiple-legacy: lz4 datagen + @echo "\n ---- test multiple files (Legacy format) ----" + @./datagen -s1 > tmp-tlm1 2> $(VOID) + @./datagen -s2 -g100K > tmp-tlm2 2> $(VOID) + @./datagen -s3 -g200K > tmp-tlm3 2> $(VOID) + # compress multiple files using legacy format: one .lz4 per source file + $(LZ4) -f -l -m tmp-tlm* + test -f tmp-tlm1.lz4 + test -f tmp-tlm2.lz4 + test -f tmp-tlm3.lz4 + # decompress multiple files compressed using legacy format: one output file per .lz4 + mv tmp-tlm1 tmp-tlm1-orig + mv tmp-tlm2 tmp-tlm2-orig + mv tmp-tlm3 tmp-tlm3-orig + $(LZ4) -d -f -m tmp-tlm*.lz4 + $(LZ4) -l -d -f -m tmp-tlm*.lz4 # -l mustn't impact -d option + $(CMP) tmp-tlm1 tmp-tlm1-orig # must be identical + $(CMP) tmp-tlm2 tmp-tlm2-orig + $(CMP) tmp-tlm3 tmp-tlm3-orig + # compress multiple files into stdout using legacy format + cat tmp-tlm1.lz4 tmp-tlm2.lz4 tmp-tlm3.lz4 > tmp-tlm-concat1 + $(RM) *.lz4 + $(LZ4) -l -m tmp-tlm1 tmp-tlm2 tmp-tlm3 -c > tmp-tlm-concat2 + test ! -f tmp-tlm1.lz4 # must not create .lz4 artefact + $(CMP) tmp-tlm-concat1 tmp-tlm-concat2 # must be equivalent + # # # decompress multiple files into stdout using legacy format + $(RM) tmp-tlm-concat1 tmp-tlm-concat2 + $(LZ4) -l -f -m tmp-tlm1 tmp-tlm2 tmp-tlm3 # generate .lz4 to decompress + cat tmp-tlm1 tmp-tlm2 tmp-tlm3 > tmp-tlm-concat1 # create concatenated reference + $(RM) tmp-tlm1 tmp-tlm2 tmp-tlm3 + $(LZ4) -d -m tmp-tlm1.lz4 tmp-tlm2.lz4 tmp-tlm3.lz4 -c > tmp-tlm-concat2 + $(LZ4) -d -l -m tmp-tlm1.lz4 tmp-tlm2.lz4 tmp-tlm3.lz4 -c > tmp-tlm-concat2 # -l mustn't impact option -d + test ! -f tmp-tlm1 # must not create file artefact + $(CMP) tmp-tlm-concat1 tmp-tlm-concat2 # must be equivalent + # # # compress multiple files, one of which is absent (must fail) + ! $(LZ4) -f -l -m tmp-tlm-concat1 notHere-legacy tmp-tlm-concat2 # must fail : notHere-legacy not present + @$(RM) tmp-tlm* + test-lz4-basic: lz4 datagen unlz4 lz4cat @echo "\n ---- test lz4 basic compression/decompression ----" ./datagen -g0 | $(LZ4) -v | $(LZ4) -t @@ -393,7 +431,7 @@ test-lz4-opt-parser: lz4 datagen ./datagen -g16M -P90 | $(LZ4) -11B5 | $(LZ4) -t ./datagen -g32M -P10 | $(LZ4) -11B5D | $(LZ4) -t -test-lz4-essentials : lz4 datagen test-lz4-basic test-lz4-multiple \ +test-lz4-essentials : lz4 datagen test-lz4-basic test-lz4-multiple test-lz4-multiple-legacy \ test-lz4-frame-concatenation test-lz4-testmode \ test-lz4-contentSize test-lz4-dict @$(RM) tmp* |