Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Commit

Permalink
Add '-k' keep and '-N' name options
Browse files Browse the repository at this point in the history
  • Loading branch information
twekkel committed Nov 28, 2019
1 parent 3a3c667 commit bcf602e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

mzpq compresses files using the ZPAQ compression library. The command-line options are deliberately very similar to those of gzip/bzip2/xz/zstd, but they are not identical. In general mzpq will achive very high compression, at the cost of memory and speed.

zpaq is a journaling archiver written by Matt Mahoney. The command line for zpaq is suited for creating encrypted, deduplicated, compressed, incremental backups. mzpq uses the same compression library, but with a simpler command line interface for only compression. zpaq can still extract compressed files created by mzpq.
zpaq is a journaling archiver written by Matt Mahoney. The command line for zpaq is suited for creating encrypted, deduplicated, compressed, incremental backups. mzpq uses the same compression library, but with a simpler command line interface for compression only. zpaq can still extract compressed files created by mzpq.

'm' in mzpq stands for micro/mini/minimalistic/... 'a' has been stripped of, as it is not an archiver like zpaq.

Expand All @@ -20,7 +20,7 @@ make

Install:
```
make install
sudo make install
```


Expand Down
22 changes: 18 additions & 4 deletions mzpq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ bool fexists(const std::string file) {

void usage() {
printf(
"Usage: mzpq [-1..9] [-cdfhV] [-m method] [files]\n"
"Usage: mzpq [-1..9] [-cdfhkNV] [-m method] [files]\n"
"\n"
" -1..9 compression level, default 4\n"
" -c write to standard output\n"
" -d decompress\n"
" -f force overwrite of output file\n"
" -f overwrite existing output files\n"
" -h this help\n"
" -k keep (don't delete) input files\n"
" -m compression method, see libzpaq.h for details\n"
" -N save original file name when compressing\n"
" -V version\n"
);
exit(1);
Expand All @@ -51,13 +53,15 @@ int main(int argc, char **argv) {
bool conout = false;
bool compress = true;
bool force = false;
bool keep = false;
bool name = false;
std::size_t found;
std::string method = "4";
std::string fname;
std::string fnorg;

// Parse command line arguments
while ((c = getopt (argc, argv, "123456789cdfhm:V")) != -1)
while ((c = getopt (argc, argv, "123456789cdfhkm:NV")) != -1)
switch(c)
{
case '1':
Expand Down Expand Up @@ -99,9 +103,15 @@ int main(int argc, char **argv) {
case 'h':
usage();
break;
case 'k':
keep = true;
break;
case 'm':
method = optarg;
break;
case 'N':
name = true;
break;
case 'V':
version();
break;
Expand All @@ -115,7 +125,7 @@ int main(int argc, char **argv) {

if ( argv[i] != NULL ) fname = argv[i];
if ( fname.compare("-") == 0) fname.clear();
std::string fnorg = fname;
if ( name ) fnorg = fname;

// Try to read from file
if ( ! fname.empty() && ! fexists(fname) ) {
Expand Down Expand Up @@ -159,6 +169,10 @@ int main(int argc, char **argv) {
libzpaq::decompress(&in, &out);
}

// Remove input file
if ( ! keep && ! fnorg.empty() ) remove(fnorg.c_str());

// Next file
i++;
} while ( i < argc );

Expand Down

0 comments on commit bcf602e

Please sign in to comment.