Options.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2016-present, 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. */
  9. #pragma once
  10. #define ZSTD_STATIC_LINKING_ONLY
  11. #define ZSTD_DISABLE_DEPRECATE_WARNINGS /* No deprecation warnings, pzstd itself is deprecated
  12. * and uses deprecated functions
  13. */
  14. #include "zstd.h"
  15. #undef ZSTD_STATIC_LINKING_ONLY
  16. #include <cstdint>
  17. #include <string>
  18. #include <vector>
  19. namespace pzstd {
  20. struct Options {
  21. enum class WriteMode { Regular, Auto, Sparse };
  22. unsigned numThreads;
  23. unsigned maxWindowLog;
  24. unsigned compressionLevel;
  25. bool decompress;
  26. std::vector<std::string> inputFiles;
  27. std::string outputFile;
  28. bool overwrite;
  29. bool keepSource;
  30. WriteMode writeMode;
  31. bool checksum;
  32. int verbosity;
  33. enum class Status {
  34. Success, // Successfully parsed options
  35. Failure, // Failure to parse options
  36. Message // Options specified to print a message (e.g. "-h")
  37. };
  38. Options();
  39. Options(unsigned numThreads, unsigned maxWindowLog, unsigned compressionLevel,
  40. bool decompress, std::vector<std::string> inputFiles,
  41. std::string outputFile, bool overwrite, bool keepSource,
  42. WriteMode writeMode, bool checksum, int verbosity)
  43. : numThreads(numThreads), maxWindowLog(maxWindowLog),
  44. compressionLevel(compressionLevel), decompress(decompress),
  45. inputFiles(std::move(inputFiles)), outputFile(std::move(outputFile)),
  46. overwrite(overwrite), keepSource(keepSource), writeMode(writeMode),
  47. checksum(checksum), verbosity(verbosity) {}
  48. Status parse(int argc, const char **argv);
  49. ZSTD_parameters determineParameters() const {
  50. ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, 0);
  51. params.fParams.contentSizeFlag = 0;
  52. params.fParams.checksumFlag = checksum;
  53. if (maxWindowLog != 0 && params.cParams.windowLog > maxWindowLog) {
  54. params.cParams.windowLog = maxWindowLog;
  55. params.cParams = ZSTD_adjustCParams(params.cParams, 0, 0);
  56. }
  57. return params;
  58. }
  59. std::string getOutputFile(const std::string &inputFile) const;
  60. };
  61. }