From ac14348a283b54603f60353cd3763f9434b73616 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Fri, 2 Sep 2016 12:35:36 -0700 Subject: [PATCH] When reading from stdin, write to stdout by default --- contrib/pzstd/Options.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/contrib/pzstd/Options.cpp b/contrib/pzstd/Options.cpp index 693e9a515..616130996 100644 --- a/contrib/pzstd/Options.cpp +++ b/contrib/pzstd/Options.cpp @@ -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