zstd/programs/fileio.h

176 lines
6.8 KiB
C
Raw Normal View History

/*
* Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
2016-08-30 10:04:33 -07:00
* All rights reserved.
*
* This source code is licensed under both the BSD-style license (found in the
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
* in the COPYING file in the root directory of this source tree).
* You may select, at your option, one of the above-listed licenses.
2016-08-30 10:04:33 -07:00
*/
2015-01-31 01:52:59 -08:00
2016-09-15 08:02:06 -07:00
#ifndef FILEIO_H_23981798732
#define FILEIO_H_23981798732
2015-01-31 01:52:59 -08:00
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
#include "../lib/zstd.h" /* ZSTD_* */
2015-01-31 01:52:59 -08:00
#if defined (__cplusplus)
extern "C" {
#endif
2015-10-22 07:31:46 -07:00
/* *************************************
2015-01-31 01:52:59 -08:00
* Special i/o constants
**************************************/
2016-12-02 15:18:57 -08:00
#define stdinmark "/*stdin*\\"
2016-11-04 03:37:27 -07:00
#define stdoutmark "/*stdout*\\"
2015-01-31 01:52:59 -08:00
#ifdef _WIN32
# define nulmark "NUL"
2015-01-31 01:52:59 -08:00
#else
# define nulmark "/dev/null"
#endif
2019-10-24 17:18:57 -07:00
2019-10-25 10:58:58 -07:00
/**
* We test whether the extension we found starts with 't', and if so, we append
2019-10-24 17:18:57 -07:00
* ".tar" to the end of the output name.
*/
#define LZMA_EXTENSION ".lzma"
#define XZ_EXTENSION ".xz"
2019-10-24 17:18:57 -07:00
#define TXZ_EXTENSION ".txz"
#define GZ_EXTENSION ".gz"
2019-10-24 17:18:57 -07:00
#define TGZ_EXTENSION ".tgz"
#define ZSTD_EXTENSION ".zst"
2019-10-24 17:18:57 -07:00
#define TZSTD_EXTENSION ".tzst"
#define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */
2019-10-24 17:18:57 -07:00
#define LZ4_EXTENSION ".lz4"
2019-10-24 17:18:57 -07:00
#define TLZ4_EXTENSION ".tlz4"
2015-01-31 01:52:59 -08:00
2017-02-08 06:17:55 -08:00
/*-*************************************
* Types
***************************************/
typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t;
2017-02-08 06:17:55 -08:00
typedef struct FIO_prefs_s FIO_prefs_t;
FIO_prefs_t* FIO_createPreferences(void);
void FIO_freePreferences(FIO_prefs_t* const prefs);
/* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
typedef struct FIO_ctx_s FIO_ctx_t;
FIO_ctx_t* FIO_createContext(void);
void FIO_freeContext(FIO_ctx_t* const fCtx);
typedef struct FIO_display_prefs_s FIO_display_prefs_t;
2017-02-08 06:17:55 -08:00
2016-03-10 12:02:25 -08:00
/*-*************************************
2015-01-31 01:52:59 -08:00
* Parameters
2015-10-22 07:31:46 -07:00
***************************************/
/* FIO_prefs_t functions */
void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
void FIO_overwriteMode(FIO_prefs_t* const prefs);
void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt);
void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag);
void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
2019-08-15 23:57:55 -07:00
void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
2019-06-24 13:40:52 -07:00
void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
2019-08-19 08:52:08 -07:00
void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
void FIO_setLiteralCompressionMode(
FIO_prefs_t* const prefs,
ZSTD_literalCompressionMode_e mode);
2015-01-31 01:52:59 -08:00
void FIO_setNoProgress(unsigned noProgress);
void FIO_setNotificationLevel(int level);
void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
2020-03-09 12:12:52 -07:00
void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
/* FIO_ctx_t functions */
void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
2020-10-07 10:44:25 -07:00
void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
2015-01-31 01:52:59 -08:00
2016-03-10 12:02:25 -08:00
/*-*************************************
* Single File functions
2015-10-22 07:31:46 -07:00
***************************************/
2016-02-11 18:50:05 -08:00
/** FIO_compressFilename() :
* @return : 0 == ok; 1 == pb with src file. */
2020-09-07 10:13:05 -07:00
int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
const char* outfilename, const char* infilename,
const char* dictFileName, int compressionLevel,
ZSTD_compressionParameters comprParams);
2015-01-31 01:52:59 -08:00
2016-02-11 18:50:05 -08:00
/** FIO_decompressFilename() :
* @return : 0 == ok; 1 == pb with src file. */
2020-09-07 10:13:05 -07:00
int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
const char* outfilename, const char* infilename, const char* dictFileName);
2015-01-31 01:52:59 -08:00
int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
2015-01-31 01:52:59 -08:00
2016-03-10 12:02:25 -08:00
/*-*************************************
* Multiple File functions
***************************************/
2016-02-11 18:50:05 -08:00
/** FIO_compressMultipleFilenames() :
* @return : nb of missing files */
2020-09-07 10:13:05 -07:00
int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
FIO_prefs_t* const prefs,
const char** inFileNamesTable,
2020-06-19 19:35:51 -07:00
const char* outMirroredDirName,
const char* outDirName,
2017-12-12 18:32:50 -08:00
const char* outFileName, const char* suffix,
const char* dictFileName, int compressionLevel,
ZSTD_compressionParameters comprParams);
2016-02-11 18:50:05 -08:00
/** FIO_decompressMultipleFilenames() :
* @return : nb of missing or skipped files */
2020-09-07 10:13:05 -07:00
int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
FIO_prefs_t* const prefs,
const char** srcNamesTable,
2020-06-19 19:35:51 -07:00
const char* outMirroredDirName,
const char* outDirName,
2017-12-12 18:32:50 -08:00
const char* outFileName,
2015-12-17 11:30:14 -08:00
const char* dictFileName);
/* FIO_checkFilenameCollisions() :
* Checks for and warns if there are any files that would have the same output path
*/
int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
2015-01-31 01:52:59 -08:00
2015-01-31 01:52:59 -08:00
/*-*************************************
* Advanced stuff (should actually be hosted elsewhere)
***************************************/
/* custom crash signal handler */
void FIO_addAbortHandler(void);
2015-01-31 01:52:59 -08:00
#if defined (__cplusplus)
}
2015-10-22 07:31:46 -07:00
#endif
2016-09-15 08:02:06 -07:00
#endif /* FILEIO_H_23981798732 */