Added possible gzip compression
This commit is contained in:
parent
089c5d1721
commit
a85dbd3bd5
5 changed files with 76 additions and 2 deletions
|
@ -1,5 +1,14 @@
|
|||
cmake_minimum_required (VERSION 2.6)
|
||||
project(cookiebot)
|
||||
set(CMAKE_BUILD_TYPE DEBUG)
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -pg -std=c99")
|
||||
set(CMAKE_C_FLAGS_MINSIZEREL "-Os -std=c99")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O0 -g -std=c99")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c99")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -pg -std=gnu++14")
|
||||
set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -std=gnu++14")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O0 -g -std=gnu++14")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -std=gnu++14")
|
||||
set (cookiebot_VERSION_MAJOR 0)
|
||||
set (cookiebot_VERSION_MINOR 0)
|
||||
find_package (ZLIB)
|
||||
|
@ -25,6 +34,7 @@ configure_file (
|
|||
"${PROJECT_BINARY_DIR}/cookiebot_conf.h"
|
||||
)
|
||||
include_directories("${PROJECT_BINARY_DIR}")
|
||||
include_directories("${PROJECT_SOURCE_DIR}/include")
|
||||
if (MOD_GZIP)
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} z)
|
||||
endif (MOD_GZIP)
|
||||
|
@ -34,5 +44,6 @@ endif (MOD_BZ2)
|
|||
if (MOD_XZ)
|
||||
set(EXTRA_LIBS ${EXTRA_LIBS} lzma)
|
||||
endif (MOD_XZ)
|
||||
add_executable(cookiebot cookiebot.cpp)
|
||||
|
||||
add_executable(cookiebot cookiebot.cpp module_storage.cpp)
|
||||
target_link_libraries (cookiebot ${EXTRA_LIBS})
|
||||
|
|
|
@ -1,9 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include "cookiebot_conf.h"
|
||||
#include <module_storage.hpp>
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
|
||||
#ifdef USE_GZIP
|
||||
printf("I use GZip\n");
|
||||
#endif
|
||||
#ifdef USE_BZIP2
|
||||
printf("I use BZip2\n");
|
||||
#endif
|
||||
#ifdef USE_XZ
|
||||
printf("I use XZ\n");
|
||||
#endif
|
||||
std::cout << getModuleStorage("test.gz") << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
#define VERSION_MAJOR @cookiebot_VERSION_MAJOR@
|
||||
#define VERSION_MINOR @cookiebot_VERSION_MINOR@
|
||||
#define ON 1
|
||||
#define OFF 0
|
||||
#define USE_GZIP @MOD_GZIP@
|
||||
#define USE_BZIP2 @MOD_BZ2@
|
||||
#define USE_XZ @MOD_XZ@
|
||||
|
|
5
include/module_storage.hpp
Normal file
5
include/module_storage.hpp
Normal file
|
@ -0,0 +1,5 @@
|
|||
#ifndef __MODULE_STORAGE_HPP
|
||||
#define __MODULE_STORAGE_HPP
|
||||
#include <string>
|
||||
auto getModuleStorage(std::string filename) -> std::string;
|
||||
#endif /* end of include guard: __MODULE_STORAGE_HPP */
|
42
module_storage.cpp
Normal file
42
module_storage.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
|
||||
#define CHUNK 16384
|
||||
#include <module_storage.hpp>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "cookiebot_conf.h"
|
||||
#include <iostream>
|
||||
#if USE_GZIP == ON
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
auto getModuleStorage(std::string filename) -> std::string {
|
||||
std::string::size_type idx;
|
||||
idx = filename.rfind('.');
|
||||
|
||||
if(idx != std::string::npos)
|
||||
{
|
||||
std::string extension = filename.substr(idx+1);
|
||||
#if USE_GZIP == ON
|
||||
if(extension=="gz") {
|
||||
FILE *out;
|
||||
out=fopen(filename.substr(0,idx).c_str(), "wb");
|
||||
struct gzFile_s *file = gzopen(filename.c_str(),"rb");
|
||||
size_t len=1024*1024;
|
||||
gzrewind(file);
|
||||
uint8_t *buf=new uint8_t[len];
|
||||
gzread(file, (void*)buf, len);
|
||||
std::cout << buf << std::endl;
|
||||
fwrite((void*)buf, len, 1, out);
|
||||
gzclose(file);
|
||||
fclose(out);
|
||||
delete[] buf;
|
||||
return filename.substr(0,idx);
|
||||
}
|
||||
#endif
|
||||
return filename;
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue