### Configure Zlib Example Dependencies Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Configures include directories and dependencies for zlib example executables ('example' and 'example64') when MZ_ZLIB is enabled, MZ_LIBCOMP is not, and ZLIB_FOUND is false. This ensures the zlib source directory is available for the example targets. ```cmake if(MZ_ZLIB AND NOT MZ_LIBCOMP AND NOT ZLIB_FOUND) if(TARGET example) target_include_directories(example PRIVATE ${ZLIB_SOURCE_DIR}) add_dependencies(${MINIZIP_TARGET} example) endif() if(TARGET example64) target_include_directories(example64 PRIVATE ${ZLIB_SOURCE_DIR}) add_dependencies(${MINIZIP_TARGET} example64) endif() endif() ``` -------------------------------- ### Install Pkgconfig File Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Installs the pkgconfig file for the library to the pkgconfig directory. ```cmake install(FILES ${MINIZIP_PC} DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") ``` -------------------------------- ### Install Libraries and Targets Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Installs the main target, its dependencies, and associated CMake export files. It also sets up include directories for installation. ```cmake target_include_directories(${MINIZIP_TARGET} PUBLIC $) # Resolve alias targets to their real targets for installation set(MINIZIP_DEP_REAL) foreach(dep_target ${MINIZIP_DEP}) get_target_property(alias_target ${dep_target} ALIASED_TARGET) if(alias_target) list(APPEND MINIZIP_DEP_REAL ${alias_target}) else() list(APPEND MINIZIP_DEP_REAL ${dep_target}) endif() endforeach() install(TARGETS ${MINIZIP_TARGET} ${MINIZIP_DEP_REAL} EXPORT ${MINIZIP_TARGET}-targets INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${MINIZIP_TARGET}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(EXPORT ${MINIZIP_TARGET}-targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${MINIZIP_TARGET}" NAMESPACE "MINIZIP::") ``` -------------------------------- ### Install Headers Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Installs the header files for the library to the specified include directory. ```cmake install(FILES ${MINIZIP_HDR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${MINIZIP_TARGET}") ``` -------------------------------- ### Compile and Install Zlib on Windows Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Compile and install zlib to a specified directory using CMake on Windows. Requires an Administrator command prompt. ```bash cmake -DCMAKE_INSTALL_PREFIX="C:\Program Files (x86)\zlib" . cmake --build . --config Release --target INSTALL ``` -------------------------------- ### Generate and Install CMake Package Config Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Creates and installs a CMake package configuration file and version file to support `find_package()` for the installed library. It includes logic for handling dependencies. ```cmake include(CMakePackageConfigHelpers) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}-config-version.cmake COMPATIBILITY SameMajorVersion) set(MINIZIP_CONFIG_CONTENT "@PACKAGE_INIT@\n") if(MINIZIP_DEP_PKG_PUBLIC OR (MINIZIP_DEP_PKG AND NOT BUILD_SHARED_LIBS)) string(APPEND MINIZIP_CONFIG_CONTENT "include(CMakeFindDependencyMacro)\n") foreach(pkg_name ${MINIZIP_DEP_PKG_PUBLIC}) string(APPEND MINIZIP_CONFIG_CONTENT "find_dependency(${pkg_name})\n") endforeach() # PRIVATE-linked deps are encapsulated in the shared library; consumers # of a static minizip still need them to satisfy transitive symbols. if(NOT BUILD_SHARED_LIBS) foreach(pkg_name ${MINIZIP_DEP_PKG}) string(APPEND MINIZIP_CONFIG_CONTENT "find_dependency(${pkg_name})\n") endforeach() endif() endif() string(APPEND MINIZIP_CONFIG_CONTENT "include(\" ${CMAKE_CURRENT_LIST_DIR}/${MINIZIP_TARGET}-targets.cmake\")") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/minizip-config.cmake.in ${MINIZIP_CONFIG_CONTENT}) # Create config for find_package() configure_package_config_file( ${CMAKE_CURRENT_BINARY_DIR}/minizip-config.cmake.in ${MINIZIP_TARGET}-config.cmake INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${MINIZIP_TARGET}") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}-config-version.cmake ${CMAKE_CURRENT_BINARY_DIR}/${MINIZIP_TARGET}-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${MINIZIP_TARGET}") ``` -------------------------------- ### Configure CMake with Existing Zlib Installation on Windows Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Point CMake to your existing zlib installation directories on Windows by specifying the library file path and include directory. ```bash cmake -DZLIB_LIBRARY:FILEPATH="C:\Program Files (x86)\zlib\lib\zlibstaticd.lib" . cmake -DZLIB_INCLUDE_DIR:PATH="C:\Program Files (x86)\zlib\include" . ``` -------------------------------- ### Install Fuzzer Executables Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Installs the zip_fuzzer and unzip_fuzzer executables to the runtime directory. This is conditional on SKIP_INSTALL_BINARIES and SKIP_INSTALL_ALL not being set. ```cmake install(TARGETS zip_fuzzer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(TARGETS unzip_fuzzer RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") ``` -------------------------------- ### Initialize Encryption Keys (Pseudocode) Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/zip/appnote.iz.txt This pseudocode outlines the initial setup of three 32-bit keys using a password. The keys are updated iteratively for each character in the password. ```pseudocode Key(0) <- 305419896 Key(1) <- 591751049 Key(2) <- 878082192 loop for i <- 0 to length(password)-1 update_keys(password(i)) end loop ``` -------------------------------- ### Open Zip File from File Path Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Opens a zip file directly from a given file path. The example shows creating a reader, opening the file, and then closing the reader. ```c const char *path = "c:\\my.zip"; void *zip_reader = mz_zip_reader_create(); if (mz_zip_reader_open_file(zip_reader, path) == MZ_OK) { printf("Zip reader was opened %s\n", path); mz_zip_reader_close(zip_reader); } mz_zip_reader_delete(&zip_reader); ``` -------------------------------- ### Open Zip File from Stream Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Opens a zip file from a provided stream. This example demonstrates opening a file stream, then opening the zip reader with that stream, and finally closing both. ```c const char *path = "c:\\my.zip"; void *zip_reader = mz_zip_reader_create(); void *file_stream = mz_stream_os_create(); err = mz_stream_os_open(file_stream, path, MZ_OPEN_MODE_READ); if (err == MZ_OK) { err = mz_zip_reader_open(zip_reader, file_stream); if (err == MZ_OK) { printf("Zip reader was opened %s\n", path); mz_zip_reader_close(zip_reader); } } mz_stream_os_delete(&file_stream); mz_zip_reader_delete(&zip_reader); ``` -------------------------------- ### Generate Xcode Project with CMake Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Use this command to create an Xcode project from a CMake build system. Ensure Git is installed if zlib is not found. ```bash cmake -G Xcode . ``` -------------------------------- ### Get Zip Reader Handle and Navigate Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Retrieves the underlying zip instance handle from a mz_zip_reader and then navigates to the first entry. ```c void *zip_handle = NULL; mz_zip_reader_get_zip_handle(zip_reader, &zip_handle); mz_zip_goto_first_entry(zip_handle); ``` -------------------------------- ### Get Compression Method String Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves a human-readable string representation for a given compression method code. Returns '?' if the method is not recognized. ```c const char *method = mz_zip_get_compression_method_string(MZ_ZIP_COMPRESS_METHOD_LZMA); printf("Compression method %s\n", method); ``` -------------------------------- ### Build minizip-ng with Tests Source: https://github.com/zlib-ng/minizip-ng/blob/develop/README.md This command generates project files for building minizip-ng with tests enabled using CMake. Ensure CMake version 3.11 or later is installed. ```bash cmake -S . -B build -D MZ_BUILD_TESTS=ON cmake --build build ``` -------------------------------- ### Configure ZSTD Support Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt This snippet enables Zstandard (ZSTD) compression support. It searches for an existing ZSTD installation or fetches it if configured. It then adds the necessary include paths, dependencies, and definitions for ZSTD compression. ```cmake if(MZ_ZSTD) # Check if zstd is present if(NOT MZ_FORCE_FETCH_LIBS) find_package(zstd QUIET CONFIG) endif() if(zstd_FOUND AND NOT MZ_FORCE_FETCH_LIBS) message(STATUS "Using ZSTD ${zstd_VERSION}") if(BUILD_SHARED_LIBS) list(APPEND MINIZIP_LIB zstd::libzstd_shared) else() list(APPEND MINIZIP_LIB zstd::libzstd_static) endif() set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lzstd") elseif(MZ_FETCH_LIBS) set(ZSTD_BUILD_PROGRAMS OFF CACHE BOOL "Build zstd programs") clone_repo(zstd https://github.com/facebook/zstd release build/cmake) list(APPEND MINIZIP_INC ${ZSTD_SOURCE_DIR}/lib) if(NOT DEFINED BUILD_SHARED_LIBS OR NOT ${BUILD_SHARED_LIBS}) list(APPEND MINIZIP_DEP libzstd_static) else() list(APPEND MINIZIP_DEP libzstd_shared) endif() else() message(STATUS "ZSTD library not found") set(MZ_ZSTD OFF) endif() if(MZ_ZSTD) if(zstd_FOUND) list(APPEND MINIZIP_DEP_PKG zstd) endif() list(APPEND MINIZIP_DEF -DHAVE_ZSTD) list(APPEND MINIZIP_SRC mz_strm_zstd.c) list(APPEND MINIZIP_HDR mz_strm_zstd.h) endif() endif() ``` -------------------------------- ### Get Raw Entry Writing Status Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Retrieves the current setting for raw entry writing. The status is stored in the provided 'raw' pointer. Returns MZ_OK on success. ```c uint8_t raw = 0; mz_zip_writer_get_raw(zip_writer, &raw); printf("Writing zip entries in mode: %s\n", (raw) ? "raw" : "normal"); ``` -------------------------------- ### Get Local File Header Entry Info Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves local file header information for the current zip entry. The returned pointer is only valid while the entry remains current. ```c int32_t err = mz_zip_goto_first_entry(zip_handle); if (err == MZ_OK) { mz_zip_file *local_file_info = NULL; err = mz_zip_entry_get_info(zip_handle, &local_file_info); if (err == MZ_OK) { printf("Local header entry filename: %s\n", local_file_info->filename); } } ``` -------------------------------- ### Using a Buffered Stream for I/O Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Illustrates how to wrap an existing stream with a buffered stream to enhance I/O performance for read operations. This improves efficiency by reducing the number of individual read calls. ```c void *stream = NULL; void *buf_stream = NULL; void *zip_handle = NULL; stream = mz_stream_os_create() buf_stream = mz_stream_buffered_create(); mz_stream_set_base(buf_stream, stream); mz_stream_buffered_open(buf_stream, NULL, MZ_OPEN_MODE_READ); // This will also call mz_stream_os_open zip_handle = mz_zip_create(); err = mz_zip_open(zip_handle, buf_stream, MZ_OPEN_MODE_READ); /* TODO: unzip operation.. */ mz_zip_close(zip_handle); mz_zip_delete(&zip_handle); mz_stream_buffered_delete(&buf_stream); ``` -------------------------------- ### Create Directory Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Creates a single directory at the specified path. For recursive directory creation, use `mz_dir_make`. ```c if (mz_os_make_dir("c:\\testdir\\") == MZ_OK) printf("Test directory created\n"); ``` -------------------------------- ### mz_os_ms_time Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Gets the current system time in milliseconds. ```APIDOC ## mz_os_ms_time ### Description Gets the time in milliseconds. ### Return - **uint64_t** - Current time in milliseconds ### Example ```c uint64_t current_time = mz_os_ms_time(); printf("Current time in %lldms\n", current_time); ``` ``` -------------------------------- ### Creating a Zip File in Memory Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Shows how to create a zip archive directly in memory using a growable memory stream. The stream's size can be set to optimize performance. ```c void *mem_stream = NULL; void *zip_handle = NULL; mem_stream = mz_stream_mem_create(); mz_stream_mem_set_grow_size(mem_stream, (128 * 1024)); mz_stream_open(mem_stream, NULL, MZ_OPEN_MODE_CREATE); zip_handle = mz_zip_create(); err = mz_zip_open(zip_handle, mem_stream, MZ_OPEN_MODE_WRITE); /* TODO: unzip operations.. */ mz_zip_close(zip_handle); mz_zip_delete(&zip_handle); mz_stream_mem_delete(&mem_stream); ``` -------------------------------- ### mz_zip_reader_get_zip_handle Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Gets the underlying zip instance handle from a mz_zip_reader instance. ```APIDOC ## mz_zip_reader_get_zip_handle ### Description Gets the underlying zip instance handle. ### Method Not applicable (C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **handle** (void *) - _mz_zip_reader_ instance - **zip_handle** (void **) - Pointer to store _mz_zip_ instance ### Return No return value. ### Example ```c void *zip_handle = NULL; mz_zip_reader_get_zip_handle(zip_reader, &zip_handle); mz_zip_goto_first_entry(zip_handle); ``` ``` -------------------------------- ### Configure PPMD Support Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt This snippet sets up support for the PPMD compression algorithm. It fetches the PPMd library from a GitHub repository, extracts its version, and then defines a static library for PPMd, adding it to the minizip-ng build. ```cmake if(MZ_PPMD) message(STATUS "Using PPMD") clone_repo(ppmd https://github.com/ip7z/7zip "26.00") # get the 7zip/PPMd version number file(READ "${PPMD_SOURCE_DIR}/C/7zVersion.h" version) string(REGEX MATCH "MY_VERSION_NUMBERS \"([0-9]*\.[0-9]*)\"" _ ${version}) set(7ZIP_VERSION_NUMBER ${CMAKE_MATCH_1}) message(STATUS " Found 7Zip/PPMd ${7ZIP_VERSION_NUMBER}") # The PPMd repository does not support cmake so we have to create # a PPMd library ourselves set(PPMD_SRC ${PPMD_SOURCE_DIR}/C/Ppmd8.c ${PPMD_SOURCE_DIR}/C/Ppmd8Dec.c ${PPMD_SOURCE_DIR}/C/Ppmd8Enc.c) set(PPMD_HDR ${PPMD_SOURCE_DIR}/C/7zTypes.h ${PPMD_SOURCE_DIR}/C/Compiler.h ${PPMD_SOURCE_DIR}/C/CpuArch.h ${PPMD_SOURCE_DIR}/C/Ppmd.h ${PPMD_SOURCE_DIR}/C/Ppmd8.h ${PPMD_SOURCE_DIR}/C/Precomp.h) add_library(ppmd STATIC ${PPMD_SRC} ${PPMD_HDR}) list(APPEND MINIZIP_DEP ppmd) list(APPEND MINIZIP_INC ${PPMD_SOURCE_DIR}) list(APPEND MINIZIP_DEF -DHAVE_PPMD) list(APPEND MINIZIP_SRC mz_strm_ppmd.c) list(APPEND MINIZIP_HDR mz_strm_ppmd.h) endif() ``` -------------------------------- ### Get File Size Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Retrieves the size of a file in bytes. This function does not check for file existence. ```c const char *path = "c:\\test3.txt"; if (mz_os_file_exists(path) == MZ_OK) { int64_t file_size = mz_os_get_file_size(path); printf("File %s size %lld\n", path, file_size); } else { printf("File %s does not exist\n", path); } ``` -------------------------------- ### Get File Attributes Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Retrieves the attributes of a file, following symbolic links. The attributes are returned as a bitmask. ```c const char *path = "c:\\test6.txt"; uint32_t attributes = 0; if (mz_os_get_file_attribs(path, &attributes) == MZ_OK) printf("File %s attributes %08x\n", attributes); ``` -------------------------------- ### Get Filename from Path Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Extracts the filename component from a given path. The filename is provided via a pointer. ```c const char *path = "c:\\windows\\test.txt"; const char *filename = NULL; printf("Path: %s\n", path); if (mz_path_get_filename(path, &filename) == MZ_OK) printf("Filename: %s\n", filename); else printf("Path has no filename\n"); ``` -------------------------------- ### mz_zip_reader_get_raw Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Gets whether or not the zip entry is being saved as raw data. This indicates if the entry will be saved without decompression. ```APIDOC ## mz_zip_reader_get_raw ### Description Gets whether or not the zip entry is being saved as raw data. This indicates if the entry will be saved without decompression. ### Method int32_t ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **handle** (void *) - _mz_zip_reader_ instance - **raw** (uint8_t *) - Pointer to store if saving as raw data ### Return int32_t - [MZ_ERROR](mz_error.md) code, MZ_OK if successful ### Example ```c uint8_t raw = 0; mz_zip_reader_get_raw(zip_reader, &raw); printf("Entry will be saved as %s data\n", (raw) ? "raw gzip" : "decompressed"); ``` ``` -------------------------------- ### Go to First Zip Entry Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Navigates to the first entry in the zip file. Returns MZ_OK on success, or MZ_END_OF_LIST if no entries exist. ```c int32_t err = mz_zip_goto_first_entry(zip_handle); if (err == MZ_OK) { mz_zip_file *file_info = NULL; err = mz_zip_entry_get_info(zip_handle, &file_info); if (err == MZ_OK) { printf("First entry is %s\n", file_info->filename); } } ``` -------------------------------- ### Get Symbolic Link Attributes Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Retrieves the attributes of a symbolic link. The attributes are stored in the provided uint32_t pointer. ```c const char *path = "c:\\test7.txt"; uint32_t attributes = 0; if (mz_os_get_link_attribs(path, &attributes) == MZ_OK) printf("Link %s attributes %08x\n", path, attributes); ``` -------------------------------- ### Create Symbolic Link Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Creates a new symbolic link at the specified path that points to a target path. Returns MZ_OK on success. ```c const char *path = "c:\\test7.txt"; const char *target_path = "c:\\test8.txt"; if (mz_os_make_symlink(path, target_path) == MZ_OK) printf("Symbolic link created at %s pointing to %s\n", path, target_path); ``` -------------------------------- ### mz_os_get_file_size Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Retrieves the size of a file in bytes. Note that this function does not check for the existence of the file before attempting to get its size. ```APIDOC ## mz_os_get_file_size ### Description Gets the length of a file. ### Arguments #### Path Parameters - **path** (const char *) - Required - File path ### Return - **int64_t** - Size of file, does not check for existence of file. ### Example ```c const char *path = "c:\\test3.txt"; if (mz_os_file_exists(path) == MZ_OK) { int64_t file_size = mz_os_get_file_size(path); printf("File %s size %lld\n", path, file_size); } else { printf("File %s does not exist\n", path); } ``` ``` -------------------------------- ### mz_os_make_dir Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Creates a directory at the specified path. For recursive creation, use `mz_dir_make`. ```APIDOC ## mz_os_make_dir ### Description Creates a directory. To recursively create a directory use _mz_dir_make_. ### Parameters #### Path Parameters - **path** (const char *) - Directory path ### Return - **int32_t** - [MZ_ERROR](mz_error.md) code, MZ_OK if successful ### Example ```c if (mz_os_make_dir("c:\\testdir\\") == MZ_OK) printf("Test directory created\n"); ``` ``` -------------------------------- ### Create Directory Recursively Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Creates a directory and any necessary parent directories. Useful for ensuring a target directory exists before writing files. ```c const char *path = "c:\\temp\\x\\y\\z\\"; if (mz_dir_make(path) == MZ_OK) printf("Dir was created: %s\n", path); else printf("Dir was not created: %s\n", path); ``` -------------------------------- ### Get Current Time in Milliseconds Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Retrieves the current system time in milliseconds. This is useful for timing operations or generating timestamps. ```c uint64_t current_time = mz_os_ms_time(); printf("Current time in %lldms\n", current_time); ``` -------------------------------- ### Open Zip Entry for Writing Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Opens a new entry in the zip file for writing. Requires populating a mz_zip_file structure with entry information. Use MZ_OK to confirm successful opening. ```c mz_zip_file file_info; memset(&file_info, 0, sizeof(file_info)); file_info.version_madeby = MZ_VERSION_MADEBY; file_info.compression_method = MZ_COMPRESS_METHOD_DEFLATE; file_info.filename = "myfile.txt"; file_info.flag = MZ_ZIP_FLAG_UTF8; ... err = mz_zip_entry_write_open(zip_handle, &file_info, 0, NULL); if (err == MZ_OK) printf("Zip entry open for writing\n"); ``` -------------------------------- ### Get Temporary File Path Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Generates a unique temporary file path. Allows specifying an optional prefix for the filename. ```c char tmp_path[256]; if (mz_os_get_temp_path(tmp_path, sizeof(tmp_path), "mz_") == MZ_OK) printf("Temporary path: %s\n", tmp_path); ``` -------------------------------- ### Get File Dates Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Retrieves the modified, accessed, and creation dates of a file. Creation date may not be supported on all systems. ```c const char *path = "c:\\test4.txt"; time_t modified_date, accessed_date, creation_date; if (mz_os_get_file_date(path, &modified_date, &accessed_date, &creation_date) == MZ_OK) printf("File %s modified %lld accessed %lld creation %lld\n", path, modified_date, accessed_date, creation_date); ``` -------------------------------- ### Get File CRC32 Hash Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Calculates the CRC32 hash of a specified file. This function is useful for integrity checks and compatibility. ```c const char *path = "c:\\temp\\test.txt"; uint32_t crc = 0; if (mz_file_get_crc(path, &crc) == MZ_OK) printf("File %s CRC: %08x\n", path, crc); else printf("Failed to calculate CRC: %s\n", path); ``` -------------------------------- ### mz_dir_make Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Creates a directory, including any necessary parent directories, recursively. ```APIDOC ## mz_dir_make ### Description Creates a directory recursively. If parent directories do not exist, they will be created as well. ### Method C Function ### Parameters #### Arguments - **path** (const char *) - Path of the directory to create. ### Return - **int32_t** - MZ_OK if successful, or an MZ_ERROR code. ### Example ```c const char *path = "c:\\temp\\x\\y\\z\\"; if (mz_dir_make(path) == MZ_OK) printf("Dir was created: %s\n", path); else printf("Dir was not created: %s\n", path); ``` ``` -------------------------------- ### mz_os_open_dir Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Opens a directory for listing its contents. Returns a handle for enumeration. ```APIDOC ## mz_os_open_dir ### Description Opens a directory for listing. ### Parameters #### Path Parameters - **path** (const char *) - Directory path ### Return - **DIR *** - Directory enumeration handle, returns NULL if error. ### Example ```c const char *search_dir = "c:\\test1\\"; DIR *dir = mz_open_dir(search_dir); if (dir) { printf("Dir %s was opened\n", search_dir); mz_os_close_dir(dir); } ``` ``` -------------------------------- ### Get MZ_ZIP Global Comment Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves the global comment string associated with a zip file. Use this to read the comment if it exists. ```c const char *global_comment = NULL; if (mz_zip_get_comment(zip_handle, &global_comment) == MZ_OK) printf("Zip file global comment: %s\n", global_comment); else printf("Zip file does not contain a global comment\n"); ``` -------------------------------- ### mz_zip_goto_first_entry Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Navigates to the first entry in the zip file. Returns MZ_OK on success or MZ_END_OF_LIST if no entries are present. ```APIDOC ## mz_zip_goto_first_entry ### Description Go to the first entry in the zip file. ### Method N/A (C function) ### Parameters #### Arguments - **handle** (void *) - _mz_zip_ instance ### Return - **int32_t** - [MZ_ERROR](mz_error.md) code, MZ_OK if successful, MZ_END_OF_LIST if no more entries. ### Example ```c int32_t err = mz_zip_goto_first_entry(zip_handle); if (err == MZ_OK) { mz_zip_file *file_info = NULL; err = mz_zip_entry_get_info(zip_handle, &file_info); if (err == MZ_OK) { printf("First entry is %s\n", file_info->filename); } } ``` ``` -------------------------------- ### Get Central Directory Disk Number Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves the disk number containing the central directory. The retrieved number is stored in the provided pointer. ```c uint32_t disk_number_with_cd = 0; // TODO: Open zip file if (mz_zip_get_disk_number_with_cd(zip_handle, &disk_number_with_cd) == MZ_OK) printf("Disk number containing cd: %d\n", disk_number_with_cd); ``` -------------------------------- ### Unzipping from a Memory Buffer Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Demonstrates how to open and read from a zip archive stored in memory using a memory stream. Ensure the zip_buffer is populated before use. ```c uint8_t *zip_buffer = NULL; int32_t zip_buffer_size = 0; void *mem_stream = NULL; void *zip_handle = NULL; /* TODO: fill zip_buffer with zip contents.. */ mem_stream = mz_stream_mem_create(); mz_stream_mem_set_buffer(mem_stream, zip_buffer, zip_buffer_size); mz_stream_open(mem_stream, NULL, MZ_OPEN_MODE_READ); zip_handle = mz_zip_create(); err = mz_zip_open(zip_handle, mem_stream, MZ_OPEN_MODE_READ); /* TODO: unzip operations.. */ mz_zip_close(zip_handle); mz_zip_delete(&zip_handle); mz_stream_mem_delete(&mem_stream); ``` -------------------------------- ### Set Follow Symbolic Links Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Determines whether symbolic links should be followed when traversing directories and files to be added to the zip archive. Set 'follow_links' to 1 to enable following links. ```c mz_zip_writer_set_follow_links(zip_writer, 1); ``` -------------------------------- ### Get Current Zip Entry Offset Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves the byte position of the current entry within the zip file. Returns MZ_ERROR if an issue occurs. ```c int32_t err = mz_zip_goto_first_entry(zip_handle); if (err == MZ_OK) { int64_t entry_offset = mz_zip_get_entry(zip_handle); if (entry_offset >= 0) { printf("Entry offset %lld\n", entry_offset); } } ``` -------------------------------- ### Get Number of Entries from mz_zip Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieve the total number of entries in an opened zip file using mz_zip_get_number_entry. The result is stored in the provided pointer. ```c uint64_t number_entry = 0; // TODO: Open zip file if (mz_zip_get_number_entry(zip_handle, &number_entry) == MZ_OK) printf("Total number of entries in zip file %d\n", number_entry); ``` -------------------------------- ### Create Zip Writer Instance Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Allocates and initializes a new mz_zip_writer instance. This function must be called before using other mz_zip_writer functions. ```c void *zip_writer = mz_zip_writer_create(); ``` -------------------------------- ### Iterate Through Zip Entries Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Iterates through all entries in a zip file, starting from the first. Prints the filename of each entry. Returns MZ_OK for each entry and MZ_END_OF_LIST when finished. ```c int32_t i = 0; int32_t err = mz_zip_goto_first_entry(zip_handle); while (err == MZ_OK) { mz_zip_file *file_info = NULL; err = mz_zip_entry_get_info(zip_handle, &file_info); if (err != MZ_OK) { printf("Failed to get entry %d info\n", i); break; } printf("Entry %d is %s\n", i, file_info->filename); err = mz_zip_goto_next_entry(zip_handle); } ``` -------------------------------- ### Configure LibLZMA Support Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt This snippet configures support for the LibLZMA library. It checks if LibLZMA is found or fetches it if enabled. It appends necessary include directories, dependencies, and definitions for LZMA compression. ```cmake if(NOT MZ_FORCE_FETCH_LIBS) find_package(LibLZMA QUIET) endif() if(LIBLZMA_FOUND AND NOT MZ_FORCE_FETCH_LIBS) message(STATUS "Using LZMA ${LIBLZMA_VERSION_STRING}") list(APPEND MINIZIP_LIB LibLZMA::LibLZMA) set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -llzma") elseif(MZ_FETCH_LIBS) set(BUILD_TESTING OFF CACHE BOOL "Build lzma tests" FORCE) clone_repo(liblzma https://github.com/tukaani-project/xz master) list(APPEND MINIZIP_INC ${LIBLZMA_SOURCE_DIR}/src/liblzma/api) list(APPEND MINIZIP_DEP liblzma) # liblzma's exported target references Threads::Threads list(APPEND MINIZIP_DEP_PKG Threads) else() message(STATUS "LibLZMA library not found") set(MZ_LZMA OFF) endif() if(MZ_LZMA) if(LIBLZMA_FOUND) list(APPEND MINIZIP_DEP_PKG LibLZMA) endif() list(APPEND MINIZIP_DEF -DHAVE_LZMA -DLZMA_API_STATIC) list(APPEND MINIZIP_SRC mz_strm_lzma.c) list(APPEND MINIZIP_HDR mz_strm_lzma.h) endif() endif() ``` -------------------------------- ### Get Underlying Zip Handle Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Retrieves the internal zip instance handle from a zip writer. This can be useful for advanced operations or when interacting with lower-level zip functions. ```c void *zip_handle = NULL; mz_zip_writer_get_zip_handle(zip_writer, &zip_handle); ``` -------------------------------- ### mz_os_make_symlink Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Creates a symbolic link pointing to a specified target path. ```APIDOC ## mz_os_make_symlink ### Description Creates a symbolic link pointing to a target. ### Arguments #### Path Parameters - **path** (const char *) - Required - Link path - **target_path** (const char *) - Required - Actual path ### Return - **int32_t** - [MZ_ERROR](mz_error.md) code, MZ_OK if successful ### Example ```c const char *path = "c:\\test7.txt"; const char *target_path = "c:\\test8.txt"; if (mz_os_make_symlink(path, target_path) == MZ_OK) printf("Symbolic link created at %s pointing to %s\n", path, target_path); ``` ``` -------------------------------- ### Open Directory Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Opens a directory to allow for listing its contents. Returns a handle that must be closed with `mz_os_close_dir`. ```c const char *search_dir = "c:\\test1\\"; DIR *dir = mz_open_dir(search_dir); if (dir) { printf("Dir %s was opened\n", search_dir); mz_os_close_dir(dir); } ``` -------------------------------- ### Go to First Zip Entry Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Navigates the zip reader to the first entry within the archive. If a pattern is set, it finds the first entry matching that pattern. Requires a valid zip reader instance. ```c mz_zip_file *file_info = NULL; if ((mz_zip_reader_goto_first_entry(zip_reader) == MZ_OK) && (mz_zip_reader_entry_get_info(zip_reader, &file_info) == MZ_OK)) { printf("Zip first entry %s\n", file_info->filename); } ``` -------------------------------- ### Get Follow Symbolic Links Status Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Retrieves the current setting for following symbolic links. The status is stored in the provided 'follow_links' pointer. Returns MZ_OK on success. ```c uint8_t follow = 0; mz_zip_writer_get_follow_links(zip_writer, &follow); printf("Following symbolic links: %s\n", (follow) ? "yes" : "no"); ``` -------------------------------- ### mz_zip_reader_create Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Creates a mz_zip_reader instance and returns its pointer. ```APIDOC ## mz_zip_reader_create ### Description Creates a _mz_zip_reader_ instance and returns its pointer. ### Method Not applicable (C function) ### Parameters None ### Return - **void *** - Pointer to the _mz_zip_reader_ instance ### Example ```c void *zip_reader = mz_zip_reader_create(); ``` ``` -------------------------------- ### Get Central Directory Entry Info Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves central directory file information for the current zip entry. The returned pointer is only valid while the entry remains current. ```c int32_t err = mz_zip_goto_first_entry(zip_handle); if (err == MZ_OK) { mz_zip_file *file_info = NULL; err = mz_zip_entry_get_info(zip_handle, &file_info); if (err == MZ_OK) { printf("Central directory entry filename: %s\n", file_info->filename); } } ``` -------------------------------- ### Get Compression Stream for Zip Entry Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieves a pointer to the compression stream for the current zip entry, allowing access to compressed bytes. Returns MZ_OK on success. ```c int32_t err = mz_zip_goto_first_entry(zip_handle); if (err == MZ_OK) err = mz_zip_entry_seek_local_header(zip_handle); if (err == MZ_OK) { void *stream = NULL; mz_zip_get_stream(zip_handle, &stream); int64_t position = mz_stream_tell(stream); printf("Position of local header of first entry: %lld\n", position); } ``` -------------------------------- ### Copy Random Binary for Compression Tests Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Copies a 'random.bin' file to the test temporary directory. This is a prerequisite for the 'gz' and 'ungz' tests. ```cmake file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/test/random.bin DESTINATION ${TEST_TEMP_DIR}) ``` -------------------------------- ### Create a Disk Splitting Archive Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/README.md Use the disk splitting stream to create an archive with a specified disk size. This is useful for archives that need to span across multiple physical or logical disks. ```c void *stream = NULL; void *split_stream = NULL; void *zip_handle = NULL; stream = mz_stream_os_create(); split_stream = mz_stream_split_create(); mz_stream_split_set_prop_int64(split_stream, MZ_STREAM_PROP_DISK_SIZE, 64 * 1024); mz_stream_set_base(split_stream, stream); mz_stream_open(split_stream, path.. zip_handle = mz_zip_create(); err = mz_zip_open(zip_handle, split_stream, MZ_OPEN_MODE_WRITE); /* TODO: unzip operation.. */ mz_zip_close(zip_handle); mz_zip_delete(&zip_handle); mz_stream_buffered_delete(&split_stream); ``` -------------------------------- ### Add minigzip CLI Executable Source: https://github.com/zlib-ng/minizip-ng/blob/develop/CMakeLists.txt Adds the minigzip command-line interface executable. This is conditionally compiled if MZ_ZLIB is enabled and MZ_LIBCOMP is not. It links against the minizip target and is installed to the binary directory if not skipped. ```cmake add_executable(minigzip_cli minigzip.c) set_target_properties(minigzip_cli PROPERTIES OUTPUT_NAME minigzip) target_compile_definitions(minigzip_cli PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) target_link_libraries(minigzip_cli ${MINIZIP_TARGET}) if(NOT SKIP_INSTALL_BINARIES AND NOT SKIP_INSTALL_ALL) install(TARGETS minigzip_cli RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() ``` -------------------------------- ### Set Compression Method Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Specifies the compression method to be used when adding entries to the zip archive. Use MZ_COMPRESS_METHOD_STORE for no compression. ```c mz_zip_writer_set_compress_method(zip_writer, MZ_COMPRESS_METHOD_STORE); ``` -------------------------------- ### Get Zip Reader Zipped Central Directory Status Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip_rw.md Checks if the archive's central directory is zipped. This can be useful for understanding the archive's structure and optimizing read operations. ```c uint8_t zip_cd = 0; mz_zip_reader_get_zip_cd(zip_reader, &zip_cd); printf("Central directory %s zipped\n", (zip_cd) ? "is" : "is not"); ``` -------------------------------- ### Create Minizip-ng Test Executable Source: https://github.com/zlib-ng/minizip-ng/blob/develop/test/CMakeLists.txt Builds the 'gtest_minizip' executable using the defined test sources and links it against the minizip library and Google Test. ```cmake add_executable(gtest_minizip test_main.cc ${TEST_SRCS}) target_compile_definitions(gtest_minizip PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF}) target_include_directories(gtest_minizip PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR}) target_link_libraries(gtest_minizip MINIZIP::minizip GTest::GTest) ``` -------------------------------- ### mz_os_set_file_attribs Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_os.md Sets the attributes of a file. ```APIDOC ## mz_os_set_file_attribs ### Description Sets a file's attributes. ### Parameters #### Path Parameters - **path** (const char *) - File path #### Input Parameters - **attributes** (uint32_t) - File attributes value ### Return - **int32_t** - [MZ_ERROR](mz_error.md) code, MZ_OK if successful ### Example ```c const char *path = "c:\\test6.txt"; uint32_t attributes = 0; if (mz_os_get_file_attribs(path, &attributes) == MZ_OK) { printf("File %s attributes %08x\n", attributes); attributes |= FILE_ATTRIBUTE_READONLY; if (mz_os_set_file_attribs(path, attributes) == MZ_OK) { printf("File changed to readonly\n"); } } ``` ``` -------------------------------- ### Get mz_stream Handle from mz_zip Instance Source: https://github.com/zlib-ng/minizip-ng/blob/develop/doc/mz_zip.md Retrieve the mz_stream handle associated with a mz_zip instance using mz_zip_get_stream. This is useful when the stream needs to be accessed directly after opening the zip file. ```c void *zip_handle = mz_zip_create(); if (mz_zip_open(zip_handle, stream_handle, MZ_OPEN_MODE_READ) == MZ_OK) { void *stream2_handle = NULL; mz_zip_get_stream(zip_handle, &stream2_handle); assert(stream_handle == stream2_handle); } ```