xref: /dragonfly/contrib/zstd/programs/fileio.h (revision c8860c9a)
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 #define ZSTD_ALT_EXTENSION  ".zstd" /* allow decompression of .zstd files */
48 
49 #define LZ4_EXTENSION   ".lz4"
50 #define TLZ4_EXTENSION  ".tlz4"
51 
52 
53 /*-*************************************
54 *  Types
55 ***************************************/
56 typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t;
57 
58 typedef struct FIO_prefs_s FIO_prefs_t;
59 
60 FIO_prefs_t* FIO_createPreferences(void);
61 void FIO_freePreferences(FIO_prefs_t* const prefs);
62 
63 /* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
64 typedef struct FIO_ctx_s FIO_ctx_t;
65 
66 FIO_ctx_t* FIO_createContext(void);
67 void FIO_freeContext(FIO_ctx_t* const fCtx);
68 
69 typedef struct FIO_display_prefs_s FIO_display_prefs_t;
70 
71 /*-*************************************
72 *  Parameters
73 ***************************************/
74 /* FIO_prefs_t functions */
75 void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
76 void FIO_overwriteMode(FIO_prefs_t* const prefs);
77 void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt);
78 void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
79 void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
80 void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
81 void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
82 void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
83 void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
84 void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
85 void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
86 void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
87 void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
88 void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
89 void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
90 void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
91 void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag);
92 void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse);  /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
93 void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
94 void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
95 void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
96 void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
97 void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
98 void FIO_setLiteralCompressionMode(
99         FIO_prefs_t* const prefs,
100         ZSTD_literalCompressionMode_e mode);
101 
102 void FIO_setNoProgress(unsigned noProgress);
103 void FIO_setNotificationLevel(int level);
104 void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
105 void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
106 void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
107 
108 /* FIO_ctx_t functions */
109 void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
110 void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
111 void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
112 
113 /*-*************************************
114 *  Single File functions
115 ***************************************/
116 /** FIO_compressFilename() :
117  * @return : 0 == ok;  1 == pb with src file. */
118 int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
119                           const char* outfilename, const char* infilename,
120                           const char* dictFileName, int compressionLevel,
121                           ZSTD_compressionParameters comprParams);
122 
123 /** FIO_decompressFilename() :
124  * @return : 0 == ok;  1 == pb with src file. */
125 int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
126                             const char* outfilename, const char* infilename, const char* dictFileName);
127 
128 int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
129 
130 
131 /*-*************************************
132 *  Multiple File functions
133 ***************************************/
134 /** FIO_compressMultipleFilenames() :
135  * @return : nb of missing files */
136 int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
137                                   FIO_prefs_t* const prefs,
138                                   const char** inFileNamesTable,
139                                   const char* outMirroredDirName,
140                                   const char* outDirName,
141                                   const char* outFileName, const char* suffix,
142                                   const char* dictFileName, int compressionLevel,
143                                   ZSTD_compressionParameters comprParams);
144 
145 /** FIO_decompressMultipleFilenames() :
146  * @return : nb of missing or skipped files */
147 int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
148                                     FIO_prefs_t* const prefs,
149                                     const char** srcNamesTable,
150                                     const char* outMirroredDirName,
151                                     const char* outDirName,
152                                     const char* outFileName,
153                                     const char* dictFileName);
154 
155 /* FIO_checkFilenameCollisions() :
156  * Checks for and warns if there are any files that would have the same output path
157  */
158 int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
159 
160 
161 
162 /*-*************************************
163 *  Advanced stuff (should actually be hosted elsewhere)
164 ***************************************/
165 
166 /* custom crash signal handler */
167 void FIO_addAbortHandler(void);
168 
169 
170 
171 #if defined (__cplusplus)
172 }
173 #endif
174 
175 #endif  /* FILEIO_H_23981798732 */
176