xref: /freebsd/sys/contrib/zstd/programs/fileio.h (revision 65422c964ace1c1d0b7858e7f6f655ddeedb4db4)
1 /*
2  * Copyright (c) 2016-2020, 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 "../lib/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 void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
98 void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
99 
100 /*-*************************************
101 *  Single File functions
102 ***************************************/
103 /** FIO_compressFilename() :
104  * @return : 0 == ok;  1 == pb with src file. */
105 int FIO_compressFilename (FIO_prefs_t* const prefs,
106                           const char* outfilename, const char* infilename,
107                           const char* dictFileName, int compressionLevel,
108                           ZSTD_compressionParameters comprParams);
109 
110 /** FIO_decompressFilename() :
111  * @return : 0 == ok;  1 == pb with src file. */
112 int FIO_decompressFilename (FIO_prefs_t* const prefs,
113                             const char* outfilename, const char* infilename, const char* dictFileName);
114 
115 int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
116 
117 
118 /*-*************************************
119 *  Multiple File functions
120 ***************************************/
121 /** FIO_compressMultipleFilenames() :
122  * @return : nb of missing files */
123 int FIO_compressMultipleFilenames(FIO_prefs_t* const prefs,
124                                   const char** inFileNamesTable, unsigned nbFiles,
125                                   const char* outDirName,
126                                   const char* outFileName, const char* suffix,
127                                   const char* dictFileName, int compressionLevel,
128                                   ZSTD_compressionParameters comprParams);
129 
130 /** FIO_decompressMultipleFilenames() :
131  * @return : nb of missing or skipped files */
132 int FIO_decompressMultipleFilenames(FIO_prefs_t* const prefs,
133                                     const char** srcNamesTable, unsigned nbFiles,
134                                     const char* outDirName,
135                                     const char* outFileName,
136                                     const char* dictFileName);
137 
138 /* FIO_checkFilenameCollisions() :
139  * Checks for and warns if there are any files that would have the same output path
140  */
141 int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
142 
143 
144 
145 /*-*************************************
146 *  Advanced stuff (should actually be hosted elsewhere)
147 ***************************************/
148 
149 /* custom crash signal handler */
150 void FIO_addAbortHandler(void);
151 
152 
153 
154 #if defined (__cplusplus)
155 }
156 #endif
157 
158 #endif  /* FILEIO_H_23981798732 */
159