blob: 92c18a350cf61c02a00519df904021f48e76293d [file] [log] [blame]
Yann Collete9dc2042017-08-31 11:24:54 -07001/*
Elliott Hughes44aba642023-09-12 20:18:59 +00002 * Copyright (c) Meta Platforms, Inc. and affiliates.
Nick Terrellc9325202016-09-01 15:22:19 -07003 * All rights reserved.
4 *
Yann Collete9dc2042017-08-31 11:24:54 -07005 * 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).
Nick Terrellc9325202016-09-01 15:22:19 -07008 */
9#pragma once
10
11#define ZSTD_STATIC_LINKING_ONLY
sen40def702021-05-13 14:41:21 -040012#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* No deprecation warnings, pzstd itself is deprecated
13 * and uses deprecated functions
14 */
Nick Terrellc9325202016-09-01 15:22:19 -070015#include "zstd.h"
16#undef ZSTD_STATIC_LINKING_ONLY
17
18#include <cstdint>
19#include <string>
Nick Terrell254c5b12016-09-21 14:29:47 -070020#include <vector>
Nick Terrellc9325202016-09-01 15:22:19 -070021
22namespace pzstd {
23
24struct Options {
Nick Terrell254c5b12016-09-21 14:29:47 -070025 enum class WriteMode { Regular, Auto, Sparse };
26
Nick Terrellc9325202016-09-01 15:22:19 -070027 unsigned numThreads;
28 unsigned maxWindowLog;
29 unsigned compressionLevel;
30 bool decompress;
Nick Terrell254c5b12016-09-21 14:29:47 -070031 std::vector<std::string> inputFiles;
Nick Terrellc9325202016-09-01 15:22:19 -070032 std::string outputFile;
33 bool overwrite;
Nick Terrell254c5b12016-09-21 14:29:47 -070034 bool keepSource;
35 WriteMode writeMode;
36 bool checksum;
37 int verbosity;
38
39 enum class Status {
40 Success, // Successfully parsed options
41 Failure, // Failure to parse options
42 Message // Options specified to print a message (e.g. "-h")
43 };
Nick Terrellc9325202016-09-01 15:22:19 -070044
45 Options();
Nick Terrell254c5b12016-09-21 14:29:47 -070046 Options(unsigned numThreads, unsigned maxWindowLog, unsigned compressionLevel,
47 bool decompress, std::vector<std::string> inputFiles,
48 std::string outputFile, bool overwrite, bool keepSource,
49 WriteMode writeMode, bool checksum, int verbosity)
50 : numThreads(numThreads), maxWindowLog(maxWindowLog),
51 compressionLevel(compressionLevel), decompress(decompress),
52 inputFiles(std::move(inputFiles)), outputFile(std::move(outputFile)),
53 overwrite(overwrite), keepSource(keepSource), writeMode(writeMode),
54 checksum(checksum), verbosity(verbosity) {}
Nick Terrellc9325202016-09-01 15:22:19 -070055
Nick Terrell254c5b12016-09-21 14:29:47 -070056 Status parse(int argc, const char **argv);
Nick Terrellc9325202016-09-01 15:22:19 -070057
58 ZSTD_parameters determineParameters() const {
59 ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, 0);
Sean Purcell0f5c95a2017-02-07 16:33:48 -080060 params.fParams.contentSizeFlag = 0;
Nick Terrell254c5b12016-09-21 14:29:47 -070061 params.fParams.checksumFlag = checksum;
Nick Terrellc9325202016-09-01 15:22:19 -070062 if (maxWindowLog != 0 && params.cParams.windowLog > maxWindowLog) {
63 params.cParams.windowLog = maxWindowLog;
64 params.cParams = ZSTD_adjustCParams(params.cParams, 0, 0);
65 }
66 return params;
67 }
Nick Terrell254c5b12016-09-21 14:29:47 -070068
69 std::string getOutputFile(const std::string &inputFile) const;
Nick Terrellc9325202016-09-01 15:22:19 -070070};
71}