this added some small refinements as well as first forays in working with gz files. Added zlib.h. Checked if valid gz file via mgic number.

This commit is contained in:
Marcel Nowicki
2022-02-11 03:28:13 +01:00
parent 0114829d5b
commit a80f78c36d
2 changed files with 19 additions and 0 deletions

View File

@@ -1,7 +1,10 @@
cmake_minimum_required(VERSION 3.21) cmake_minimum_required(VERSION 3.21)
project(Tarstats__) project(Tarstats__)
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -std=c++20") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -std=c++20")
add_executable(tarstats_pp main.cpp tarconst.h tarfunc.cpp tarfunc.h) add_executable(tarstats_pp main.cpp tarconst.h tarfunc.cpp tarfunc.h)
target_link_libraries(tarstats_pp)

View File

@@ -9,6 +9,7 @@
#include <filesystem> #include <filesystem>
#include "tarconst.h" #include "tarconst.h"
#include "tarfunc.h" #include "tarfunc.h"
#include "zlib.h"
int main(int argc, char** argv) { int main(int argc, char** argv) {
// Trivial check for arguments. // Trivial check for arguments.
@@ -26,6 +27,7 @@ int main(int argc, char** argv) {
} }
bool toFile = false; bool toFile = false;
bool toJSON = false; bool toJSON = false;
bool g = false;
std::vector<std::string> archiveFilename {}; std::vector<std::string> archiveFilename {};
for (auto i : cmdparam) { for (auto i : cmdparam) {
@@ -44,6 +46,9 @@ int main(int argc, char** argv) {
case 'h': case 'h':
tar::printhelp(); tar::printhelp();
return 9; return 9;
case 'g':
g = true;
break;
case '-': case '-':
break; break;
default: default:
@@ -55,6 +60,17 @@ int main(int argc, char** argv) {
} }
} }
if (g) {
std::ifstream test("test4.tar.gz", std::ios::binary);
char x;
test.seekg(1);
test.read((&x), 1);
test.close();
if (x == '\213')
std::cout << "success" << std::endl;
return 0;
}
for (auto &archiveName : archiveFilename) { for (auto &archiveName : archiveFilename) {
//count the types of all items //count the types of all items
std::map<std::string, uintmax_t> typecount{ std::map<std::string, uintmax_t> typecount{