mirror of
				https://github.com/facebook/zstd.git
				synced 2025-10-31 16:47:48 +02:00 
			
		
		
		
	Allow -o with multiple files
This commit is contained in:
		| @@ -939,7 +939,7 @@ int FIO_compressFilename(const char* dstFileName, const char* srcFileName, | ||||
|  | ||||
|  | ||||
| int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFiles, | ||||
|                                   const char* suffix, | ||||
|                                   const char* outFileName, const char* suffix, | ||||
|                                   const char* dictFileName, int compressionLevel, | ||||
|                                   ZSTD_compressionParameters* comprParams) | ||||
| { | ||||
| @@ -955,16 +955,15 @@ int FIO_compressMultipleFilenames(const char** inFileNamesTable, unsigned nbFile | ||||
|     /* init */ | ||||
|     if (dstFileName==NULL) | ||||
|         EXM_THROW(27, "FIO_compressMultipleFilenames : allocation error for dstFileName"); | ||||
|     if (suffix == NULL) | ||||
|     if (outFileName == NULL && suffix == NULL) | ||||
|         EXM_THROW(28, "FIO_compressMultipleFilenames : dst unknown");  /* should never happen */ | ||||
|  | ||||
|     /* loop on each file */ | ||||
|     if (!strcmp(suffix, stdoutmark)) { | ||||
|     if (outFileName != NULL) { | ||||
|         unsigned u; | ||||
|         ress.dstFile = stdout; | ||||
|         SET_BINARY_MODE(stdout); | ||||
|         ress.dstFile = FIO_openDstFile(outFileName); | ||||
|         for (u=0; u<nbFiles; u++) | ||||
|             missed_files += FIO_compressFilename_srcFile(ress, stdoutmark, inFileNamesTable[u], compressionLevel); | ||||
|             missed_files += FIO_compressFilename_srcFile(ress, outFileName, inFileNamesTable[u], compressionLevel); | ||||
|         if (fclose(ress.dstFile)) | ||||
|             EXM_THROW(29, "Write error : cannot properly close stdout"); | ||||
|     } else { | ||||
| @@ -1654,24 +1653,21 @@ int FIO_decompressFilename(const char* dstFileName, const char* srcFileName, | ||||
|  | ||||
| #define MAXSUFFIXSIZE 8 | ||||
| int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles, | ||||
|                                     const char* suffix, | ||||
|                                     const char* outFileName, | ||||
|                                     const char* dictFileName) | ||||
| { | ||||
|     int skippedFiles = 0; | ||||
|     int missingFiles = 0; | ||||
|     dRess_t ress = FIO_createDResources(dictFileName); | ||||
|  | ||||
|     if (suffix==NULL) | ||||
|         EXM_THROW(70, "zstd: decompression: unknown dst");   /* should never happen */ | ||||
|  | ||||
|     if (!strcmp(suffix, stdoutmark) || !strcmp(suffix, nulmark)) {  /* special cases : -c or -t */ | ||||
|     if (outFileName) { | ||||
|         unsigned u; | ||||
|         ress.dstFile = FIO_openDstFile(suffix); | ||||
|         if (ress.dstFile == 0) EXM_THROW(71, "cannot open %s", suffix); | ||||
|         ress.dstFile = FIO_openDstFile(outFileName); | ||||
|         if (ress.dstFile == 0) EXM_THROW(71, "cannot open %s", outFileName); | ||||
|         for (u=0; u<nbFiles; u++) | ||||
|             missingFiles += FIO_decompressSrcFile(ress, suffix, srcNamesTable[u]); | ||||
|             missingFiles += FIO_decompressSrcFile(ress, outFileName, srcNamesTable[u]); | ||||
|         if (fclose(ress.dstFile)) | ||||
|             EXM_THROW(72, "Write error : cannot properly close stdout"); | ||||
|             EXM_THROW(72, "Write error : cannot properly close output file"); | ||||
|     } else { | ||||
|         size_t suffixSize; | ||||
|         size_t dfnSize = FNSPACE; | ||||
|   | ||||
| @@ -84,14 +84,14 @@ int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int dis | ||||
| /** FIO_compressMultipleFilenames() : | ||||
|     @return : nb of missing files */ | ||||
| int FIO_compressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles, | ||||
|                                   const char* suffix, | ||||
|                                   const char* outFileName, const char* suffix, | ||||
|                                   const char* dictFileName, int compressionLevel, | ||||
|                                   ZSTD_compressionParameters* comprParams); | ||||
|  | ||||
| /** FIO_decompressMultipleFilenames() : | ||||
|     @return : nb of missing or skipped files */ | ||||
| int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles, | ||||
|                                     const char* suffix, | ||||
|                                     const char* outFileName, | ||||
|                                     const char* dictFileName); | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -815,12 +815,6 @@ int main(int argCount, const char* argv[]) | ||||
|     if (outFileName && !strcmp(outFileName, stdoutmark) && IS_CONSOLE(stdout) && !strcmp(filenameTable[0], stdinmark) && !forceStdout && operation!=zom_decompress) | ||||
|         CLEAN_RETURN(badusage(programName)); | ||||
|  | ||||
|     /* user-selected output filename, only possible with a single file */ | ||||
|     if (outFileName && strcmp(outFileName,stdoutmark) && strcmp(outFileName,nulmark) && (filenameIdx>1)) { | ||||
|         DISPLAY("Too many files (%u) on the command line. \n", filenameIdx); | ||||
|         CLEAN_RETURN(filenameIdx); | ||||
|     } | ||||
|  | ||||
| #ifndef ZSTD_NOCOMPRESS | ||||
|     /* check compression level limits */ | ||||
|     {   int const maxCLevel = ultra ? ZSTD_maxCLevel() : ZSTDCLI_CLEVEL_MAX; | ||||
| @@ -854,7 +848,7 @@ int main(int argCount, const char* argv[]) | ||||
|         if ((filenameIdx==1) && outFileName) | ||||
|           operationResult = FIO_compressFilename(outFileName, filenameTable[0], dictFileName, cLevel, &compressionParams); | ||||
|         else | ||||
|           operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : suffix, dictFileName, cLevel, &compressionParams); | ||||
|           operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, outFileName, suffix, dictFileName, cLevel, &compressionParams); | ||||
| #else | ||||
|         (void)suffix; | ||||
|         DISPLAY("Compression not supported\n"); | ||||
| @@ -872,7 +866,7 @@ int main(int argCount, const char* argv[]) | ||||
|         if (filenameIdx==1 && outFileName) | ||||
|             operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName); | ||||
|         else | ||||
|             operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName ? outFileName : ZSTD_EXTENSION, dictFileName); | ||||
|             operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, outFileName, dictFileName); | ||||
| #else | ||||
|         DISPLAY("Decompression not supported\n"); | ||||
| #endif | ||||
|   | ||||
| @@ -173,6 +173,22 @@ rm tmp | ||||
| $ZSTD -f tmp && die "tmp not present : should have failed" | ||||
| test ! -f tmp.zst  # tmp.zst should not be created | ||||
|  | ||||
| $ECHO "test : compress multiple files" | ||||
| $ECHO hello > tmp1 | ||||
| $ECHO world > tmp2 | ||||
| $ZSTD tmp1 tmp2 -o "$INTOVOID" | ||||
| $ZSTD tmp1 tmp2 -c | $ZSTD -t | ||||
| $ZSTD tmp1 tmp2 -o tmp.zst | ||||
| test ! -f tmp1.zst | ||||
| test ! -f tmp2.zst | ||||
| $ZSTD tmp1 tmp2 | ||||
| $ZSTD -t tmp1.zst tmp2.zst | ||||
| $ZSTD -dc tmp1.zst tmp2.zst | ||||
| $ZSTD tmp1.zst tmp2.zst -o "$INTOVOID" | ||||
| $ZSTD -d tmp1.zst tmp2.zst -o tmp | ||||
| rm tmp* | ||||
|  | ||||
|  | ||||
|  | ||||
| $ECHO "\n===>  Advanced compression parameters " | ||||
| $ECHO "Hello world!" | $ZSTD --zstd=windowLog=21,      - -o tmp.zst && die "wrong parameters not detected!" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user