| 1 |
/* |
| 2 |
* Copyright (c) Meta Platforms, Inc. and affiliates. |
| 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 |
|
| 11 |
#define ZSTD_STATIC_LINKING_ONLY |
| 12 |
#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* No deprecation warnings, pzstd itself is deprecated |
| 13 |
* and uses deprecated functions |
| 14 |
*/ |
| 15 |
#include "zstd.h" |
| 16 |
#undef ZSTD_STATIC_LINKING_ONLY |
| 17 |
|
| 18 |
#include <cstdint> |
| 19 |
#include <string> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
namespace pzstd { |
| 23 |
|
| 24 |
struct Options { |
| 25 |
enum class WriteMode { Regular, Auto, Sparse }; |
| 26 |
|
| 27 |
unsigned numThreads; |
| 28 |
unsigned maxWindowLog; |
| 29 |
unsigned compressionLevel; |
| 30 |
bool decompress; |
| 31 |
std::vector<std::string> inputFiles; |
| 32 |
std::string outputFile; |
| 33 |
bool overwrite; |
| 34 |
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 |
}; |
| 44 |
|
| 45 |
Options(); |
| 46 |
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) {} |
| 55 |
|
| 56 |
Status parse(int argc, const char **argv); |
| 57 |
|
| 58 |
ZSTD_parameters determineParameters() const { |
| 59 |
ZSTD_parameters params = ZSTD_getParams(compressionLevel, 0, 0); |
| 60 |
params.fParams.contentSizeFlag = 0; |
| 61 |
params.fParams.checksumFlag = checksum; |
| 62 |
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 |
} |
| 68 |
|
| 69 |
std::string getOutputFile(const std::string &inputFile) const; |
| 70 |
}; |
| 71 |
} |