fileio.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (c) 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. #ifndef FILEIO_H_23981798732
  11. #define FILEIO_H_23981798732
  12. #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
  13. #include "../lib/zstd.h" /* ZSTD_* */
  14. #if defined (__cplusplus)
  15. extern "C" {
  16. #endif
  17. /* *************************************
  18. * Special i/o constants
  19. **************************************/
  20. #define stdinmark "/*stdin*\\"
  21. #define stdoutmark "/*stdout*\\"
  22. #ifdef _WIN32
  23. # define nulmark "NUL"
  24. #else
  25. # define nulmark "/dev/null"
  26. #endif
  27. /**
  28. * We test whether the extension we found starts with 't', and if so, we append
  29. * ".tar" to the end of the output name.
  30. */
  31. #define LZMA_EXTENSION ".lzma"
  32. #define XZ_EXTENSION ".xz"
  33. #define TXZ_EXTENSION ".txz"
  34. #define GZ_EXTENSION ".gz"
  35. #define TGZ_EXTENSION ".tgz"
  36. #define ZSTD_EXTENSION ".zst"
  37. #define TZSTD_EXTENSION ".tzst"
  38. #define ZSTD_ALT_EXTENSION ".zstd" /* allow decompression of .zstd files */
  39. #define LZ4_EXTENSION ".lz4"
  40. #define TLZ4_EXTENSION ".tlz4"
  41. /*-*************************************
  42. * Types
  43. ***************************************/
  44. typedef enum { FIO_zstdCompression, FIO_gzipCompression, FIO_xzCompression, FIO_lzmaCompression, FIO_lz4Compression } FIO_compressionType_t;
  45. typedef struct FIO_prefs_s FIO_prefs_t;
  46. FIO_prefs_t* FIO_createPreferences(void);
  47. void FIO_freePreferences(FIO_prefs_t* const prefs);
  48. /* Mutable struct containing relevant context and state regarding (de)compression with respect to file I/O */
  49. typedef struct FIO_ctx_s FIO_ctx_t;
  50. FIO_ctx_t* FIO_createContext(void);
  51. void FIO_freeContext(FIO_ctx_t* const fCtx);
  52. typedef struct FIO_display_prefs_s FIO_display_prefs_t;
  53. typedef enum { FIO_ps_auto, FIO_ps_never, FIO_ps_always } FIO_progressSetting_e;
  54. /*-*************************************
  55. * Parameters
  56. ***************************************/
  57. /* FIO_prefs_t functions */
  58. void FIO_setCompressionType(FIO_prefs_t* const prefs, FIO_compressionType_t compressionType);
  59. void FIO_overwriteMode(FIO_prefs_t* const prefs);
  60. void FIO_setAdaptiveMode(FIO_prefs_t* const prefs, unsigned adapt);
  61. void FIO_setAdaptMin(FIO_prefs_t* const prefs, int minCLevel);
  62. void FIO_setAdaptMax(FIO_prefs_t* const prefs, int maxCLevel);
  63. void FIO_setUseRowMatchFinder(FIO_prefs_t* const prefs, int useRowMatchFinder);
  64. void FIO_setBlockSize(FIO_prefs_t* const prefs, int blockSize);
  65. void FIO_setChecksumFlag(FIO_prefs_t* const prefs, int checksumFlag);
  66. void FIO_setDictIDFlag(FIO_prefs_t* const prefs, int dictIDFlag);
  67. void FIO_setLdmBucketSizeLog(FIO_prefs_t* const prefs, int ldmBucketSizeLog);
  68. void FIO_setLdmFlag(FIO_prefs_t* const prefs, unsigned ldmFlag);
  69. void FIO_setLdmHashRateLog(FIO_prefs_t* const prefs, int ldmHashRateLog);
  70. void FIO_setLdmHashLog(FIO_prefs_t* const prefs, int ldmHashLog);
  71. void FIO_setLdmMinMatch(FIO_prefs_t* const prefs, int ldmMinMatch);
  72. void FIO_setMemLimit(FIO_prefs_t* const prefs, unsigned memLimit);
  73. void FIO_setNbWorkers(FIO_prefs_t* const prefs, int nbWorkers);
  74. void FIO_setOverlapLog(FIO_prefs_t* const prefs, int overlapLog);
  75. void FIO_setRemoveSrcFile(FIO_prefs_t* const prefs, unsigned flag);
  76. void FIO_setSparseWrite(FIO_prefs_t* const prefs, unsigned sparse); /**< 0: no sparse; 1: disable on stdout; 2: always enabled */
  77. void FIO_setRsyncable(FIO_prefs_t* const prefs, int rsyncable);
  78. void FIO_setStreamSrcSize(FIO_prefs_t* const prefs, size_t streamSrcSize);
  79. void FIO_setTargetCBlockSize(FIO_prefs_t* const prefs, size_t targetCBlockSize);
  80. void FIO_setSrcSizeHint(FIO_prefs_t* const prefs, size_t srcSizeHint);
  81. void FIO_setTestMode(FIO_prefs_t* const prefs, int testMode);
  82. void FIO_setLiteralCompressionMode(
  83. FIO_prefs_t* const prefs,
  84. ZSTD_paramSwitch_e mode);
  85. void FIO_setProgressSetting(FIO_progressSetting_e progressSetting);
  86. void FIO_setNotificationLevel(int level);
  87. void FIO_setExcludeCompressedFile(FIO_prefs_t* const prefs, int excludeCompressedFiles);
  88. void FIO_setAllowBlockDevices(FIO_prefs_t* const prefs, int allowBlockDevices);
  89. void FIO_setPatchFromMode(FIO_prefs_t* const prefs, int value);
  90. void FIO_setContentSize(FIO_prefs_t* const prefs, int value);
  91. void FIO_displayCompressionParameters(const FIO_prefs_t* prefs);
  92. /* FIO_ctx_t functions */
  93. void FIO_setNbFilesTotal(FIO_ctx_t* const fCtx, int value);
  94. void FIO_setHasStdoutOutput(FIO_ctx_t* const fCtx, int value);
  95. void FIO_determineHasStdinInput(FIO_ctx_t* const fCtx, const FileNamesTable* const filenames);
  96. /*-*************************************
  97. * Single File functions
  98. ***************************************/
  99. /** FIO_compressFilename() :
  100. * @return : 0 == ok; 1 == pb with src file. */
  101. int FIO_compressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
  102. const char* outfilename, const char* infilename,
  103. const char* dictFileName, int compressionLevel,
  104. ZSTD_compressionParameters comprParams);
  105. /** FIO_decompressFilename() :
  106. * @return : 0 == ok; 1 == pb with src file. */
  107. int FIO_decompressFilename (FIO_ctx_t* const fCtx, FIO_prefs_t* const prefs,
  108. const char* outfilename, const char* infilename, const char* dictFileName);
  109. int FIO_listMultipleFiles(unsigned numFiles, const char** filenameTable, int displayLevel);
  110. /*-*************************************
  111. * Multiple File functions
  112. ***************************************/
  113. /** FIO_compressMultipleFilenames() :
  114. * @return : nb of missing files */
  115. int FIO_compressMultipleFilenames(FIO_ctx_t* const fCtx,
  116. FIO_prefs_t* const prefs,
  117. const char** inFileNamesTable,
  118. const char* outMirroredDirName,
  119. const char* outDirName,
  120. const char* outFileName, const char* suffix,
  121. const char* dictFileName, int compressionLevel,
  122. ZSTD_compressionParameters comprParams);
  123. /** FIO_decompressMultipleFilenames() :
  124. * @return : nb of missing or skipped files */
  125. int FIO_decompressMultipleFilenames(FIO_ctx_t* const fCtx,
  126. FIO_prefs_t* const prefs,
  127. const char** srcNamesTable,
  128. const char* outMirroredDirName,
  129. const char* outDirName,
  130. const char* outFileName,
  131. const char* dictFileName);
  132. /* FIO_checkFilenameCollisions() :
  133. * Checks for and warns if there are any files that would have the same output path
  134. */
  135. int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles);
  136. /*-*************************************
  137. * Advanced stuff (should actually be hosted elsewhere)
  138. ***************************************/
  139. /* custom crash signal handler */
  140. void FIO_addAbortHandler(void);
  141. #if defined (__cplusplus)
  142. }
  143. #endif
  144. #endif /* FILEIO_H_23981798732 */