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)
19extern "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***************************************/
56typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t;
57
58typedef struct FIO_prefs_s FIO_prefs_t;
59
60FIO_prefs_t* FIO_createPreferences(void);
61void 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 */
64typedef struct FIO_ctx_s FIO_ctx_t;
65
66FIO_ctx_t* FIO_createContext(void);
67void FIO_freeContext(FIO_ctx_t* const fCtx);
68
69typedef struct FIO_display_prefs_s FIO_display_prefs_t;
70
71/*-*************************************
72*  Parameters
73***************************************/
74/* FIO_prefs_t functions */
75void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
76void FIO_overwriteMode(FIO_prefs_t* const prefs);
77void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt);
78void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
79void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
80void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
81void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
82void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
83void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
84void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
85void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
86void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
87void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
88void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
89void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
90void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
91void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag);
92void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse);  /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
93void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
94void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
95void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
96void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
97void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
98void FIO_setLiteralCompressionMode(
99        FIO_prefs_t* const prefs,
100        ZSTD_literalCompressionMode_e mode);
101
102void FIO_setNoProgress(unsigned noProgress);
103void FIO_setNotificationLevel(int level);
104void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
105void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
106void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
107
108/* FIO_ctx_t functions */
109void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
110void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
111void 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. */
118int 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. */
125int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
126                            const char* outfilename, const char* infilename, const char* dictFileName);
127
128int 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 */
136int 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 */
147int 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 */
158int 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 */
167void FIO_addAbortHandler(void);
168
169
170
171#if defined (__cplusplus)
172}
173#endif
174
175#endif  /* FILEIO_H_23981798732 */
176