10c16b537SWarner Losh /* 2*37f1f268SConrad Meyer * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc. 30c16b537SWarner Losh * All rights reserved. 40c16b537SWarner Losh * 50c16b537SWarner Losh * This source code is licensed under both the BSD-style license (found in the 60c16b537SWarner Losh * LICENSE file in the root directory of this source tree) and the GPLv2 (found 70c16b537SWarner Losh * in the COPYING file in the root directory of this source tree). 80c16b537SWarner Losh * You may select, at your option, one of the above-listed licenses. 90c16b537SWarner Losh */ 100c16b537SWarner Losh 110c16b537SWarner Losh 120c16b537SWarner Losh #ifndef FILEIO_H_23981798732 130c16b537SWarner Losh #define FILEIO_H_23981798732 140c16b537SWarner Losh 150c16b537SWarner Losh #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */ 16*37f1f268SConrad Meyer #include "../lib/zstd.h" /* ZSTD_* */ 170c16b537SWarner Losh 180c16b537SWarner Losh #if defined (__cplusplus) 190c16b537SWarner Losh extern "C" { 200c16b537SWarner Losh #endif 210c16b537SWarner Losh 220c16b537SWarner Losh 230c16b537SWarner Losh /* ************************************* 240c16b537SWarner Losh * Special i/o constants 250c16b537SWarner Losh **************************************/ 260c16b537SWarner Losh #define stdinmark "/*stdin*\\" 270c16b537SWarner Losh #define stdoutmark "/*stdout*\\" 280c16b537SWarner Losh #ifdef _WIN32 299cbefe25SConrad Meyer # define nulmark "NUL" 300c16b537SWarner Losh #else 310c16b537SWarner Losh # define nulmark "/dev/null" 320c16b537SWarner Losh #endif 339cbefe25SConrad Meyer 349cbefe25SConrad Meyer /** 359cbefe25SConrad Meyer * We test whether the extension we found starts with 't', and if so, we append 369cbefe25SConrad Meyer * ".tar" to the end of the output name. 379cbefe25SConrad Meyer */ 380c16b537SWarner Losh #define LZMA_EXTENSION ".lzma" 390c16b537SWarner Losh #define XZ_EXTENSION ".xz" 409cbefe25SConrad Meyer #define TXZ_EXTENSION ".txz" 419cbefe25SConrad Meyer 420c16b537SWarner Losh #define GZ_EXTENSION ".gz" 439cbefe25SConrad Meyer #define TGZ_EXTENSION ".tgz" 449cbefe25SConrad Meyer 450c16b537SWarner Losh #define ZSTD_EXTENSION ".zst" 469cbefe25SConrad Meyer #define TZSTD_EXTENSION ".tzst" 479cbefe25SConrad Meyer 480c16b537SWarner Losh #define LZ4_EXTENSION ".lz4" 499cbefe25SConrad Meyer #define TLZ4_EXTENSION ".tlz4" 500c16b537SWarner Losh 510c16b537SWarner Losh 520c16b537SWarner Losh /*-************************************* 530c16b537SWarner Losh * Types 540c16b537SWarner Losh ***************************************/ 550c16b537SWarner Losh typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t; 560c16b537SWarner Losh 572b9c00cbSConrad Meyer typedef struct FIO_prefs_s FIO_prefs_t; 582b9c00cbSConrad Meyer 592b9c00cbSConrad Meyer FIO_prefs_t* FIO_createPreferences(void); 602b9c00cbSConrad Meyer void FIO_freePreferences(FIO_prefs_t* const prefs); 612b9c00cbSConrad Meyer 622b9c00cbSConrad Meyer typedef struct FIO_display_prefs_s FIO_display_prefs_t; 630c16b537SWarner Losh 640c16b537SWarner Losh /*-************************************* 650c16b537SWarner Losh * Parameters 660c16b537SWarner Losh ***************************************/ 672b9c00cbSConrad Meyer void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType); 682b9c00cbSConrad Meyer void FIO_overwriteMode(FIO_prefs_t* const prefs); 692b9c00cbSConrad Meyer void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt); 702b9c00cbSConrad Meyer void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel); 712b9c00cbSConrad Meyer void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel); 722b9c00cbSConrad Meyer void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize); 732b9c00cbSConrad Meyer void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag); 742b9c00cbSConrad Meyer void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag); 752b9c00cbSConrad Meyer void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog); 762b9c00cbSConrad Meyer void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag); 772b9c00cbSConrad Meyer void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog); 782b9c00cbSConrad Meyer void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog); 792b9c00cbSConrad Meyer void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch); 802b9c00cbSConrad Meyer void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit); 812b9c00cbSConrad Meyer void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers); 822b9c00cbSConrad Meyer void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog); 832b9c00cbSConrad Meyer void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag); 842b9c00cbSConrad Meyer void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */ 852b9c00cbSConrad Meyer void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable); 869cbefe25SConrad Meyer void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize); 874d3f1eafSConrad Meyer void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize); 889cbefe25SConrad Meyer void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint); 899cbefe25SConrad Meyer void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode); 902b9c00cbSConrad Meyer void FIO_setLiteralCompressionMode( 912b9c00cbSConrad Meyer FIO_prefs_t* const prefs, 922b9c00cbSConrad Meyer ZSTD_literalCompressionMode_e mode); 930c16b537SWarner Losh 942b9c00cbSConrad Meyer void FIO_setNoProgress(unsigned noProgress); 952b9c00cbSConrad Meyer void FIO_setNotificationLevel(int level); 969cbefe25SConrad Meyer void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles); 97*37f1f268SConrad Meyer void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value); 98*37f1f268SConrad Meyer void FIO_setContentSize(FIO_prefs_t* const prefs, int value); 990c16b537SWarner Losh 1000c16b537SWarner Losh /*-************************************* 1010c16b537SWarner Losh * Single File functions 1020c16b537SWarner Losh ***************************************/ 1030c16b537SWarner Losh /** FIO_compressFilename() : 1049cbefe25SConrad Meyer * @return : 0 == ok; 1 == pb with src file. */ 1052b9c00cbSConrad Meyer int FIO_compressFilename (FIO_prefs_t* const prefs, 1069cbefe25SConrad Meyer const char* outfilename, const char* infilename, 1079cbefe25SConrad Meyer const char* dictFileName, int compressionLevel, 1089cbefe25SConrad Meyer ZSTD_compressionParameters comprParams); 1090c16b537SWarner Losh 1100c16b537SWarner Losh /** FIO_decompressFilename() : 1119cbefe25SConrad Meyer * @return : 0 == ok; 1 == pb with src file. */ 1122b9c00cbSConrad Meyer int FIO_decompressFilename (FIO_prefs_t* const prefs, 1132b9c00cbSConrad Meyer const char* outfilename, const char* infilename, const char* dictFileName); 1140c16b537SWarner Losh 1150c16b537SWarner Losh int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel); 1160c16b537SWarner Losh 1170f743729SConrad Meyer 1180c16b537SWarner Losh /*-************************************* 1190c16b537SWarner Losh * Multiple File functions 1200c16b537SWarner Losh ***************************************/ 1210c16b537SWarner Losh /** FIO_compressMultipleFilenames() : 1229cbefe25SConrad Meyer * @return : nb of missing files */ 1232b9c00cbSConrad Meyer int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs, 1249cbefe25SConrad Meyer const char** inFileNamesTable, unsigned nbFiles, 1259cbefe25SConrad Meyer const char* outDirName, 126052d3c12SConrad Meyer const char* outFileName, const char* suffix, 1270c16b537SWarner Losh const char* dictFileName, int compressionLevel, 1280f743729SConrad Meyer ZSTD_compressionParameters comprParams); 1290c16b537SWarner Losh 1300c16b537SWarner Losh /** FIO_decompressMultipleFilenames() : 1319cbefe25SConrad Meyer * @return : nb of missing or skipped files */ 1322b9c00cbSConrad Meyer int FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs, 1332b9c00cbSConrad Meyer const char** srcNamesTable, unsigned nbFiles, 1349cbefe25SConrad Meyer const char* outDirName, 135052d3c12SConrad Meyer const char* outFileName, 1360c16b537SWarner Losh const char* dictFileName); 1370c16b537SWarner Losh 1389cbefe25SConrad Meyer /* FIO_checkFilenameCollisions() : 1399cbefe25SConrad Meyer * Checks for and warns if there are any files that would have the same output path 1409cbefe25SConrad Meyer */ 1419cbefe25SConrad Meyer int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles); 1429cbefe25SConrad Meyer 1439cbefe25SConrad Meyer 1440c16b537SWarner Losh 1450f743729SConrad Meyer /*-************************************* 1460f743729SConrad Meyer * Advanced stuff (should actually be hosted elsewhere) 1470f743729SConrad Meyer ***************************************/ 1480f743729SConrad Meyer 1490f743729SConrad Meyer /* custom crash signal handler */ 1500f743729SConrad Meyer void FIO_addAbortHandler(void); 1510f743729SConrad Meyer 1520f743729SConrad Meyer 1530f743729SConrad Meyer 1540c16b537SWarner Losh #if defined (__cplusplus) 1550c16b537SWarner Losh } 1560c16b537SWarner Losh #endif 1570c16b537SWarner Losh 1580c16b537SWarner Losh #endif /* FILEIO_H_23981798732 */ 159