Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decompress one or more text files from zip with minizip #24

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Declare files that will always have CRLF line endings on checkout.
# This is needed for the unit tests to pass when unzipping files.
Benchmark/Files/SmallBasicTextFileZip/SmallBasicTextFile.txt text eol=crlf

Benchmark/Files/MultiTextFileZip/TextFileOne.txt text eol=crlf
Benchmark/Files/MultiTextFileZip/TextFileTwo.txt text eol=crlf
Benchmark/Files/MultiTextFileZip/ThirdTextFile.txt text eol=crlf

Benchmark/Files/MultiTextFileAndSubDirZip/DirFileOne/TextFileOne.txt text eol=crlf
Benchmark/Files/MultiTextFileAndSubDirZip/TextFile.txt text eol=crlf
Benchmark/Files/MultiTextFileAndSubDirZip/DirOfDirs/OtherDir/DummyFile.txt text eol=crlf
Benchmark/Files/MultiTextFileAndSubDirZip/DirOfDirs/OtherDir/FilleInDirectory.txt text eol=crlf
Benchmark/Files/MultiTextFileAndSubDirZip/DirOfDirs/SubDirWithCopyOfTopLevelFile/TextFile.txt text eol=crlf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ main.exe
Benchmark*.txt*
Benchmark/Files/*.compressed.*
Benchmark/Files/*.decompressed.*
Benchmark/Files/*.zipped.*
Benchmark/Files/*.unzipped.*

# Test generated files
Test*.txt*
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "External/zlib"]
path = External/zlib
url = https://github.com/madler/zlib.git
[submodule "External/minizip-ng"]
path = External/minizip-ng
url = https://github.com/zlib-ng/minizip-ng
26 changes: 26 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,31 @@
"unistd.h": "c",
"bitset": "c",
"ftw.h": "c"
"zip_minizip.h": "c",
"unzip.h": "c",
"unzip_minizip.h": "c",
"testzipunzipminizip.h": "c",
"unity_fixture.h": "c",
"testdeflateinflatezlib.h": "c",
"cstdlib": "c",
"rope": "c",
"*.def": "c",
"testunzipminizip.h": "c",
"unity_fixture_internals.h": "c",
"unity_memory.h": "c",
"string_view": "c",
"regex": "c",
"*.inc": "c",
"zipcontentinfo.h": "c",
"iunzip.h": "c",
"typeindex": "c",
"chrono": "c",
"typeinfo": "c",
"ioapi.h": "c",
"stdlib.h": "c",
"stat.h": "c",
"types.h": "c",
"unistd.h": "c",
"dirent.h": "c"
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is
the first text file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some dummy file with empty second line
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is in a directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The 3rd file contains

an empty line on line 2.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions Benchmark/Files/MultiTextFileAndSubDirZip/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The zip file has been created with the build in compressions option from the Windows 11 Pro 23H2 file explorer.

1. Select the files to zip.
2. Right-click > "Compress to..." > "Additional options"
3. For the `*_store.zip` file:
- Archive format: `ZIP`
- Compression method: `Store`
- Retain symbolic links: `checked` (this is the default)
4. For the `*_deflate.zip` file:
- Archive format: `ZIP`
- Compression method: `Deflate`
- Compression level: `6` (this is the default)
- Retain symbolic links: `checked` (this is the default)


3 changes: 3 additions & 0 deletions Benchmark/Files/MultiTextFileAndSubDirZip/TextFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The 3rd file contains

an empty line on line 2.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions Benchmark/Files/MultiTextFileZip/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The zip file has been created with the build in compressions option from the Windows 11 Pro 23H2 file explorer.

1. Select the files to zip.
2. Right-click > "Compress to..." > "Additional options"
3. For the `*_store.zip` file:
- Archive format: `ZIP`
- Compression method: `Store`
- Retain symbolic links: `checked` (this is the default)
4. For the `*_deflate.zip` file:
- Archive format: `ZIP`
- Compression method: `Deflate`
- Compression level: `6` (this is the default)
- Retain symbolic links: `checked` (this is the default)


2 changes: 2 additions & 0 deletions Benchmark/Files/MultiTextFileZip/TextFileOne.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is
the first text file.
2 changes: 2 additions & 0 deletions Benchmark/Files/MultiTextFileZip/TextFileTwo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Second file is this
.
3 changes: 3 additions & 0 deletions Benchmark/Files/MultiTextFileZip/ThirdTextFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The 3rd file contains

an empty line on line 2.
1 change: 1 addition & 0 deletions Benchmark/Files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All these files are created on windows. Meaning that by default they end in `\r\n` rather than `\n`. This is important when testing that unzipped files are identical as the original.
15 changes: 15 additions & 0 deletions Benchmark/Files/SmallBasicTextFileZip/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The zip file has been created with the build in compressions option from the Windows 11 Pro 23H2 file explorer.

1. Select the files to zip.
2. Right-click > "Compress to..." > "Additional options"
3. For the `*_store.zip` file:
- Archive format: `ZIP`
- Compression method: `Store`
- Retain symbolic links: `checked` (this is the default)
4. For the `*_deflate.zip` file:
- Archive format: `ZIP`
- Compression method: `Deflate`
- Compression level: `6` (this is the default)
- Retain symbolic links: `checked` (this is the default)


4 changes: 4 additions & 0 deletions Benchmark/Files/SmallBasicTextFileZip/SmallBasicTextFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is a test file.
On the second line there are eight words
The third line has a tab.
And the last line is a longer piece. Consising of two sentences.
Binary file not shown.
Binary file not shown.
5 changes: 4 additions & 1 deletion CoDeLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ set(CoDeLib_PUBLIC_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include/CoDeLib)
set(COMMON_HEADERS
${CoDeLib_PUBLIC_INCLUDE_PATH}/IDeflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IInflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IUnZip.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(RaiiString)
add_subdirectory(ZipContentInfo)
add_subdirectory(Test)

install(
TARGETS CoDeLib Deflate_zlib Inflate_zlib RaiiString FileUtils
TARGETS CoDeLib Deflate_zlib Inflate_zlib UnZip_minizip RaiiString ZipContentInfo FileUtils
EXPORT CoDeLibTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
4 changes: 3 additions & 1 deletion CoDeLib/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ check_required_components(CoDeLib)
include(CMakeFindDependencyMacro)

set(ZLIB_USE_STATIC_LIBS "ON")
find_dependency(ZLIB REQUIRED)
find_dependency(ZLIB REQUIRED)

find_dependency(minizip REQUIRED)
3 changes: 2 additions & 1 deletion CoDeLib/CustomDeflate.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

# refs

- https://pnrsolution.org/Datacenter/Vol4/Issue1/58.pdf
- https://pnrsolution.org/Datacenter/Vol4/Issue1/58.pdf
- https://nachtimwald.com/2019/09/08/making-minizip-easier-to-use/
1 change: 0 additions & 1 deletion CoDeLib/Deflate_zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(ZLIB_USE_STATIC_LIBS "ON")
find_package(ZLIB REQUIRED)
target_link_libraries(Deflate_zlib PRIVATE ZLIB::ZLIB)

message(STATUS "CoDeLib_PUBLIC_INCLUDE_PATH: ${CoDeLib_PUBLIC_INCLUDE_PATH}")
set(Deflate_zlib_PUBLIC_INCLUDE_PATH ${CoDeLib_PUBLIC_INCLUDE_PATH}/Deflate_zlib)
set(Deflate_zlib_PUBLIC_HEADERS
${Deflate_zlib_PUBLIC_INCLUDE_PATH}/Deflate_zlib.h
Expand Down
10 changes: 10 additions & 0 deletions CoDeLib/FileUtils/src/FileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ bool FilesAreEqual(FILE *pFile1, FILE *pFile2) {
const size_t fileSize2 = GetFileSizeInBytes(pFile2);

if (fileSize1 != fileSize2) {
printf("File sizes not equal:\n");
printf(" fileSize1: %lu\n", (unsigned long)fileSize1);
printf(" fileSize2: %lu\n", (unsigned long)fileSize2);
return false;
}

Expand All @@ -306,6 +309,9 @@ bool FilesAreEqual(FILE *pFile1, FILE *pFile2) {
bytesRead2 = fread(buffer2, 1, bufferSize, pFile2);

if (bytesRead1 != bytesRead2) {
printf("Bytes read not equal:\n");
printf(" bytesRead1: %lu\n", (unsigned long)bytesRead1);
printf(" bytesRead2: %lu\n", (unsigned long)bytesRead2);
return false;
}

Expand All @@ -315,12 +321,16 @@ bool FilesAreEqual(FILE *pFile1, FILE *pFile2) {
const int errorFile2 = ferror(pFile2);
if ((eofFile1 && !eofFile2) || (!eofFile1 && eofFile2)) {
printf("EOF indicator set only by one file\n");
return false;
} else if ((!eofFile1 && errorFile1) || (!eofFile2 && errorFile2)) {
printf("Error indicator set");
return false;
}

if (memcmp(buffer1, buffer2, bytesRead1) != 0) {
printf("Buffers not equal\n");
printf(" buffer1: %s\n", buffer1);
printf(" buffer2: %s\n", buffer2);
return false;
}
} while (bytesRead1 > 0);
Expand Down
21 changes: 15 additions & 6 deletions CoDeLib/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ add_executable(CoDeLib_Test
src/main.c
src/TestRaiiString.c
src/TestDeflateInflateZlib.c
src/TestFileUtils.c)
src/TestFileUtils.c
src/TestUnZipMinizip.c
src/TestUnZipMinizipInflateZlib.c
src/TestZipContentInfo.c
)

target_include_directories(CoDeLib_Test PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
)

target_link_libraries(CoDeLib_Test PRIVATE Deflate_zlib)
target_link_libraries(CoDeLib_Test PRIVATE Inflate_zlib)
target_link_libraries(CoDeLib_Test PRIVATE RaiiString)
target_link_libraries(CoDeLib_Test PRIVATE FileUtils)

FetchContent_Declare(
Unity
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
Expand All @@ -23,4 +22,14 @@ FetchContent_Declare(
# If cache is not used, you will get `Policy CMP0077 is not set: option() honors normal variables.`
set(UNITY_EXTENSION_FIXTURE ON CACHE INTERNAL "")
FetchContent_MakeAvailable(Unity)

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 RaiiString)
target_link_libraries(CoDeLib_Test PRIVATE ZipContentInfo)

target_link_libraries(CoDeLib_Test PRIVATE unity)


Loading