Skip to content

Commit

Permalink
dev: Zip multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
enzoevers committed Dec 27, 2024
1 parent 82a600d commit 44ca145
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CoDeLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ set(COMMON_HEADERS
${CoDeLib_PUBLIC_INCLUDE_PATH}/IDeflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IInflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IUnZip.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IZip.h
)
install(FILES ${COMMON_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CoDeLib)

add_subdirectory(Deflate_zlib)
add_subdirectory(Inflate_zlib)
add_subdirectory(FileUtils)
add_subdirectory(UnZip_minizip)
add_subdirectory(Zip_minizip)
add_subdirectory(RaiiString)
add_subdirectory(ZipContentInfo)
add_subdirectory(Test)

install(
TARGETS CoDeLib Deflate_zlib Inflate_zlib UnZip_minizip RaiiString ZipContentInfo FileUtils
TARGETS CoDeLib Deflate_zlib Inflate_zlib UnZip_minizip Zip_minizip RaiiString ZipContentInfo FileUtils
EXPORT CoDeLibTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
2 changes: 2 additions & 0 deletions CoDeLib/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ add_executable(CoDeLib_Test
src/TestDeflateInflateZlib.c
src/TestFileUtils.c
src/TestUnZipMinizip.c
src/TestZipMinizip.c
src/TestUnZipMinizipInflateZlib.c
src/TestZipContentInfo.c
)
Expand All @@ -27,6 +28,7 @@ target_link_libraries(CoDeLib_Test PRIVATE Deflate_zlib)
target_link_libraries(CoDeLib_Test PRIVATE Inflate_zlib)
target_link_libraries(CoDeLib_Test PRIVATE FileUtils)
target_link_libraries(CoDeLib_Test PRIVATE UnZip_minizip)
target_link_libraries(CoDeLib_Test PRIVATE Zip_minizip)
target_link_libraries(CoDeLib_Test PRIVATE RaiiString)
target_link_libraries(CoDeLib_Test PRIVATE ZipContentInfo)

Expand Down
63 changes: 63 additions & 0 deletions CoDeLib/Test/src/TestZipMinizip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "TestZipMinizip.h"
#include "unity_fixture.h"
#include <CoDeLib/FileUtils/FileUtils.h>
#include <CoDeLib/RaiiString/RaiiString.h>
#include <CoDeLib/Zip_minizip/Zip_minizip.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>

static char *g_pFullPathToBenchmarkTestFiles;

void SetupTestZipMinizip(char *pFullPathToBenchmarkTestFiles) {
g_pFullPathToBenchmarkTestFiles = pFullPathToBenchmarkTestFiles;
}

TEST_GROUP(TestZipMinizip);

static RaiiString g_pathToSmallBasicTextFileZipSource;
static RaiiString g_pathToMultiTextFileZipSource;
static RaiiString g_pathToMultiTextFileAndSubDirZipSource;

TEST_SETUP(TestZipMinizip) {
g_pathToSmallBasicTextFileZipSource =
RaiiStringCreateFromCString(g_pFullPathToBenchmarkTestFiles);
RaiiStringAppend_cString(&g_pathToSmallBasicTextFileZipSource,
"/SmallBasicTextFileZip/");

g_pathToMultiTextFileZipSource =
RaiiStringCreateFromCString(g_pFullPathToBenchmarkTestFiles);
RaiiStringAppend_cString(&g_pathToMultiTextFileZipSource,
"/MultiTextFileZip/");

g_pathToMultiTextFileAndSubDirZipSource =
RaiiStringCreateFromCString(g_pFullPathToBenchmarkTestFiles);
RaiiStringAppend_cString(&g_pathToMultiTextFileAndSubDirZipSource,
"/MultiTextFileAndSubDirZip/");
}

TEST_TEAR_DOWN(TestZipMinizip) {
RaiiStringClean(&g_pathToSmallBasicTextFileZipSource);
RaiiStringClean(&g_pathToMultiTextFileZipSource);
RaiiStringClean(&g_pathToMultiTextFileAndSubDirZipSource);

if (PathExists("./tmp/")) {
TEST_ASSERT_TRUE(RecursiveRmdir("./tmp/"));
}
}

//==============================
// Zip()
//==============================

TEST(TestZipMinizip, test_Zip_gfds) { TEST_IGNORE_MESSAGE("Implement me!"); }

//==============================
// TEST_GROUP_RUNNER
//==============================

TEST_GROUP_RUNNER(TestZipMinizip) {
// Zip()
RUN_TEST_CASE(TestZipMinizip, test_Zip_gfds);
}
3 changes: 3 additions & 0 deletions CoDeLib/Test/src/TestZipMinizip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void SetupTestZipMinizip(char *pFullPathToBenchmarkTestFiles);
3 changes: 3 additions & 0 deletions CoDeLib/Test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "TestFileUtils.h"
#include "TestUnZipMinizip.h"
#include "TestUnZipMinizipInflateZlib.h"
#include "TestZipMinizip.h"
#include <CoDeLib/FileUtils/FileUtils.h>
#include <CoDeLib/RaiiString/RaiiString.h>

Expand All @@ -12,6 +13,7 @@ static void RunAllTests(void) {
RUN_TEST_GROUP(TestDeflateInflateZlib);
RUN_TEST_GROUP(TestFileUtils);
RUN_TEST_GROUP(TestUnZipMinizip);
RUN_TEST_GROUP(TestZipMinizip);
RUN_TEST_GROUP(TestUnZipMinizipInflateZlib);
RUN_TEST_GROUP(TestZipContentInfo);
}
Expand All @@ -35,6 +37,7 @@ int main(int argc, const char **argv) {
SetupTestFileUtils(fullPathToBenchmarkTestFiles.pString,
currentWorkingDirectory.pString);
SetupTestUnZipMinizip(fullPathToBenchmarkTestFiles.pString);
SetupTestZipMinizip(fullPathToBenchmarkTestFiles.pString);
SetupTestUnZipMinizipInflateZlib(fullPathToBenchmarkTestFiles.pString);

return UnityMain(argc, argv, RunAllTests);
Expand Down
16 changes: 16 additions & 0 deletions CoDeLib/Zip_minizip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
add_library(Zip_minizip STATIC
src/Zip_minizip.c)

target_include_directories(Zip_minizip PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

find_package(MINIZIP REQUIRED)
target_link_libraries(Zip_minizip PRIVATE MINIZIP::minizip)

set(Zip_minizip_PUBLIC_INCLUDE_PATH ${CoDeLib_PUBLIC_INCLUDE_PATH}/Zip_minizip)
set(Zip_minizip_PUBLIC_HEADERS
${Zip_minizip_PUBLIC_INCLUDE_PATH}/Zip_minizip.h
)
install(FILES ${Zip_minizip_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CoDeLib/Zip_minizip)
29 changes: 29 additions & 0 deletions CoDeLib/Zip_minizip/src/Zip_minizip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <CoDeLib/FileUtils/FileUtils.h>
#include <CoDeLib/Zip_minizip/Zip_minizip.h>

// minizip
#include <mz.h>
#include <unzip.h>

//==============================
// Helper functions
//==============================

//==============================
// Interface functions
//==============================

ZIP_RETURN_CODES
Zip(const RaiiString *const pOutputZipPath __attribute__((unused)),
const RaiiString *const pInputPathArray __attribute__((unused)),
const size_t inputPathArraySize __attribute__((unused))) {
return ZIP_ERROR;
}

const struct IZip zip_minizip = {
.Zip = Zip,
};

//==============================
// Helper functions
//==============================
26 changes: 26 additions & 0 deletions CoDeLib/include/CoDeLib/IZip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <CoDeLib/ZipContentInfo.h>
#include <stdio.h>

typedef enum { ZIP_SUCCESS, ZIP_ERROR } ZIP_RETURN_CODES;

struct IZip {
/*!
* @brief Zips the input file(s) and write the output to the output zip
* file.
* @param pOutputZipPath The path to the output zip file. If the directory
* does not exist, it will be created.
* @param pInputPathArray The array of paths to the files to be zipped. Both
* absolute and relative paths are supported. Path to directories will zip
* all files and sub-directories in the directory. Path to files will zip
* the file. The array can be a mix of absolute, relative, directies and
* files.
* @param inputPathArraySize The number of elements in pInputPathArray.
* @return ZIP_SUCCESS if the zipping was successful, ZIP_ERROR
* otherwise.
*/
ZIP_RETURN_CODES(*Zip)
(const RaiiString *const pOutputZipPath,
const RaiiString *const pInputPathArray, const size_t inputPathArraySize);
};
5 changes: 5 additions & 0 deletions CoDeLib/include/CoDeLib/Zip_minizip/Zip_minizip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <CoDeLib/IZip.h>

extern const struct IZip zip_minizip;

0 comments on commit 44ca145

Please sign in to comment.