1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

When reading from stdin, write to stdout by default

This commit is contained in:
Nick Terrell
2016-09-02 12:35:36 -07:00
parent 1e2f6a1f5d
commit ac14348a28

View File

@ -146,23 +146,21 @@ bool Options::parse(int argc, const char** argv) {
// Determine output file if not specified
if (outputFile.empty()) {
if (inputFile == "-") {
std::fprintf(
stderr,
"Invalid arguments: Reading from stdin, but -o not provided.\n");
return false;
}
// Attempt to add/remove zstd extension from the input file
if (decompress) {
int stemSize = inputFile.size() - zstdExtension.size();
if (stemSize > 0 && inputFile.substr(stemSize) == zstdExtension) {
outputFile = inputFile.substr(0, stemSize);
} else {
std::fprintf(
stderr, "Invalid argument: Unable to determine output file.\n");
return false;
}
outputFile = "-";
} else {
outputFile = inputFile + zstdExtension;
// Attempt to add/remove zstd extension from the input file
if (decompress) {
int stemSize = inputFile.size() - zstdExtension.size();
if (stemSize > 0 && inputFile.substr(stemSize) == zstdExtension) {
outputFile = inputFile.substr(0, stemSize);
} else {
std::fprintf(
stderr, "Invalid argument: Unable to determine output file.\n");
return false;
}
} else {
outputFile = inputFile + zstdExtension;
}
}
}
// Check compression level