1 /* 2 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 * All rights reserved. 4 * 5 * This source code is licensed under both the BSD-style license (found in the 6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 * in the COPYING file in the root directory of this source tree). 8 * You may select, at your option, one of the above-listed licenses. 9 */ 10 11 12 #ifndef FILEIO_H_23981798732 13 #define FILEIO_H_23981798732 14 15 #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */ 16 #include "zstd.h" /* ZSTD_* */ 17 18 #if defined (__cplusplus) 19 extern "C" { 20 #endif 21 22 23 /* ************************************* 24 * Special i/o constants 25 **************************************/ 26 #define stdinmark "/*stdin*\\" 27 #define stdoutmark "/*stdout*\\" 28 #ifdef _WIN32 29 # define nulmark "NUL" 30 #else 31 # define nulmark "/dev/null" 32 #endif 33 34 /** 35 * We test whether the extension we found starts with 't', and if so, we append 36 * ".tar" to the end of the output name. 37 */ 38 #define LZMA_EXTENSION ".lzma" 39 #define XZ_EXTENSION ".xz" 40 #define TXZ_EXTENSION ".txz" 41 42 #define GZ_EXTENSION ".gz" 43 #define TGZ_EXTENSION ".tgz" 44 45 #define ZSTD_EXTENSION ".zst" 46 #define TZSTD_EXTENSION ".tzst" 47 48 #define LZ4_EXTENSION ".lz4" 49 #define TLZ4_EXTENSION ".tlz4" 50 51 52 /*-************************************* 53 * Types 54 ***************************************/ 55 typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t; 56 57 typedef struct FIO_prefs_s FIO_prefs_t; 58 59 FIO_prefs_t* FIO_createPreferences(void); 60 void FIO_freePreferences(FIO_prefs_t* const prefs); 61 62 typedef struct FIO_display_prefs_s FIO_display_prefs_t; 63 64 /*-************************************* 65 * Parameters 66 ***************************************/ 67 void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType); 68 void FIO_overwriteMode(FIO_prefs_t* const prefs); 69 void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt); 70 void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel); 71 void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel); 72 void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize); 73 void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag); 74 void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag); 75 void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog); 76 void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag); 77 void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog); 78 void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog); 79 void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch); 80 void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit); 81 void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers); 82 void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog); 83 void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag); 84 void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */ 85 void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable); 86 void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize); 87 void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize); 88 void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint); 89 void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode); 90 void FIO_setLiteralCompressionMode( 91 FIO_prefs_t* const prefs, 92 ZSTD_literalCompressionMode_e mode); 93 94 void FIO_setNoProgress(unsigned noProgress); 95 void FIO_setNotificationLevel(int level); 96 void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles); 97 98 /*-************************************* 99 * Single File functions 100 ***************************************/ 101 /** FIO_compressFilename() : 102 * @return : 0 == ok; 1 == pb with src file. */ 103 int FIO_compressFilename (FIO_prefs_t* const prefs, 104 const char* outfilename, const char* infilename, 105 const char* dictFileName, int compressionLevel, 106 ZSTD_compressionParameters comprParams); 107 108 /** FIO_decompressFilename() : 109 * @return : 0 == ok; 1 == pb with src file. */ 110 int FIO_decompressFilename (FIO_prefs_t* const prefs, 111 const char* outfilename, const char* infilename, const char* dictFileName); 112 113 int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel); 114 115 116 /*-************************************* 117 * Multiple File functions 118 ***************************************/ 119 /** FIO_compressMultipleFilenames() : 120 * @return : nb of missing files */ 121 int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs, 122 const char** inFileNamesTable, unsigned nbFiles, 123 const char* outDirName, 124 const char* outFileName, const char* suffix, 125 const char* dictFileName, int compressionLevel, 126 ZSTD_compressionParameters comprParams); 127 128 /** FIO_decompressMultipleFilenames() : 129 * @return : nb of missing or skipped files */ 130 int FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs, 131 const char** srcNamesTable, unsigned nbFiles, 132 const char* outDirName, 133 const char* outFileName, 134 const char* dictFileName); 135 136 /* FIO_checkFilenameCollisions() : 137 * Checks for and warns if there are any files that would have the same output path 138 */ 139 int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles); 140 141 142 143 /*-************************************* 144 * Advanced stuff (should actually be hosted elsewhere) 145 ***************************************/ 146 147 /* custom crash signal handler */ 148 void FIO_addAbortHandler(void); 149 150 151 152 #if defined (__cplusplus) 153 } 154 #endif 155 156 #endif /* FILEIO_H_23981798732 */ 157