tools/zlibutil: Chnage CLI to act more like other compression utilities
Compression is now the implied default action, decompress with the -d flag.
parent
e0cb220d37
commit
e87435dc0b
|
@ -105,7 +105,7 @@ std::vector<char> decompressData(const char* data, int size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Finnaly, the main file
|
Finally, the main file
|
||||||
⠀⠀⠀⠀⠀⠀⠀⢠⣤⣄⣀⣠⣤⣶⣿⣯⣿⣽⣾⣷⣶⣶⡦⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⠀⠀⢠⣤⣄⣀⣠⣤⣶⣿⣯⣿⣽⣾⣷⣶⣶⡦⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⠀⠀⢀⣿⣟⣯⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣦⣄⠀⠀⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⠀⠀⢀⣿⣟⣯⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣟⣦⣄⠀⠀⠀⠀⠀⠀⠀
|
||||||
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣾⡷⣄⠀⠀⠀⠀⠀
|
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣿⣾⡷⣄⠀⠀⠀⠀⠀
|
||||||
|
@ -135,7 +135,6 @@ 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;
|
||||||
|
@ -174,32 +173,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