tools/zlibutil: Change CLI to act more like other compression utilities
Compression is now the implied default action, decompress with the -d flag.master
parent
a787a89493
commit
a48c4dcd33
|
@ -36,7 +36,7 @@
|
||||||
#define CHUNK_SIZE 16384 // Chunk size
|
#define CHUNK_SIZE 16384 // Chunk size
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Finnaly, the main file
|
Finally, the main file
|
||||||
⠀⠀⠀⠀⠀⠀⠀⢠⣤⣄⣀⣠⣤⣶⣿⣯⣿⣽⣾⣷⣶⣶⡦⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⠀⠀⢠⣤⣄⣀⣠⣤⣶⣿⣯⣿⣽⣾⣷⣶⣶⡦⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⠀⠀⢀⣿⣟⣯⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣦⣄⠀⠀⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⠀⠀⢀⣿⣟⣯⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣦⣄⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣾⡷⣄⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣾⡷⣄⠀⠀⠀⠀⠀
|
||||||
|
@ -66,8 +66,7 @@ Finnaly, the main file
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::vector<CLI::Flag> flags;
|
std::vector<CLI::Flag> flags;
|
||||||
flags.push_back(CLI::Flag('c', "compress", "compress a file"));
|
flags.push_back(CLI::Flag('d', "decompress", "descompress a file"));
|
||||||
flags.push_back(CLI::Flag('d', "decompress", "descompress a file"));
|
|
||||||
std::vector<CLI::Option> options;
|
std::vector<CLI::Option> options;
|
||||||
std::vector<CLI::Argument> arguments;
|
std::vector<CLI::Argument> arguments;
|
||||||
arguments.push_back(CLI::Argument("FILE", "path of the file to compress/decompress"));
|
arguments.push_back(CLI::Argument("FILE", "path of the file to compress/decompress"));
|
||||||
|
@ -105,32 +104,39 @@ int main(int argc, char* argv[]) {
|
||||||
return EXIT_USAGE;
|
return EXIT_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string filename = cliParser.getArgument(0).value;
|
||||||
|
|
||||||
ErrorOr<File*> filePointer = File::open(cliParser.getArgument(0).value, 'r');
|
ErrorOr<File*> filePointer = File::open(filename, 'r');
|
||||||
if (filePointer.isError) {
|
if (filePointer.isError) {
|
||||||
std::cout << "Failed to open file: " << cliParser.getArgument(0).value << std::endl;
|
std::cout << "Failed to open file: " << filename << std::endl;
|
||||||
return EXIT_RUNTIME;
|
return EXIT_RUNTIME;
|
||||||
}
|
}
|
||||||
File* file = filePointer.value;
|
File* file = filePointer.value;
|
||||||
File *writeFile;
|
File *writeFile;
|
||||||
|
|
||||||
if (cliParser.getFlag("compress").value) {
|
if (cliParser.getFlag("decompress").value) {
|
||||||
std::vector<uint8_t> bytes = file->read(file->size.value).value; // this is what you get from lib/file IIRC
|
|
||||||
std::vector<char> differentBytes = std::vector<char>(bytes.begin(), bytes.end());
|
|
||||||
|
|
||||||
std::vector<char> compressed = compressData(differentBytes.data(), file->size.value);
|
|
||||||
std::vector<unsigned char> unsigneddata = std::vector<unsigned char>(compressed.begin(), compressed.end());
|
|
||||||
writeFile = File::open(cliParser.getArgument(0).value + ".compressed", 'w').value;
|
|
||||||
writeFile->write(unsigneddata);
|
|
||||||
writeFile->close();
|
|
||||||
} else if (cliParser.getFlag("decompress").value) {
|
|
||||||
std::vector<uint8_t> bytes = file->read(file->size.value).value; // this is what you get from lib/file IIRC
|
std::vector<uint8_t> bytes = file->read(file->size.value).value; // this is what you get from lib/file IIRC
|
||||||
std::vector<char> differentBytes = std::vector<char>(bytes.begin(), bytes.end());
|
std::vector<char> differentBytes = std::vector<char>(bytes.begin(), bytes.end());
|
||||||
|
|
||||||
std::vector<char> compressed = decompressData(differentBytes.data(), file->size.value);
|
std::vector<char> compressed = decompressData(differentBytes.data(), file->size.value);
|
||||||
std::vector<unsigned char> unsigneddata = std::vector<unsigned char>(compressed.begin(), compressed.end());
|
std::vector<unsigned char> unsigneddata = std::vector<unsigned char>(compressed.begin(), compressed.end());
|
||||||
|
|
||||||
writeFile = File::open(cliParser.getArgument(0).value + ".uncompressed", 'w').value;
|
std::string outFilename;
|
||||||
|
if (filename.length() > 3 && filename.rfind(".zz") == filename.length()-3) {
|
||||||
|
outFilename = filename.substr(0, filename.length()-3);
|
||||||
|
} else {
|
||||||
|
outFilename = filename + ".uncompressed";
|
||||||
|
}
|
||||||
|
writeFile = File::open(outFilename, 'w').value;
|
||||||
|
writeFile->write(unsigneddata);
|
||||||
|
writeFile->close();
|
||||||
|
} else {
|
||||||
|
std::vector<uint8_t> bytes = file->read(file->size.value).value; // this is what you get from lib/file IIRC
|
||||||
|
std::vector<char> differentBytes = std::vector<char>(bytes.begin(), bytes.end());
|
||||||
|
|
||||||
|
std::vector<char> compressed = compressData(differentBytes.data(), file->size.value);
|
||||||
|
std::vector<unsigned char> unsigneddata = std::vector<unsigned char>(compressed.begin(), compressed.end());
|
||||||
|
writeFile = File::open(filename + ".zz", 'w').value;
|
||||||
writeFile->write(unsigneddata);
|
writeFile->write(unsigneddata);
|
||||||
writeFile->close();
|
writeFile->close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue