Path: blob/main/sys/contrib/zstd/programs/fileio.h
48254 views
/*1* Copyright (c) Yann Collet, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/91011#ifndef FILEIO_H_2398179873212#define FILEIO_H_239817987321314#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */15#include "../lib/zstd.h" /* ZSTD_* */1617#if defined (__cplusplus)18extern "C" {19#endif202122/* *************************************23* Special i/o constants24**************************************/25#define stdinmark "/*stdin*\\"26#define stdoutmark "/*stdout*\\"27#ifdef _WIN3228# define nulmark "NUL"29#else30# define nulmark "/dev/null"31#endif3233/**34* We test whether the extension we found starts with 't', and if so, we append35* ".tar" to the end of the output name.36*/37#define LZMA_EXTENSION ".lzma"38#define XZ_EXTENSION ".xz"39#define TXZ_EXTENSION ".txz"4041#define GZ_EXTENSION ".gz"42#define TGZ_EXTENSION ".tgz"4344#define ZSTD_EXTENSION ".zst"45#define TZSTD_EXTENSION ".tzst"46#define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */4748#define LZ4_EXTENSION ".lz4"49#define TLZ4_EXTENSION ".tlz4"505152/*-*************************************53* Types54***************************************/55typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t;5657typedef struct FIO_prefs_s FIO_prefs_t;5859FIO_prefs_t* FIO_createPreferences(void);60void FIO_freePreferences(FIO_prefs_t* const prefs);6162/* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */63typedef struct FIO_ctx_s FIO_ctx_t;6465FIO_ctx_t* FIO_createContext(void);66void FIO_freeContext(FIO_ctx_t* const fCtx);6768typedef struct FIO_display_prefs_s FIO_display_prefs_t;6970typedef enum { FIO_ps_auto, FIO_ps_never, FIO_ps_always } FIO_progressSetting_e;7172/*-*************************************73* Parameters74***************************************/75/* FIO_prefs_t functions */76void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);77void FIO_overwriteMode(FIO_prefs_t* const prefs);78void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt);79void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);80void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);81void FIO_setUseRowMatchFinder(FIO_prefs_t* const prefs, int useRowMatchFinder);82void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);83void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);84void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);85void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);86void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);87void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);88void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);89void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);90void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);91void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);92void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);93void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag);94void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */95void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);96void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);97void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);98void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);99void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);100void FIO_setLiteralCompressionMode(101FIO_prefs_t* const prefs,102ZSTD_paramSwitch_e mode);103104void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);105void FIO_setNotificationLevel(int level);106void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);107void FIO_setAllowBlockDevices(FIO_prefs_t* const prefs, int allowBlockDevices);108void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);109void FIO_setContentSize(FIO_prefs_t* const prefs, int value);110void FIO_displayCompressionParameters(const FIO_prefs_t* prefs);111112/* FIO_ctx_t functions */113void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);114void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);115void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);116117/*-*************************************118* Single File functions119***************************************/120/** FIO_compressFilename() :121* @return : 0 == ok; 1 == pb with src file. */122int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,123const char* outfilename, const char* infilename,124const char* dictFileName, int compressionLevel,125ZSTD_compressionParameters comprParams);126127/** FIO_decompressFilename() :128* @return : 0 == ok; 1 == pb with src file. */129int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,130const char* outfilename, const char* infilename, const char* dictFileName);131132int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);133134135/*-*************************************136* Multiple File functions137***************************************/138/** FIO_compressMultipleFilenames() :139* @return : nb of missing files */140int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,141FIO_prefs_t* const prefs,142const char** inFileNamesTable,143const char* outMirroredDirName,144const char* outDirName,145const char* outFileName, const char* suffix,146const char* dictFileName, int compressionLevel,147ZSTD_compressionParameters comprParams);148149/** FIO_decompressMultipleFilenames() :150* @return : nb of missing or skipped files */151int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,152FIO_prefs_t* const prefs,153const char** srcNamesTable,154const char* outMirroredDirName,155const char* outDirName,156const char* outFileName,157const char* dictFileName);158159/* FIO_checkFilenameCollisions() :160* Checks for and warns if there are any files that would have the same output path161*/162int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);163164165166/*-*************************************167* Advanced stuff (should actually be hosted elsewhere)168***************************************/169170/* custom crash signal handler */171void FIO_addAbortHandler(void);172173174175#if defined (__cplusplus)176}177#endif178179#endif /* FILEIO_H_23981798732 */180181182