Compare commits
321 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c30a001bc | ||
|
|
8980137de6 | ||
|
|
4d99a8f7c2 | ||
|
|
13c4e52c91 | ||
|
|
d9be48fbe6 | ||
|
|
3a404922aa | ||
|
|
e680017bae | ||
|
|
2fa13ca8a3 | ||
|
|
0f4cbb8c27 | ||
|
|
efbf3935b1 | ||
|
|
35528ad769 | ||
|
|
189f56edaa | ||
|
|
11e7c39508 | ||
|
|
1ff82be7d6 | ||
|
|
8e8e609e02 | ||
|
|
bf7a1f0a5a | ||
|
|
4000bc3a87 | ||
|
|
200c9053d0 | ||
|
|
8573fd7cd6 | ||
|
|
961de84cbb | ||
|
|
0283a1796e | ||
|
|
3c46a05141 | ||
|
|
43bc679d05 | ||
|
|
8714fd3cd8 | ||
|
|
60ec4a72b9 | ||
|
|
3cc84f4f0c | ||
|
|
2552e6d45a | ||
|
|
622aea128a | ||
|
|
16413c213d | ||
|
|
a77af68d92 | ||
|
|
e5700656b3 | ||
|
|
4d6f89cb0a | ||
|
|
f8a09fe199 | ||
|
|
6cfbb0d1d8 | ||
|
|
fa8ef4584b | ||
|
|
039b1d2962 | ||
|
|
32bb60d989 | ||
|
|
05ab4dc05c | ||
|
|
697f010d70 | ||
|
|
bd9e22f577 | ||
|
|
9aef68479f | ||
|
|
69763e8811 | ||
|
|
18795fa61e | ||
|
|
96b0c0fc64 | ||
|
|
acfba6a21d | ||
|
|
93ded54847 | ||
|
|
a23a38bf53 | ||
|
|
d0190e5cdf | ||
|
|
90a5b2f89b | ||
|
|
6f09a0f0b5 | ||
|
|
fd55960854 | ||
|
|
b0af33a61b | ||
|
|
9ae305f6e1 | ||
|
|
d9d197c926 | ||
|
|
654bf8bdeb | ||
|
|
fe6330e1d8 | ||
|
|
f259216256 | ||
|
|
f0709ed3f5 | ||
|
|
293d4db1b7 | ||
|
|
12680974d1 | ||
|
|
ad8dedc1b3 | ||
|
|
08c03ff478 | ||
|
|
2ec92b4852 | ||
|
|
78e9404362 | ||
|
|
963a27a112 | ||
|
|
2363190ebf | ||
|
|
7265019066 | ||
|
|
83341a5605 | ||
|
|
39622ead92 | ||
|
|
ab052e6e58 | ||
|
|
39f65158c7 | ||
|
|
ca0cdfc52d | ||
|
|
7b9bcf7f94 | ||
|
|
92ab73ac32 | ||
|
|
78ef92043c | ||
|
|
11f77193b7 | ||
|
|
4a8dc21d9d | ||
|
|
725b8df44c | ||
|
|
8cdf426109 | ||
|
|
680454c21e | ||
|
|
a203b9a0d4 | ||
|
|
d4ad2bf51e | ||
|
|
be92575500 | ||
|
|
a2b5326d86 | ||
|
|
de0a4d2444 | ||
|
|
482c77e661 | ||
|
|
37ea28133d | ||
|
|
9cd715b3b1 | ||
|
|
a9d7f80cc6 | ||
|
|
8db69b6b59 | ||
|
|
c610f58a57 | ||
|
|
e1e7f70e59 | ||
|
|
76b3a87285 | ||
|
|
5c9c89509c | ||
|
|
719967dc82 | ||
|
|
18bc504331 | ||
|
|
144c351f34 | ||
|
|
bc77ea1017 | ||
|
|
7c459c8a05 | ||
|
|
118b2e3d34 | ||
|
|
e7d0e216d5 | ||
|
|
5a38f5564a | ||
|
|
9eedb97176 | ||
|
|
8a7cf60c7a | ||
|
|
d9bd65a843 | ||
|
|
71ba5d12d6 | ||
|
|
e285002431 | ||
|
|
cd1dc96d27 | ||
|
|
5245b1c52f | ||
|
|
842a20e586 | ||
|
|
edc251cfa9 | ||
|
|
9ffbe56a73 | ||
|
|
f2b59b344d | ||
|
|
0ce345c44a | ||
|
|
0796bdbee6 | ||
|
|
056cc8db14 | ||
|
|
60942b0f04 | ||
|
|
8997650f5c | ||
|
|
698faddd95 | ||
|
|
ff862d4596 | ||
|
|
740049e643 | ||
|
|
2cd06e3f32 | ||
|
|
f3d9e2293b | ||
|
|
1541a11e9b | ||
|
|
501a761549 | ||
|
|
aa70ef1644 | ||
|
|
13b21dddc7 | ||
|
|
a956b4c753 | ||
|
|
ecbbbe0138 | ||
|
|
72e7267054 | ||
|
|
12b78b6d5a | ||
|
|
2beb69d0a5 | ||
|
|
0a88083589 | ||
|
|
3e5e488ba9 | ||
|
|
75c948a1dd | ||
|
|
b4108c6fcf | ||
|
|
e6a7c5daed | ||
|
|
66c7313326 | ||
|
|
82d6810a38 | ||
|
|
ee4deb08fa | ||
|
|
cb2b132b86 | ||
|
|
591faa9574 | ||
|
|
3a387ec369 | ||
|
|
cda0b3e7f0 | ||
|
|
e841503cad | ||
|
|
a7961f5b4c | ||
|
|
ca1a779ee1 | ||
|
|
18da352921 | ||
|
|
d9c899cea4 | ||
|
|
70c79cc9d5 | ||
|
|
583f4f27c2 | ||
|
|
9b89689723 | ||
|
|
f99eae6e04 | ||
|
|
fc0c0f585e | ||
|
|
78ae375016 | ||
|
|
f542e6df73 | ||
|
|
46347635c8 | ||
|
|
c0aad72d46 | ||
|
|
08f2c2d7e3 | ||
|
|
cb97387d20 | ||
|
|
d301afc498 | ||
|
|
8ac52a6cae | ||
|
|
2281a42c77 | ||
|
|
17b4f33dde | ||
|
|
f2df122f6f | ||
|
|
6e1754595a | ||
|
|
0c905aec41 | ||
|
|
ee598099cb | ||
|
|
61b202f26a | ||
|
|
a145b53b6a | ||
|
|
58254a3241 | ||
|
|
cf2833fdc1 | ||
|
|
57176046b5 | ||
|
|
9edb278d22 | ||
|
|
b7f04b700b | ||
|
|
75744d32d4 | ||
|
|
b43f8a0c22 | ||
|
|
17d6763721 | ||
|
|
31b389ac61 | ||
|
|
fe03be2c51 | ||
|
|
60bbf6c808 | ||
|
|
b99e5c3de3 | ||
|
|
d6566206ce | ||
|
|
6241bc718c | ||
|
|
6b6b27aff2 | ||
|
|
3a43b8c4bb | ||
|
|
864ecc8d14 | ||
|
|
f52e09a208 | ||
|
|
95795bb996 | ||
|
|
0bac8947c5 | ||
|
|
90ff5d51e4 | ||
|
|
fe4a8b78f3 | ||
|
|
225354290d | ||
|
|
b485d01faf | ||
|
|
1cdb9afad0 | ||
|
|
cd65995953 | ||
|
|
1721df91bb | ||
|
|
d1640e7c4f | ||
|
|
9457abb670 | ||
|
|
8410f3c640 | ||
|
|
209ba6540c | ||
|
|
1e7621d96c | ||
|
|
5ebed82882 | ||
|
|
e6faac9881 | ||
|
|
65ad3cdf66 | ||
|
|
320764e3ca | ||
|
|
d34ae4a14f | ||
|
|
aa3c99a7b4 | ||
|
|
f33da29f61 | ||
|
|
b36e55e48d | ||
|
|
797c58be3c | ||
|
|
d2d7d090fa | ||
|
|
436d915546 | ||
|
|
49860a15fa | ||
|
|
524906517d | ||
|
|
3d000933a7 | ||
|
|
40b0612004 | ||
|
|
8da3cbb64e | ||
|
|
164c81c7d7 | ||
|
|
a8e9424b16 | ||
|
|
fa09b1f3d4 | ||
|
|
4159f8c8c3 | ||
|
|
ccff20b76d | ||
|
|
1e8c7ce810 | ||
|
|
e48d8bab88 | ||
|
|
a828cc329c | ||
|
|
1567c8d06c | ||
|
|
a88d1571c1 | ||
|
|
f66b3e1901 | ||
|
|
5108f95f58 | ||
|
|
3a00ea8b73 | ||
|
|
a0dd5179db | ||
|
|
107def8e36 | ||
|
|
334e0d64ce | ||
|
|
0238ce2a3b | ||
|
|
cd99affed0 | ||
|
|
bee490c712 | ||
|
|
6ed35304fe | ||
|
|
e0c964c4a3 | ||
|
|
416f5ea723 | ||
|
|
e8ab1c9a6d | ||
|
|
e71344bdd7 | ||
|
|
3b9a004a4f | ||
|
|
d57872c77a | ||
|
|
b713ca2b4a | ||
|
|
185bc3c683 | ||
|
|
ff06fbaafc | ||
|
|
1261dfa9ad | ||
|
|
ea41268ac9 | ||
|
|
c3e5de6699 | ||
|
|
a3aeeb3307 | ||
|
|
4ec19d6731 | ||
|
|
a4264837ae | ||
|
|
b4936524bc | ||
|
|
e9020723b3 | ||
|
|
5ba89c135d | ||
|
|
25de35faec | ||
|
|
4d1d5b6771 | ||
|
|
034f0228eb | ||
|
|
4b8c4f432c | ||
|
|
9d79ea2245 | ||
|
|
6db3c0d290 | ||
|
|
96f0da1db9 | ||
|
|
93c6567773 | ||
|
|
2b45f89867 | ||
|
|
5c62e23e04 | ||
|
|
f3461d636a | ||
|
|
45a080c050 | ||
|
|
2e15a3ff77 | ||
|
|
d31e119d4d | ||
|
|
3a884afaa7 | ||
|
|
ae423e65b4 | ||
|
|
336fca3bd4 | ||
|
|
a3ca94f833 | ||
|
|
9ce0d0ddff | ||
|
|
f8600923fc | ||
|
|
306edd2022 | ||
|
|
407d298c14 | ||
|
|
53bfef515c | ||
|
|
91fa285a27 | ||
|
|
df65d5a1de | ||
|
|
46cdde2ac5 | ||
|
|
3616bf804b | ||
|
|
76237898c0 | ||
|
|
3af5c82fd3 | ||
|
|
55f4dfe1d2 | ||
|
|
b344eaf775 | ||
|
|
36b6c99f62 | ||
|
|
04f2169b8a | ||
|
|
14a5a1397b | ||
|
|
fef12d34f1 | ||
|
|
b01930542e | ||
|
|
9c88e826a2 | ||
|
|
22e4ef1b1d | ||
|
|
7a7d0b423b | ||
|
|
c17cc20c80 | ||
|
|
0f6b199e5b | ||
|
|
0b7d3070b9 | ||
|
|
aadc405b1c | ||
|
|
02c51d3662 | ||
|
|
9393a95f26 | ||
|
|
82e5b184e4 | ||
|
|
81df2df0f6 | ||
|
|
64d92e19ad | ||
|
|
404c574eba | ||
|
|
c1f791f81b | ||
|
|
c93e4d804c | ||
|
|
84e8458de0 | ||
|
|
78cdcb0fce | ||
|
|
0d13890f4b | ||
|
|
7ecd1b3677 | ||
|
|
a0786b126d | ||
|
|
9b1ddf6861 | ||
|
|
149b34c254 | ||
|
|
6e915ef7fc | ||
|
|
11f795a19c | ||
|
|
ec028ffe66 | ||
|
|
a6a989cc18 | ||
|
|
3d51050db5 | ||
|
|
3c7177c0cb | ||
|
|
35c2d67bcf |
@ -44,3 +44,4 @@ SpacesInCStyleCastParentheses: false
|
||||
SpaceAfterControlStatementKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
ContinuationIndentWidth: 4
|
||||
SortIncludes: false
|
||||
41
.github/workflows/c-cpp.yml
vendored
Normal file
41
.github/workflows/c-cpp.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
name: C/C++ CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: amalgamate
|
||||
run: bash amalgamate.sh
|
||||
- name: Run CMake consuming CMakePreset.json and run tests
|
||||
uses: lukka/run-cmake@v10
|
||||
with:
|
||||
# This is the name of the CMakePresets.json's configuration to use to generate
|
||||
# the project files. This configuration leverages the vcpkg.cmake toolchain file to
|
||||
# run vcpkg and install all dependencies specified in vcpkg.json.
|
||||
configurePreset: 'gcc'
|
||||
# Additional arguments can be appended to the cmake command.
|
||||
# This is useful to reduce the number of CMake's Presets since you can reuse
|
||||
# an existing preset with different variables.
|
||||
configurePresetAdditionalArgs: "['-DENABLE_YOUR_FEATURE=1']"
|
||||
# This is the name of the CMakePresets.json's configuration to build the project.
|
||||
buildPreset: 'gcc'
|
||||
# Additional arguments can be appended when building, for example to specify the
|
||||
# configuration to build.
|
||||
# This is useful to reduce the number of CMake's Presets you need in CMakePresets.json.
|
||||
buildPresetAdditionalArgs: "['--config Release']"
|
||||
|
||||
# This is the name of the CMakePresets.json's configuration to test the project with.
|
||||
testPreset: 'gcc'
|
||||
# Additional arguments can be appended when testing, for example to specify the config
|
||||
# to test.
|
||||
# This is useful to reduce the number of CMake's Presets you need in CMakePresets.json.
|
||||
testPresetAdditionalArgs: "[]"
|
||||
23
.github/workflows/ci-fuzz.yml
vendored
Normal file
23
.github/workflows/ci-fuzz.yml
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
name: CIFuzz
|
||||
on: [pull_request]
|
||||
jobs:
|
||||
Fuzzing:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Build Fuzzers
|
||||
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||
with:
|
||||
oss-fuzz-project-name: 'miniz'
|
||||
dry-run: false
|
||||
- name: Run Fuzzers
|
||||
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||
with:
|
||||
oss-fuzz-project-name: 'miniz'
|
||||
fuzz-seconds: 900
|
||||
dry-run: false
|
||||
- name: Upload Crash
|
||||
uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: artifacts
|
||||
path: ./out/artifacts
|
||||
60
.github/workflows/release.yml
vendored
Normal file
60
.github/workflows/release.yml
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
name: Create release
|
||||
|
||||
# Controls when the action will run.
|
||||
on:
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Create new release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: source
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get install -y cmake
|
||||
|
||||
- name: Configure
|
||||
run: |
|
||||
mkdir build
|
||||
mkdir inst
|
||||
cd build
|
||||
cmake ../source -G"Unix Makefiles" -DAMALGAMATE_SOURCES=ON -DCMAKE_INSTALL_PREFIX=../inst
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
cd build
|
||||
make install
|
||||
|
||||
- name: Get current version
|
||||
id: relver
|
||||
run: echo "::set-output name=relver::$(cat build/miniz.pc | grep Version | cut -d ':' -f2 | xargs)"
|
||||
|
||||
- name: Create Release
|
||||
id: create_release
|
||||
uses: actions/create-release@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ steps.relver.outputs.relver }}
|
||||
release_name: Release ${{ steps.relver.outputs.relver }}
|
||||
draft: false
|
||||
prerelease: false
|
||||
|
||||
- name: Upload Release Asset
|
||||
id: upload-release-asset
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./build/miniz-${{ steps.relver.outputs.relver }}.zip
|
||||
asset_name: miniz-${{ steps.relver.outputs.relver }}.zip
|
||||
asset_content_type: application/zip
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/_build
|
||||
/amalgamation
|
||||
/bin
|
||||
365
CMakeLists.txt
365
CMakeLists.txt
@ -1,40 +1,331 @@
|
||||
PROJECT(miniz)
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
set(CMAKE_CONFIGURATION_TYPES Release)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
||||
|
||||
set(miniz_SOURCE miniz.c miniz_zip.c miniz_tinfl.c miniz_tdef.c)
|
||||
|
||||
add_library(miniz ${miniz_SOURCE})
|
||||
|
||||
set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c")
|
||||
set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c")
|
||||
set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c")
|
||||
set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c")
|
||||
set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c")
|
||||
set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c")
|
||||
set(MINIZ_TESTER_SRC_LIST
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable(example1 ${EXAMPLE1_SRC_LIST})
|
||||
target_link_libraries(example1 miniz)
|
||||
add_executable(example2 ${EXAMPLE2_SRC_LIST})
|
||||
target_link_libraries(example2 miniz)
|
||||
add_executable(example3 ${EXAMPLE3_SRC_LIST})
|
||||
target_link_libraries(example3 miniz)
|
||||
add_executable(example4 ${EXAMPLE4_SRC_LIST})
|
||||
target_link_libraries(example4 miniz)
|
||||
add_executable(example5 ${EXAMPLE5_SRC_LIST})
|
||||
target_link_libraries(example5 miniz)
|
||||
add_executable(example6 ${EXAMPLE6_SRC_LIST})
|
||||
target_link_libraries(example6 miniz)
|
||||
if(${UNIX})
|
||||
target_link_libraries(example6 m)
|
||||
# determine whether this is a standalone project or included by other projects
|
||||
set (MINIZ_STANDALONE_PROJECT ON)
|
||||
if(DEFINED PROJECT_NAME)
|
||||
set(MINIZ_STANDALONE_PROJECT OFF)
|
||||
endif()
|
||||
|
||||
if(CMAKE_MINOR_VERSION LESS 12)
|
||||
project(miniz)
|
||||
# see issue https://gitlab.kitware.com/cmake/cmake/merge_requests/1799
|
||||
else()
|
||||
project(miniz)
|
||||
set(CMAKE_C_STANDARD 90)
|
||||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
# set(CMAKE_C_VISIBILITY_PRESET hidden)
|
||||
# set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
|
||||
|
||||
if (MSVC)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /Zi /permissive-")
|
||||
else ()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow -Wformat=2 -Wall -Wno-overlength-strings -pedantic")
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
set(MINIZ_API_VERSION 3)
|
||||
set(MINIZ_MINOR_VERSION 0)
|
||||
set(MINIZ_PATCH_VERSION 2)
|
||||
set(MINIZ_VERSION
|
||||
${MINIZ_API_VERSION}.${MINIZ_MINOR_VERSION}.${MINIZ_PATCH_VERSION})
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "")
|
||||
# CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
|
||||
# differentiation between debug and release builds.
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
|
||||
"Choose the type of build, options are: None (CMAKE_CXX_FLAGS or \
|
||||
CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
|
||||
endif ()
|
||||
|
||||
option(BUILD_EXAMPLES "Build examples" ${MINIZ_STANDALONE_PROJECT})
|
||||
option(BUILD_FUZZERS "Build fuzz targets" OFF)
|
||||
option(AMALGAMATE_SOURCES "Amalgamate sources into miniz.h/c" OFF)
|
||||
option(BUILD_HEADER_ONLY "Build a header-only version" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared library instead of static" OFF)
|
||||
option(BUILD_NO_STDIO" Build a without stdio version" OFF)
|
||||
option(BUILD_TESTS "Build tests" ${MINIZ_STANDALONE_PROJECT})
|
||||
option(INSTALL_PROJECT "Install project" ${MINIZ_STANDALONE_PROJECT})
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
|
||||
|
||||
if(INSTALL_PROJECT)
|
||||
include(GNUInstallDirs)
|
||||
endif()
|
||||
|
||||
if(BUILD_HEADER_ONLY)
|
||||
set(AMALGAMATE_SOURCES ON CACHE BOOL "Build a header-only version" FORCE)
|
||||
endif(BUILD_HEADER_ONLY)
|
||||
|
||||
if(AMALGAMATE_SOURCES)
|
||||
# Amalgamate
|
||||
file(COPY miniz.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/)
|
||||
file(READ miniz.h MINIZ_H)
|
||||
file(READ miniz_common.h MINIZ_COMMON_H)
|
||||
file(READ miniz_tdef.h MINIZ_TDEF_H)
|
||||
file(READ miniz_tinfl.h MINIZ_TINFL_H)
|
||||
file(READ miniz_zip.h MINIZ_ZIP_H)
|
||||
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h
|
||||
"${MINIZ_COMMON_H} ${MINIZ_TDEF_H} ${MINIZ_TINFL_H} ${MINIZ_ZIP_H}")
|
||||
|
||||
file(COPY miniz.c DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/)
|
||||
file(READ miniz_tdef.c MINIZ_TDEF_C)
|
||||
file(READ miniz_tinfl.c MINIZ_TINFL_C)
|
||||
file(READ miniz_zip.c MINIZ_ZIP_C)
|
||||
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c
|
||||
"${MINIZ_TDEF_C} ${MINIZ_TINFL_C} ${MINIZ_ZIP_C}")
|
||||
|
||||
file(READ ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h AMAL_MINIZ_H)
|
||||
file(READ ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c AMAL_MINIZ_C)
|
||||
foreach(REPLACE_STRING miniz;miniz_common;miniz_tdef;miniz_tinfl;miniz_zip;miniz_export)
|
||||
string(REPLACE "#include \"${REPLACE_STRING}.h\"" "" AMAL_MINIZ_H "${AMAL_MINIZ_H}")
|
||||
string(REPLACE "#include \"${REPLACE_STRING}.h\"" "" AMAL_MINIZ_C "${AMAL_MINIZ_C}")
|
||||
endforeach()
|
||||
string(CONCAT AMAL_MINIZ_H "#ifndef MINIZ_EXPORT\n#define MINIZ_EXPORT\n#endif\n" "${AMAL_MINIZ_H}")
|
||||
if(BUILD_HEADER_ONLY)
|
||||
string(CONCAT AMAL_MINIZ_H "${AMAL_MINIZ_H}" "\n#ifndef MINIZ_HEADER_FILE_ONLY\n"
|
||||
"${AMAL_MINIZ_C}" "\n#endif // MINIZ_HEADER_FILE_ONLY\n")
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}")
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
|
||||
# Might not be a good idea to force this on the library user
|
||||
# as it could bloat the global namespace
|
||||
# https://github.com/libevent/libevent/issues/460
|
||||
# target_compile_definitions(${PROJECT_NAME}
|
||||
# INTERFACE $<$<C_COMPILER_ID:GNU>:_GNU_SOURCE>)
|
||||
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND
|
||||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
else(BUILD_HEADER_ONLY)
|
||||
string(CONCAT AMAL_MINIZ_C "#include \"miniz.h\"\n" "${AMAL_MINIZ_C}")
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h "${AMAL_MINIZ_H}")
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c "${AMAL_MINIZ_C}")
|
||||
set(miniz_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.c)
|
||||
add_library(${PROJECT_NAME} STATIC ${miniz_SOURCE})
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
endif(BUILD_HEADER_ONLY)
|
||||
|
||||
set(INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/miniz.h)
|
||||
|
||||
file(GLOB_RECURSE ZIP_FILES RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/amalgamation" "${CMAKE_CURRENT_BINARY_DIR}/amalgamation/*")
|
||||
file(GLOB_RECURSE ZIP_FILES2 RELATIVE "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/examples/*")
|
||||
list(APPEND ZIP_FILES ${ZIP_FILES2})
|
||||
list(APPEND ZIP_FILES "ChangeLog.md")
|
||||
list(APPEND ZIP_FILES "readme.md")
|
||||
list(APPEND ZIP_FILES "LICENSE")
|
||||
set(ZIP_OUT_FN "${CMAKE_CURRENT_BINARY_DIR}/miniz-${MINIZ_VERSION}.zip")
|
||||
message(STATUS "Zip files: ${ZIP_FILES}")
|
||||
add_custom_command(
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/examples ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/examples
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/ChangeLog.md ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/ChangeLog.md
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/readme.md ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/readme.md
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/LICENSE ${CMAKE_CURRENT_BINARY_DIR}/amalgamation/LICENSE
|
||||
COMMAND ${CMAKE_COMMAND} -E tar "cf" "${ZIP_OUT_FN}" --format=zip -- ${ZIP_FILES}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/amalgamation"
|
||||
OUTPUT "${ZIP_OUT_FN}"
|
||||
DEPENDS ${ZIP_FILES}
|
||||
COMMENT "Zipping to ${CMAKE_CURRENT_BINARY_DIR}/miniz.zip."
|
||||
)
|
||||
|
||||
add_custom_target(
|
||||
create_zip ALL
|
||||
DEPENDS "${ZIP_OUT_FN}"
|
||||
)
|
||||
else(AMALGAMATE_SOURCES)
|
||||
include(GenerateExportHeader)
|
||||
set(miniz_SOURCE miniz.c miniz_zip.c miniz_tinfl.c miniz_tdef.c)
|
||||
add_library(${PROJECT_NAME} ${miniz_SOURCE})
|
||||
generate_export_header(${PROJECT_NAME})
|
||||
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
string(TOUPPER ${PROJECT_NAME} PROJECT_UPPER)
|
||||
set_target_properties(${PROJECT_NAME}
|
||||
PROPERTIES INTERFACE_COMPILE_DEFINITIONS ${PROJECT_UPPER}_STATIC_DEFINE)
|
||||
else()
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY C_VISIBILITY_PRESET hidden)
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${MINIZ_VERSION})
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${MINIZ_API_VERSION})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
file(GLOB INSTALL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
|
||||
list(APPEND
|
||||
INSTALL_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h)
|
||||
endif(AMALGAMATE_SOURCES)
|
||||
|
||||
if(NOT BUILD_HEADER_ONLY)
|
||||
target_compile_definitions(${PROJECT_NAME}
|
||||
PRIVATE $<$<C_COMPILER_ID:GNU>:_GNU_SOURCE>)
|
||||
|
||||
# pkg-config file
|
||||
configure_file(miniz.pc.in ${CMAKE_CURRENT_BINARY_DIR}/miniz.pc @ONLY)
|
||||
|
||||
if(INSTALL_PROJECT)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/miniz.pc
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BUILD_NO_STDIO)
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE MINIZ_NO_STDIO)
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY
|
||||
INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${MINIZ_API_VERSION})
|
||||
set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY
|
||||
COMPATIBLE_INTERFACE_STRING ${PROJECT_NAME}_MAJOR_VERSION
|
||||
)
|
||||
|
||||
if(INSTALL_PROJECT)
|
||||
install(TARGETS ${PROJECT_NAME} EXPORT ${PROJECT_NAME}Targets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
# users can use <miniz.h> or <miniz/miniz.h>
|
||||
INCLUDES DESTINATION include ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
|
||||
)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file(
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
VERSION ${MINIZ_VERSION}
|
||||
COMPATIBILITY AnyNewerVersion
|
||||
)
|
||||
|
||||
export(EXPORT ${PROJECT_NAME}Targets
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Targets.cmake"
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
)
|
||||
configure_file(Config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
|
||||
@ONLY
|
||||
)
|
||||
|
||||
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
FILE
|
||||
${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE
|
||||
${PROJECT_NAME}::
|
||||
DESTINATION
|
||||
${ConfigPackageLocation}
|
||||
)
|
||||
install(
|
||||
FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}Config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
DESTINATION
|
||||
${ConfigPackageLocation}
|
||||
COMPONENT
|
||||
Devel
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_EXAMPLES)
|
||||
set(EXAMPLE1_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.c")
|
||||
set(EXAMPLE2_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.c")
|
||||
set(EXAMPLE3_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example3.c")
|
||||
set(EXAMPLE4_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example4.c")
|
||||
set(EXAMPLE5_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example5.c")
|
||||
set(EXAMPLE6_SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/examples/example6.c")
|
||||
set(MINIZ_TESTER_SRC_LIST
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tests/miniz_tester.cpp"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/tests/timer.cpp")
|
||||
|
||||
add_executable(example1 ${EXAMPLE1_SRC_LIST})
|
||||
target_link_libraries(example1 miniz)
|
||||
if(NOT BUILD_NO_STDIO)
|
||||
add_executable(example2 ${EXAMPLE2_SRC_LIST})
|
||||
target_link_libraries(example2 miniz)
|
||||
endif()
|
||||
add_executable(example3 ${EXAMPLE3_SRC_LIST})
|
||||
target_link_libraries(example3 miniz)
|
||||
add_executable(example4 ${EXAMPLE4_SRC_LIST})
|
||||
target_link_libraries(example4 miniz)
|
||||
add_executable(example5 ${EXAMPLE5_SRC_LIST})
|
||||
target_link_libraries(example5 miniz)
|
||||
add_executable(example6 ${EXAMPLE6_SRC_LIST})
|
||||
target_link_libraries(example6 miniz)
|
||||
if(${UNIX})
|
||||
target_link_libraries(example6 m)
|
||||
endif()
|
||||
|
||||
# add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST})
|
||||
# target_link_libraries(miniz_tester miniz)
|
||||
endif(BUILD_EXAMPLES)
|
||||
|
||||
if(BUILD_FUZZERS)
|
||||
set(FUZZ_MAIN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/tests/fuzz_main.c")
|
||||
|
||||
set(CHECKSUM_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/checksum_fuzzer.c")
|
||||
set(FLUSH_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/flush_fuzzer.c")
|
||||
set(UNCOMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress_fuzzer.c")
|
||||
set(UNCOMPRESS2_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/uncompress2_fuzzer.c")
|
||||
set(COMPRESS_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/compress_fuzzer.c")
|
||||
set(SMALL_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/small_fuzzer.c")
|
||||
set(LARGE_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/large_fuzzer.c")
|
||||
set(ZIP_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/zip_fuzzer.c")
|
||||
set(ADD_IN_PLACE_FUZZER_SRC_LIST "${FUZZ_MAIN_SRC}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/add_in_place_fuzzer.c")
|
||||
|
||||
add_executable(checksum_fuzzer ${CHECKSUM_FUZZER_SRC_LIST})
|
||||
target_link_libraries(checksum_fuzzer miniz)
|
||||
|
||||
add_executable(flush_fuzzer ${FLUSH_FUZZER_SRC_LIST})
|
||||
target_link_libraries(flush_fuzzer miniz)
|
||||
|
||||
add_executable(uncompress_fuzzer ${UNCOMPRESS_FUZZER_SRC_LIST})
|
||||
target_link_libraries(uncompress_fuzzer miniz)
|
||||
|
||||
add_executable(uncompress2_fuzzer ${UNCOMPRESS2_FUZZER_SRC_LIST})
|
||||
target_link_libraries(uncompress2_fuzzer miniz)
|
||||
|
||||
add_executable(compress_fuzzer ${COMPRESS_FUZZER_SRC_LIST})
|
||||
target_link_libraries(compress_fuzzer miniz)
|
||||
|
||||
add_executable(small_fuzzer ${SMALL_FUZZER_SRC_LIST})
|
||||
target_link_libraries(small_fuzzer miniz)
|
||||
|
||||
add_executable(large_fuzzer ${LARGE_FUZZER_SRC_LIST})
|
||||
target_link_libraries(large_fuzzer miniz)
|
||||
|
||||
add_executable(zip_fuzzer ${ZIP_FUZZER_SRC_LIST})
|
||||
target_link_libraries(zip_fuzzer miniz)
|
||||
|
||||
add_executable(add_in_place_fuzzer ${ADD_IN_PLACE_FUZZER_SRC_LIST})
|
||||
target_link_libraries(add_in_place_fuzzer miniz)
|
||||
endif()
|
||||
|
||||
if(BUILD_TESTS)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED YES)
|
||||
|
||||
add_executable(catch_tests tests/main.cpp tests/catch_amalgamated.cpp)
|
||||
if(BUILD_NO_STDIO)
|
||||
target_compile_definitions(catch_tests PRIVATE -DMINIZ_NO_STDIO)
|
||||
endif()
|
||||
target_link_libraries(catch_tests miniz)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME catch_tests COMMAND $<TARGET_FILE:catch_tests>)
|
||||
endif()
|
||||
|
||||
set(INCLUDE_INSTALL_DIR "include")
|
||||
|
||||
if(INSTALL_PROJECT)
|
||||
install(FILES ${INSTALL_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
# add_executable(miniz_tester ${MINIZ_TESTER_SRC_LIST})
|
||||
# target_link_libraries(miniz_tester miniz)
|
||||
|
||||
31
CMakePresets.json
Normal file
31
CMakePresets.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"version": 6,
|
||||
"cmakeMinimumRequired": {
|
||||
"major": 3,
|
||||
"minor": 5,
|
||||
"patch": 0
|
||||
},
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "gcc",
|
||||
"displayName": "GCC",
|
||||
"description": "Default build options for GCC",
|
||||
"generator": "Unix Makefiles",
|
||||
"binaryDir": "${sourceDir}/build"
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "gcc",
|
||||
"configurePreset": "gcc"
|
||||
}
|
||||
],
|
||||
"testPresets": [
|
||||
{
|
||||
"name": "gcc",
|
||||
"configurePreset": "gcc",
|
||||
"output": {"outputOnFailure": true},
|
||||
"execution": {"noTestsAction": "error", "stopOnFailure": true}
|
||||
}
|
||||
]
|
||||
}
|
||||
117
ChangeLog.md
117
ChangeLog.md
@ -1,5 +1,113 @@
|
||||
## Changelog
|
||||
|
||||
### 3.0.2
|
||||
|
||||
- Fix buffer overrun in mz_utf8z_to_widechar on Windows
|
||||
|
||||
### 3.0.1
|
||||
|
||||
- Fix compilation error with MINIZ_USE_UNALIGNED_LOADS_AND_STORES=1
|
||||
|
||||
### 3.0.0
|
||||
|
||||
- Reduce memory usage for inflate. This changes `struct tinfl_decompressor_tag` and therefore requires a major version bump (breaks ABI compatibility)
|
||||
- Add padding to structures so it continues to work if features differ. This also changes some structures
|
||||
- Use _ftelli64, _fseeki64 and stat with MinGW32 and OpenWatcom
|
||||
- Fix varios warnings with OpenWatcom compiler
|
||||
- Avoid using unaligned memory access in UBSan builds
|
||||
- Set MINIZ_LITTLE_ENDIAN only if not set
|
||||
- Add MINIZ_NO_DEFLATE_APIS and MINIZ_NO_INFLATE_APIS
|
||||
- Fix use of uninitialized memory in tinfl_decompress_mem_to_callback()
|
||||
- Use wfopen on windows
|
||||
- Use _wstat64 instead _stat64 on windows
|
||||
- Use level_and_flags after MZ_DEFAULT_COMPRESSION has been handled
|
||||
- Improve endianess detection
|
||||
- Don't use unaligned stores and loads per default
|
||||
- Fix function declaration if MINIZ_NO_STDIO is used
|
||||
- Fix MZ_ZIP_GENERAL_PURPOSE_BIT_FLAG_UTF8 not being set
|
||||
- Remove total files check (its 32-bit uint)
|
||||
- tinfl_decompress: avoid NULL ptr arithmetic UB
|
||||
- miniz_zip: fix mz_zip_reader_extract_to_heap to read correct sizes
|
||||
- Eliminate 64-bit operations on 32-bit machines
|
||||
- Disable treating warnings as error with MSVC
|
||||
- Disable building shared lib via CMake by default
|
||||
- Fixed alignment problems on MacOS
|
||||
- Fixed get error string for MZ_ZIP_TOTAL_ERRORS
|
||||
- Write correct FLEVEL 2-bit value in zlib header
|
||||
- miniz.pc.in: fix include path not containing the "miniz" suffix
|
||||
- Fix compatibility with FreeBSD
|
||||
- pkg-config tweaks
|
||||
- Fix integer overflow in header corruption check
|
||||
- Fix some warnings
|
||||
- tdefl_compress_normal: Avoid NULL ptr arithmetic UB
|
||||
- replace use of stdint.h types with mz_ variants
|
||||
|
||||
|
||||
### 2.2.0
|
||||
|
||||
- Fix examples with amalgamation
|
||||
- Modified cmake script to support shared library mode and find_package
|
||||
- Fix for misleading doc comment on `mz_zip_reader_init_cfile` function
|
||||
- Add include location tolerance and stop forcing `_GNU_SOURCE`
|
||||
- Fix: mz_zip_reader_locate_file_v2 returns an mz_bool
|
||||
- Fix large file system checks
|
||||
- Add #elif to enable an external mz_crc32() to be linked in
|
||||
- Write with dynamic size (size of file/data to be added not known before adding)
|
||||
- Added uncompress2 for zlib compatibility
|
||||
- Add support for building as a Meson subproject
|
||||
- Added OSSFuzz support; Integrate with CIFuzz
|
||||
- Add pkg-config file
|
||||
- Fixed use-of-uninitialized value msan error when copying dist bytes with no output bytes written.
|
||||
- mz_zip_validate_file(): fix memory leak on errors
|
||||
- Fixed MSAN use-of-uninitialized in tinfl_decompress when invalid dist is decoded. In this instance dist was 31 which s_dist_base translates as 0
|
||||
- Add flag to set (compressed) size in local file header
|
||||
- avoid use of uninitialized value in tdefl_record_literal
|
||||
|
||||
### 2.1.0
|
||||
|
||||
- More instances of memcpy instead of cast and use memcpy per default
|
||||
- Remove inline for c90 support
|
||||
- New function to read files via callback functions when adding them
|
||||
- Fix out of bounds read while reading Zip64 extended information
|
||||
- guard memcpy when n == 0 because buffer may be NULL
|
||||
- Implement inflateReset() function
|
||||
- Move comp/decomp alloc/free prototypes under guarding #ifndef MZ_NO_MALLOC
|
||||
- Fix large file support under Windows
|
||||
- Don't warn if _LARGEFILE64_SOURCE is not defined to 1
|
||||
- Fixes for MSVC warnings
|
||||
- Remove check that path of file added to archive contains ':' or '\'
|
||||
- Add !defined check on MINIZ_USE_ALIGNED_LOADS_AND_STORES
|
||||
|
||||
### 2.0.8
|
||||
|
||||
- Remove unimplemented functions (mz_zip_locate_file and mz_zip_locate_file_v2)
|
||||
- Add license, changelog, readme and example files to release zip
|
||||
- Fix heap overflow to user buffer in tinfl_status tinfl_decompress
|
||||
- Fix corrupt archive if uncompressed file smaller than 4 byte and the file is added by mz_zip_writer_add_mem*
|
||||
|
||||
### 2.0.7
|
||||
|
||||
- Removed need in C++ compiler in cmake build
|
||||
- Fixed a lot of uninitialized value errors found with Valgrind by memsetting m_dict to 0 in tdefl_init
|
||||
- Fix resource leak in mz_zip_reader_init_file_v2
|
||||
- Fix assert with mz_zip_writer_add_mem* w/MZ_DEFAULT_COMPRESSION
|
||||
- cmake build: install library and headers
|
||||
- Remove _LARGEFILE64_SOURCE requirement from apple defines for large files
|
||||
|
||||
### 2.0.6
|
||||
|
||||
- Improve MZ_ZIP_FLAG_WRITE_ZIP64 documentation
|
||||
- Remove check for cur_archive_file_ofs > UINT_MAX because cur_archive_file_ofs is not used after this point
|
||||
- Add cmake debug configuration
|
||||
- Fix PNG height when creating png files
|
||||
- Add "iterative" file extraction method based on mz_zip_reader_extract_to_callback.
|
||||
- Option to use memcpy for unaligned data access
|
||||
- Define processor/arch macros as zero if not set to one
|
||||
|
||||
### 2.0.4/2.0.5
|
||||
|
||||
- Fix compilation with the various omission compile definitions
|
||||
|
||||
### 2.0.3
|
||||
|
||||
- Fix GCC/clang compile warnings
|
||||
@ -19,11 +127,12 @@
|
||||
|
||||
### 2.0.0 beta
|
||||
|
||||
- Matthew Sitton merged to vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed
|
||||
- Matthew Sitton merged miniz 1.x to Rich Geldreich's vogl ZIP64 changes. Miniz is now licensed as MIT since the vogl code base is MIT licensed
|
||||
- Miniz is now split into several files
|
||||
- Miniz does now not seek backwards when creating ZIP files. That is the ZIP files can be streamed
|
||||
- Miniz automatically switches to the ZIP64 format the created ZIP files goes over ZIP file limits
|
||||
- Miniz automatically switches to the ZIP64 format when the created ZIP files goes over ZIP file limits
|
||||
- Similar to [SQLite](https://www.sqlite.org/amalgamation.html) the Miniz source code is amalgamated into one miniz.c/miniz.h pair in a build step (amalgamate.sh). Please use miniz.c/miniz.h in your projects
|
||||
- Miniz 2 is only source back-compatible with miniz 1.x. It breaks binary compatibility because structures changed
|
||||
|
||||
### v1.16 BETA Oct 19, 2013
|
||||
|
||||
@ -36,7 +145,7 @@ The inflator now has a new failure status TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRE
|
||||
- The inflator coroutine func. is subtle and complex so I'm being cautious about this release. I would greatly appreciate any help with testing or any feedback.
|
||||
I feel good about these changes, and they've been through several hours of automated testing, but they will probably not fix anything for the majority of prev. users so I'm
|
||||
going to mark this release as beta for a few weeks and continue testing it at work/home on various things.
|
||||
- The inflator in raw (non-zlib) mode is now usable on gzip or similiar data streams that have a bunch of bytes following the raw deflate data (problem discovered by rustyzip author williamw520).
|
||||
- The inflator in raw (non-zlib) mode is now usable on gzip or similar data streams that have a bunch of bytes following the raw deflate data (problem discovered by rustyzip author williamw520).
|
||||
This version should *never* read beyond the last byte of the raw deflate data independent of how many bytes you pass into the input buffer. This issue was caused by the various Huffman bitbuffer lookahead optimizations, and
|
||||
would not be an issue if the caller knew and enforced the precise size of the raw compressed data *or* if the compressed data was in zlib format (i.e. always followed by the byte aligned zlib adler32).
|
||||
So in other words, you can now call the inflator on deflate streams that are followed by arbitrary amounts of data and it's guaranteed that decompression will stop exactly on the last byte.
|
||||
@ -57,7 +166,7 @@ Merged over a few very minor bug fixes that I fixed in the zip64 branch. This is
|
||||
Interim bugfix release while I work on the next major release with zip64 and streaming compression/decompression support. Fixed the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com), which could cause the locate files func to not find files when this flag was specified. Also fixed a bug in mz_zip_reader_extract_to_mem_no_alloc() with user provided read buffers (thanks kymoon). I also merged lots of compiler fixes from various github repo branches and Google Code issue reports. I finally added cmake support (only tested under for Linux so far), compiled and tested with clang v3.3 and gcc 4.6 (under Linux), added defl_write_image_to_png_file_in_memory_ex() (supports Y flipping for OpenGL use, real-time compression), added a new PNG example (example6.c - Mandelbrot), and I added 64-bit file I/O support (stat64(), etc.) for glibc.
|
||||
|
||||
- Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks kahmyong.moon@hp.com) which could cause locate files to not find files. This bug
|
||||
would only have occured in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place()
|
||||
would only have occurred in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place()
|
||||
(which used this flag). If you can't switch to v1.15 but want to fix this bug, just remove the uses of this flag from both helper funcs (and of course don't use the flag).
|
||||
- Bugfix in mz_zip_reader_extract_to_mem_no_alloc() from kymoon when pUser_read_buf is not NULL and compressed size is > uncompressed size
|
||||
- Fixing mz_zip_reader_extract_*() funcs so they don't try to extract compressed data from directory entries, to account for weird zipfiles which contain zero-size compressed data on dir entries.
|
||||
|
||||
1
Config.cmake.in
Normal file
1
Config.cmake.in
Normal file
@ -0,0 +1 @@
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
52
amalgamate.sh
Normal file → Executable file
52
amalgamate.sh
Normal file → Executable file
@ -3,47 +3,53 @@
|
||||
set -e
|
||||
|
||||
mkdir -p amalgamation
|
||||
OUTPUT_PREFIX=amalgamation/miniz
|
||||
|
||||
cat miniz.h > $OUTPUT_PREFIX.h
|
||||
cat miniz.c > $OUTPUT_PREFIX.c
|
||||
cat miniz_common.h >> $OUTPUT_PREFIX.h
|
||||
cat miniz_tdef.c >> $OUTPUT_PREFIX.c
|
||||
cat miniz_tdef.h >> $OUTPUT_PREFIX.h
|
||||
cat miniz_tinfl.c >> $OUTPUT_PREFIX.c
|
||||
cat miniz_tinfl.h >> $OUTPUT_PREFIX.h
|
||||
cat miniz_zip.c >> $OUTPUT_PREFIX.c
|
||||
cat miniz_zip.h >> $OUTPUT_PREFIX.h
|
||||
OUTPUT_PREFIX=_build/amalgamation
|
||||
|
||||
|
||||
sed -i '0,/#include "miniz.h"/{s/#include "miniz.h"/#include "miniz.h"/}' $OUTPUT_PREFIX.c
|
||||
for i in miniz miniz_common miniz_tdef miniz_tinfl miniz_zip
|
||||
do
|
||||
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.h
|
||||
sed -i "s/#include \"$i.h\"//g" $OUTPUT_PREFIX.c
|
||||
done
|
||||
cmake -H. -B_build -DAMALGAMATE_SOURCES=ON -G"Unix Makefiles"
|
||||
|
||||
echo "int main() { return 0; }" > main.c
|
||||
echo "Test compile with GCC..."
|
||||
gcc -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
|
||||
gcc -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out
|
||||
echo "Test compile with GCC ANSI..."
|
||||
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out
|
||||
gcc -ansi -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out
|
||||
if command -v clang
|
||||
then
|
||||
echo "Test compile with clang..."
|
||||
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow main.c $OUTPUT_PREFIX.c -o test.out
|
||||
clang -Wall -Wpedantic -fsanitize=unsigned-integer-overflow -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out
|
||||
fi
|
||||
for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC
|
||||
for def in MINIZ_NO_STDIO MINIZ_NO_TIME MINIZ_NO_DEFLATE_APIS MINIZ_NO_INFLATE_APIS MINIZ_NO_ARCHIVE_APIS MINIZ_NO_ARCHIVE_WRITING_APIS MINIZ_NO_ZLIB_APIS MINIZ_NO_ZLIB_COMPATIBLE_NAMES MINIZ_NO_MALLOC
|
||||
do
|
||||
echo "Test compile with GCC and define $def..."
|
||||
gcc -ansi -pedantic -Wall main.c $OUTPUT_PREFIX.c -o test.out -D${def}
|
||||
gcc -ansi -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out -D${def}
|
||||
done
|
||||
echo "Test compile with GCC and MINIZ_USE_UNALIGNED_LOADS_AND_STORES=1..."
|
||||
gcc -ansi -pedantic -Wall -I$OUTPUT_PREFIX main.c $OUTPUT_PREFIX/miniz.c -o test.out -DMINIZ_USE_UNALIGNED_LOADS_AND_STORES=1
|
||||
rm test.out
|
||||
rm main.c
|
||||
|
||||
cp $OUTPUT_PREFIX/miniz.* amalgamation/
|
||||
cp ChangeLog.md amalgamation/
|
||||
cp LICENSE amalgamation/
|
||||
cp readme.md amalgamation/
|
||||
mkdir -p amalgamation/examples
|
||||
cp examples/* amalgamation/examples/
|
||||
|
||||
cd amalgamation
|
||||
! test -e miniz.zip || rm miniz.zip
|
||||
echo -e "miniz.c\nminiz.h" | zip -@ miniz
|
||||
cat << EOF | zip -@ miniz
|
||||
miniz.c
|
||||
miniz.h
|
||||
ChangeLog.md
|
||||
LICENSE
|
||||
readme.md
|
||||
examples/example1.c
|
||||
examples/example2.c
|
||||
examples/example3.c
|
||||
examples/example4.c
|
||||
examples/example5.c
|
||||
examples/example6.c
|
||||
EOF
|
||||
cd ..
|
||||
|
||||
echo "Amalgamation created."
|
||||
|
||||
@ -7,99 +7,99 @@ typedef unsigned short uint16;
|
||||
typedef unsigned int uint;
|
||||
|
||||
// The string to compress.
|
||||
static const char *s_pStr = "Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson." \
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson.";
|
||||
static const char *s_pStr = "Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson.";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint step = 0;
|
||||
int cmp_status;
|
||||
uLong src_len = (uLong)strlen(s_pStr);
|
||||
uLong cmp_len = compressBound(src_len);
|
||||
uLong uncomp_len = src_len;
|
||||
uint8 *pCmp, *pUncomp;
|
||||
uint total_succeeded = 0;
|
||||
(void)argc, (void)argv;
|
||||
uint step = 0;
|
||||
int cmp_status;
|
||||
uLong src_len = (uLong)strlen(s_pStr);
|
||||
uLong cmp_len = compressBound(src_len);
|
||||
uLong uncomp_len = src_len;
|
||||
uint8 *pCmp, *pUncomp;
|
||||
uint total_succeeded = 0;
|
||||
(void)argc, (void)argv;
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
do
|
||||
{
|
||||
// Allocate buffers to hold compressed and uncompressed data.
|
||||
pCmp = (mz_uint8 *)malloc((size_t)cmp_len);
|
||||
pUncomp = (mz_uint8 *)malloc((size_t)src_len);
|
||||
if ((!pCmp) || (!pUncomp))
|
||||
do
|
||||
{
|
||||
printf("Out of memory!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Allocate buffers to hold compressed and uncompressed data.
|
||||
pCmp = (mz_uint8 *)malloc((size_t)cmp_len);
|
||||
pUncomp = (mz_uint8 *)malloc((size_t)src_len);
|
||||
if ((!pCmp) || (!pUncomp))
|
||||
{
|
||||
printf("Out of memory!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Compress the string.
|
||||
cmp_status = compress(pCmp, &cmp_len, (const unsigned char *)s_pStr, src_len);
|
||||
if (cmp_status != Z_OK)
|
||||
{
|
||||
printf("compress() failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Compress the string.
|
||||
cmp_status = compress(pCmp, &cmp_len, (const unsigned char *)s_pStr, src_len);
|
||||
if (cmp_status != Z_OK)
|
||||
{
|
||||
printf("compress() failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Compressed from %u to %u bytes\n", (mz_uint32)src_len, (mz_uint32)cmp_len);
|
||||
printf("Compressed from %u to %u bytes\n", (mz_uint32)src_len, (mz_uint32)cmp_len);
|
||||
|
||||
if (step)
|
||||
{
|
||||
// Purposely corrupt the compressed data if fuzzy testing (this is a very crude fuzzy test).
|
||||
uint n = 1 + (rand() % 3);
|
||||
while (n--)
|
||||
{
|
||||
uint i = rand() % cmp_len;
|
||||
pCmp[i] ^= (rand() & 0xFF);
|
||||
}
|
||||
}
|
||||
if (step)
|
||||
{
|
||||
// Purposely corrupt the compressed data if fuzzy testing (this is a very crude fuzzy test).
|
||||
uint n = 1 + (rand() % 3);
|
||||
while (n--)
|
||||
{
|
||||
uint i = rand() % cmp_len;
|
||||
pCmp[i] ^= (rand() & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
// Decompress.
|
||||
cmp_status = uncompress(pUncomp, &uncomp_len, pCmp, cmp_len);
|
||||
total_succeeded += (cmp_status == Z_OK);
|
||||
// Decompress.
|
||||
cmp_status = uncompress(pUncomp, &uncomp_len, pCmp, cmp_len);
|
||||
total_succeeded += (cmp_status == Z_OK);
|
||||
|
||||
if (step)
|
||||
{
|
||||
printf("Simple fuzzy test: step %u total_succeeded: %u\n", step, total_succeeded);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cmp_status != Z_OK)
|
||||
{
|
||||
printf("uncompress failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Decompressed from %u to %u bytes\n", (mz_uint32)cmp_len, (mz_uint32)uncomp_len);
|
||||
|
||||
// Ensure uncompress() returned the expected data.
|
||||
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, (size_t)src_len)))
|
||||
{
|
||||
printf("Decompression failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (step)
|
||||
{
|
||||
printf("Simple fuzzy test: step %u total_succeeded: %u\n", step, total_succeeded);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cmp_status != Z_OK)
|
||||
{
|
||||
printf("uncompress failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Decompressed from %u to %u bytes\n", (mz_uint32)cmp_len, (mz_uint32)uncomp_len);
|
||||
step++;
|
||||
|
||||
// Ensure uncompress() returned the expected data.
|
||||
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, (size_t)src_len)))
|
||||
{
|
||||
printf("Decompression failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
// Keep on fuzzy testing if there's a non-empty command line.
|
||||
} while (argc >= 2);
|
||||
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
|
||||
step++;
|
||||
|
||||
// Keep on fuzzy testing if there's a non-empty command line.
|
||||
} while (argc >= 2);
|
||||
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -3,17 +3,17 @@
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
|
||||
#if defined(__GNUC__)
|
||||
// Ensure we get the 64-bit variants of the CRT's file I/O calls
|
||||
#ifndef _FILE_OFFSET_BITS
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE 1
|
||||
#endif
|
||||
// Ensure we get the 64-bit variants of the CRT's file I/O calls
|
||||
#ifndef _FILE_OFFSET_BITS
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#endif
|
||||
#ifndef _LARGEFILE64_SOURCE
|
||||
#define _LARGEFILE64_SOURCE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "miniz_zip.h"
|
||||
#include "miniz.h"
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
@ -21,144 +21,144 @@ typedef unsigned int uint;
|
||||
|
||||
// The string to compress.
|
||||
static const char *s_pTest_str =
|
||||
"MISSION CONTROL I wouldn't worry too much about the computer. First of all, there is still a chance that he is right, despite your tests, and" \
|
||||
"if it should happen again, we suggest eliminating this possibility by allowing the unit to remain in place and seeing whether or not it" \
|
||||
"actually fails. If the computer should turn out to be wrong, the situation is still not alarming. The type of obsessional error he may be" \
|
||||
"guilty of is not unknown among the latest generation of HAL 9000 computers. It has almost always revolved around a single detail, such as" \
|
||||
"the one you have described, and it has never interfered with the integrity or reliability of the computer's performance in other areas." \
|
||||
"No one is certain of the cause of this kind of malfunctioning. It may be over-programming, but it could also be any number of reasons. In any" \
|
||||
"event, it is somewhat analogous to human neurotic behavior. Does this answer your query? Zero-five-three-Zero, MC, transmission concluded.";
|
||||
"MISSION CONTROL I wouldn't worry too much about the computer. First of all, there is still a chance that he is right, despite your tests, and"
|
||||
"if it should happen again, we suggest eliminating this possibility by allowing the unit to remain in place and seeing whether or not it"
|
||||
"actually fails. If the computer should turn out to be wrong, the situation is still not alarming. The type of obsessional error he may be"
|
||||
"guilty of is not unknown among the latest generation of HAL 9000 computers. It has almost always revolved around a single detail, such as"
|
||||
"the one you have described, and it has never interfered with the integrity or reliability of the computer's performance in other areas."
|
||||
"No one is certain of the cause of this kind of malfunctioning. It may be over-programming, but it could also be any number of reasons. In any"
|
||||
"event, it is somewhat analogous to human neurotic behavior. Does this answer your query? Zero-five-three-Zero, MC, transmission concluded.";
|
||||
|
||||
static const char *s_pComment = "This is a comment";
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i, sort_iter;
|
||||
mz_bool status;
|
||||
size_t uncomp_size;
|
||||
mz_zip_archive zip_archive;
|
||||
void *p;
|
||||
const int N = 50;
|
||||
char data[2048];
|
||||
char archive_filename[64];
|
||||
static const char *s_Test_archive_filename = "__mz_example2_test__.zip";
|
||||
int i, sort_iter;
|
||||
mz_bool status;
|
||||
size_t uncomp_size;
|
||||
mz_zip_archive zip_archive;
|
||||
void *p;
|
||||
const int N = 50;
|
||||
char data[2048];
|
||||
char archive_filename[64];
|
||||
static const char *s_Test_archive_filename = "__mz_example2_test__.zip";
|
||||
|
||||
assert((strlen(s_pTest_str) + 64) < sizeof(data));
|
||||
assert((strlen(s_pTest_str) + 64) < sizeof(data));
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
(void)argc, (void)argv;
|
||||
(void)argc, (void)argv;
|
||||
|
||||
// Delete the test archive, so it doesn't keep growing as we run this test
|
||||
remove(s_Test_archive_filename);
|
||||
// Delete the test archive, so it doesn't keep growing as we run this test
|
||||
remove(s_Test_archive_filename);
|
||||
|
||||
// Append a bunch of text files to the test archive
|
||||
for (i = (N - 1); i >= 0; --i)
|
||||
{
|
||||
sprintf(archive_filename, "%u.txt", i);
|
||||
sprintf(data, "%u %s %u", (N - 1) - i, s_pTest_str, i);
|
||||
// Append a bunch of text files to the test archive
|
||||
for (i = (N - 1); i >= 0; --i)
|
||||
{
|
||||
sprintf(archive_filename, "%u.txt", i);
|
||||
sprintf(data, "%u %s %u", (N - 1) - i, s_pTest_str, i);
|
||||
|
||||
// Add a new file to the archive. Note this is an IN-PLACE operation, so if it fails your archive is probably hosed (its central directory may not be complete) but it should be recoverable using zip -F or -FF. So use caution with this guy.
|
||||
// A more robust way to add a file to an archive would be to read it into memory, perform the operation, then write a new archive out to a temp file and then delete/rename the files.
|
||||
// Or, write a new archive to disk to a temp file, then delete/rename the files. For this test this API is fine.
|
||||
status = mz_zip_add_mem_to_archive_file_in_place(s_Test_archive_filename, archive_filename, data, strlen(data) + 1, s_pComment, (uint16)strlen(s_pComment), MZ_BEST_COMPRESSION);
|
||||
// Add a new file to the archive. Note this is an IN-PLACE operation, so if it fails your archive is probably hosed (its central directory may not be complete) but it should be recoverable using zip -F or -FF. So use caution with this guy.
|
||||
// A more robust way to add a file to an archive would be to read it into memory, perform the operation, then write a new archive out to a temp file and then delete/rename the files.
|
||||
// Or, write a new archive to disk to a temp file, then delete/rename the files. For this test this API is fine.
|
||||
status = mz_zip_add_mem_to_archive_file_in_place(s_Test_archive_filename, archive_filename, data, strlen(data) + 1, s_pComment, (uint16)strlen(s_pComment), MZ_BEST_COMPRESSION);
|
||||
if (!status)
|
||||
{
|
||||
printf("mz_zip_add_mem_to_archive_file_in_place failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a directory entry for testing
|
||||
status = mz_zip_add_mem_to_archive_file_in_place(s_Test_archive_filename, "directory/", NULL, 0, "no comment", (uint16)strlen("no comment"), MZ_BEST_COMPRESSION);
|
||||
if (!status)
|
||||
{
|
||||
printf("mz_zip_add_mem_to_archive_file_in_place failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Add a directory entry for testing
|
||||
status = mz_zip_add_mem_to_archive_file_in_place(s_Test_archive_filename, "directory/", NULL, 0, "no comment", (uint16)strlen("no comment"), MZ_BEST_COMPRESSION);
|
||||
if (!status)
|
||||
{
|
||||
printf("mz_zip_add_mem_to_archive_file_in_place failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Now try to open the archive.
|
||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||
|
||||
status = mz_zip_reader_init_file(&zip_archive, s_Test_archive_filename, 0);
|
||||
if (!status)
|
||||
{
|
||||
printf("mz_zip_reader_init_file() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Get and print information about each file in the archive.
|
||||
for (i = 0; i < (int)mz_zip_reader_get_num_files(&zip_archive); i++)
|
||||
{
|
||||
mz_zip_archive_file_stat file_stat;
|
||||
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat))
|
||||
{
|
||||
printf("mz_zip_reader_file_stat() failed!\n");
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u, Is Dir: %u\n", file_stat.m_filename, file_stat.m_comment, (uint)file_stat.m_uncomp_size, (uint)file_stat.m_comp_size, mz_zip_reader_is_file_a_directory(&zip_archive, i));
|
||||
|
||||
if (!strcmp(file_stat.m_filename, "directory/"))
|
||||
{
|
||||
if (!mz_zip_reader_is_file_a_directory(&zip_archive, i))
|
||||
{
|
||||
printf("mz_zip_reader_is_file_a_directory() didn't return the expected results!\n");
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
printf("mz_zip_add_mem_to_archive_file_in_place failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the archive, freeing any resources it was using
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
|
||||
// Now verify the compressed data
|
||||
for (sort_iter = 0; sort_iter < 2; sort_iter++)
|
||||
{
|
||||
// Now try to open the archive.
|
||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||
status = mz_zip_reader_init_file(&zip_archive, s_Test_archive_filename, sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0);
|
||||
|
||||
status = mz_zip_reader_init_file(&zip_archive, s_Test_archive_filename, 0);
|
||||
if (!status)
|
||||
{
|
||||
printf("mz_zip_reader_init_file() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
printf("mz_zip_reader_init_file() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
// Get and print information about each file in the archive.
|
||||
for (i = 0; i < (int)mz_zip_reader_get_num_files(&zip_archive); i++)
|
||||
{
|
||||
sprintf(archive_filename, "%u.txt", i);
|
||||
sprintf(data, "%u %s %u", (N - 1) - i, s_pTest_str, i);
|
||||
mz_zip_archive_file_stat file_stat;
|
||||
if (!mz_zip_reader_file_stat(&zip_archive, i, &file_stat))
|
||||
{
|
||||
printf("mz_zip_reader_file_stat() failed!\n");
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Try to extract all the files to the heap.
|
||||
p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);
|
||||
if (!p)
|
||||
{
|
||||
printf("mz_zip_reader_extract_file_to_heap() failed!\n");
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Filename: \"%s\", Comment: \"%s\", Uncompressed size: %u, Compressed size: %u, Is Dir: %u\n", file_stat.m_filename, file_stat.m_comment, (uint)file_stat.m_uncomp_size, (uint)file_stat.m_comp_size, mz_zip_reader_is_file_a_directory(&zip_archive, i));
|
||||
|
||||
// Make sure the extraction really succeeded.
|
||||
if ((uncomp_size != (strlen(data) + 1)) || (memcmp(p, data, strlen(data))))
|
||||
{
|
||||
printf("mz_zip_reader_extract_file_to_heap() failed to extract the proper data\n");
|
||||
mz_free(p);
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
|
||||
printf("File data: \"%s\"\n", (const char *)p);
|
||||
|
||||
// We're done.
|
||||
mz_free(p);
|
||||
if (!strcmp(file_stat.m_filename, "directory/"))
|
||||
{
|
||||
if (!mz_zip_reader_is_file_a_directory(&zip_archive, i))
|
||||
{
|
||||
printf("mz_zip_reader_is_file_a_directory() didn't return the expected results!\n");
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close the archive, freeing any resources it was using
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
}
|
||||
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
// Now verify the compressed data
|
||||
for (sort_iter = 0; sort_iter < 2; sort_iter++)
|
||||
{
|
||||
memset(&zip_archive, 0, sizeof(zip_archive));
|
||||
status = mz_zip_reader_init_file(&zip_archive, s_Test_archive_filename, sort_iter ? MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY : 0);
|
||||
if (!status)
|
||||
{
|
||||
printf("mz_zip_reader_init_file() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
sprintf(archive_filename, "%u.txt", i);
|
||||
sprintf(data, "%u %s %u", (N - 1) - i, s_pTest_str, i);
|
||||
|
||||
// Try to extract all the files to the heap.
|
||||
p = mz_zip_reader_extract_file_to_heap(&zip_archive, archive_filename, &uncomp_size, 0);
|
||||
if (!p)
|
||||
{
|
||||
printf("mz_zip_reader_extract_file_to_heap() failed!\n");
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Make sure the extraction really succeeded.
|
||||
if ((uncomp_size != (strlen(data) + 1)) || (memcmp(p, data, strlen(data))))
|
||||
{
|
||||
printf("mz_zip_reader_extract_file_to_heap() failed to extract the proper data\n");
|
||||
mz_free(p);
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
|
||||
printf("File data: \"%s\"\n", (const char *)p);
|
||||
|
||||
// We're done.
|
||||
mz_free(p);
|
||||
}
|
||||
|
||||
// Close the archive, freeing any resources it was using
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
}
|
||||
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -9,8 +9,8 @@ typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint;
|
||||
|
||||
#define my_max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define my_min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#define my_max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define my_min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
#define BUF_SIZE (1024 * 1024)
|
||||
static uint8 s_inbuf[BUF_SIZE];
|
||||
@ -18,252 +18,252 @@ static uint8 s_outbuf[BUF_SIZE];
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *pMode;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size;
|
||||
int level = Z_BEST_COMPRESSION;
|
||||
z_stream stream;
|
||||
int p = 1;
|
||||
const char *pSrc_filename;
|
||||
const char *pDst_filename;
|
||||
long file_loc;
|
||||
const char *pMode;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size;
|
||||
int level = Z_BEST_COMPRESSION;
|
||||
z_stream stream;
|
||||
int p = 1;
|
||||
const char *pSrc_filename;
|
||||
const char *pDst_filename;
|
||||
long file_loc;
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
if (argc < 4)
|
||||
{
|
||||
printf("Usage: example3 [options] [mode:c or d] infile outfile\n");
|
||||
printf("\nModes:\n");
|
||||
printf("c - Compresses file infile to a zlib stream in file outfile\n");
|
||||
printf("d - Decompress zlib stream in file infile to file outfile\n");
|
||||
printf("\nOptions:\n");
|
||||
printf("-l[0-10] - Compression level, higher values are slower.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while ((p < argc) && (argv[p][0] == '-'))
|
||||
{
|
||||
switch (argv[p][1])
|
||||
if (argc < 4)
|
||||
{
|
||||
case 'l':
|
||||
{
|
||||
level = atoi(&argv[1][2]);
|
||||
if ((level < 0) || (level > 10))
|
||||
{
|
||||
printf("Invalid level!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Invalid option: %s\n", argv[p]);
|
||||
printf("Usage: example3 [options] [mode:c or d] infile outfile\n");
|
||||
printf("\nModes:\n");
|
||||
printf("c - Compresses file infile to a zlib stream in file outfile\n");
|
||||
printf("d - Decompress zlib stream in file infile to file outfile\n");
|
||||
printf("\nOptions:\n");
|
||||
printf("-l[0-10] - Compression level, higher values are slower.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
if ((argc - p) < 3)
|
||||
{
|
||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if ((argc - p) > 3)
|
||||
{
|
||||
printf("Too many filenames!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pMode = argv[p++];
|
||||
if (!strchr("cCdD", pMode[0]))
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pSrc_filename = argv[p++];
|
||||
pDst_filename = argv[p++];
|
||||
|
||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||
|
||||
// Open input file.
|
||||
pInfile = fopen(pSrc_filename, "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Determine input file's size.
|
||||
fseek(pInfile, 0, SEEK_END);
|
||||
file_loc = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
if ((file_loc < 0) || (file_loc > INT_MAX))
|
||||
{
|
||||
// This is not a limitation of miniz or tinfl, but this example.
|
||||
printf("File is too large to be processed by this example.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
infile_size = (uint)file_loc;
|
||||
|
||||
// Open output file.
|
||||
pOutfile = fopen(pDst_filename, "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Input file size: %u\n", infile_size);
|
||||
|
||||
// Init the z_stream
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
stream.next_in = s_inbuf;
|
||||
stream.avail_in = 0;
|
||||
stream.next_out = s_outbuf;
|
||||
stream.avail_out = BUF_SIZE;
|
||||
|
||||
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
||||
{
|
||||
// Compression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
if (deflateInit(&stream, level) != Z_OK)
|
||||
{
|
||||
printf("deflateInit() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for ( ; ; )
|
||||
while ((p < argc) && (argv[p][0] == '-'))
|
||||
{
|
||||
int status;
|
||||
if (!stream.avail_in)
|
||||
{
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
switch (argv[p][1])
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
case 'l':
|
||||
{
|
||||
level = atoi(&argv[1][2]);
|
||||
if ((level < 0) || (level > 10))
|
||||
{
|
||||
printf("Invalid level!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Invalid option: %s\n", argv[p]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
stream.next_in = s_inbuf;
|
||||
stream.avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
//printf("Input bytes remaining: %u\n", infile_remaining);
|
||||
}
|
||||
|
||||
status = deflate(&stream, infile_remaining ? Z_NO_FLUSH : Z_FINISH);
|
||||
|
||||
if ((status == Z_STREAM_END) || (!stream.avail_out))
|
||||
{
|
||||
// Output buffer is full, or compression is done, so write buffer to output file.
|
||||
uint n = BUF_SIZE - stream.avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
stream.next_out = s_outbuf;
|
||||
stream.avail_out = BUF_SIZE;
|
||||
}
|
||||
|
||||
if (status == Z_STREAM_END)
|
||||
break;
|
||||
else if (status != Z_OK)
|
||||
{
|
||||
printf("deflate() failed with status %i!\n", status);
|
||||
if ((argc - p) < 3)
|
||||
{
|
||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (deflateEnd(&stream) != Z_OK)
|
||||
else if ((argc - p) > 3)
|
||||
{
|
||||
printf("deflateEnd() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if ((pMode[0] == 'd') || (pMode[0] == 'D'))
|
||||
{
|
||||
// Decompression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
if (inflateInit(&stream))
|
||||
{
|
||||
printf("inflateInit() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
int status;
|
||||
if (!stream.avail_in)
|
||||
{
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
stream.next_in = s_inbuf;
|
||||
stream.avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
}
|
||||
|
||||
status = inflate(&stream, Z_SYNC_FLUSH);
|
||||
|
||||
if ((status == Z_STREAM_END) || (!stream.avail_out))
|
||||
{
|
||||
// Output buffer is full, or decompression is done, so write buffer to output file.
|
||||
uint n = BUF_SIZE - stream.avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
stream.next_out = s_outbuf;
|
||||
stream.avail_out = BUF_SIZE;
|
||||
}
|
||||
|
||||
if (status == Z_STREAM_END)
|
||||
break;
|
||||
else if (status != Z_OK)
|
||||
{
|
||||
printf("inflate() failed with status %i!\n", status);
|
||||
printf("Too many filenames!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (inflateEnd(&stream) != Z_OK)
|
||||
pMode = argv[p++];
|
||||
if (!strchr("cCdD", pMode[0]))
|
||||
{
|
||||
printf("inflateEnd() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fclose(pInfile);
|
||||
if (EOF == fclose(pOutfile))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
pSrc_filename = argv[p++];
|
||||
pDst_filename = argv[p++];
|
||||
|
||||
printf("Total input bytes: %u\n", (mz_uint32)stream.total_in);
|
||||
printf("Total output bytes: %u\n", (mz_uint32)stream.total_out);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||
|
||||
// Open input file.
|
||||
pInfile = fopen(pSrc_filename, "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Determine input file's size.
|
||||
fseek(pInfile, 0, SEEK_END);
|
||||
file_loc = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
|
||||
{
|
||||
// This is not a limitation of miniz or tinfl, but this example.
|
||||
printf("File is too large to be processed by this example.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
infile_size = (uint)file_loc;
|
||||
|
||||
// Open output file.
|
||||
pOutfile = fopen(pDst_filename, "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Input file size: %u\n", infile_size);
|
||||
|
||||
// Init the z_stream
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
stream.next_in = s_inbuf;
|
||||
stream.avail_in = 0;
|
||||
stream.next_out = s_outbuf;
|
||||
stream.avail_out = BUF_SIZE;
|
||||
|
||||
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
||||
{
|
||||
// Compression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
if (deflateInit(&stream, level) != Z_OK)
|
||||
{
|
||||
printf("deflateInit() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int status;
|
||||
if (!stream.avail_in)
|
||||
{
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
stream.next_in = s_inbuf;
|
||||
stream.avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
// printf("Input bytes remaining: %u\n", infile_remaining);
|
||||
}
|
||||
|
||||
status = deflate(&stream, infile_remaining ? Z_NO_FLUSH : Z_FINISH);
|
||||
|
||||
if ((status == Z_STREAM_END) || (!stream.avail_out))
|
||||
{
|
||||
// Output buffer is full, or compression is done, so write buffer to output file.
|
||||
uint n = BUF_SIZE - stream.avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
stream.next_out = s_outbuf;
|
||||
stream.avail_out = BUF_SIZE;
|
||||
}
|
||||
|
||||
if (status == Z_STREAM_END)
|
||||
break;
|
||||
else if (status != Z_OK)
|
||||
{
|
||||
printf("deflate() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (deflateEnd(&stream) != Z_OK)
|
||||
{
|
||||
printf("deflateEnd() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else if ((pMode[0] == 'd') || (pMode[0] == 'D'))
|
||||
{
|
||||
// Decompression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
if (inflateInit(&stream))
|
||||
{
|
||||
printf("inflateInit() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int status;
|
||||
if (!stream.avail_in)
|
||||
{
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
stream.next_in = s_inbuf;
|
||||
stream.avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
}
|
||||
|
||||
status = inflate(&stream, Z_SYNC_FLUSH);
|
||||
|
||||
if ((status == Z_STREAM_END) || (!stream.avail_out))
|
||||
{
|
||||
// Output buffer is full, or decompression is done, so write buffer to output file.
|
||||
uint n = BUF_SIZE - stream.avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
stream.next_out = s_outbuf;
|
||||
stream.avail_out = BUF_SIZE;
|
||||
}
|
||||
|
||||
if (status == Z_STREAM_END)
|
||||
break;
|
||||
else if (status != Z_OK)
|
||||
{
|
||||
printf("inflate() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (inflateEnd(&stream) != Z_OK)
|
||||
{
|
||||
printf("inflateEnd() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fclose(pInfile);
|
||||
if (EOF == fclose(pOutfile))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Total input bytes: %u\n", (mz_uint32)stream.total_in);
|
||||
printf("Total output bytes: %u\n", (mz_uint32)stream.total_out);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
// example4.c - Uses tinfl.c to decompress a zlib stream in memory to an output file
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
#include "miniz_tinfl.h"
|
||||
#include "miniz.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
@ -8,95 +8,95 @@ typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint;
|
||||
|
||||
#define my_max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define my_min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#define my_max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define my_min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
static int tinfl_put_buf_func(const void* pBuf, int len, void *pUser)
|
||||
static int tinfl_put_buf_func(const void *pBuf, int len, void *pUser)
|
||||
{
|
||||
return len == (int)fwrite(pBuf, 1, len, (FILE*)pUser);
|
||||
return len == (int)fwrite(pBuf, 1, len, (FILE *)pUser);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int status;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size, outfile_size;
|
||||
size_t in_buf_size;
|
||||
uint8 *pCmp_data;
|
||||
long file_loc;
|
||||
int status;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size, outfile_size;
|
||||
size_t in_buf_size;
|
||||
uint8 *pCmp_data;
|
||||
long file_loc;
|
||||
|
||||
if (argc != 3)
|
||||
{
|
||||
printf("Usage: example4 infile outfile\n");
|
||||
printf("Decompresses zlib stream in file infile to file outfile.\n");
|
||||
printf("Input file must be able to fit entirely in memory.\n");
|
||||
printf("example3 can be used to create compressed zlib streams.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (argc != 3)
|
||||
{
|
||||
printf("Usage: example4 infile outfile\n");
|
||||
printf("Decompresses zlib stream in file infile to file outfile.\n");
|
||||
printf("Input file must be able to fit entirely in memory.\n");
|
||||
printf("example3 can be used to create compressed zlib streams.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Open input file.
|
||||
pInfile = fopen(argv[1], "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Open input file.
|
||||
pInfile = fopen(argv[1], "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Determine input file's size.
|
||||
fseek(pInfile, 0, SEEK_END);
|
||||
file_loc = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
// Determine input file's size.
|
||||
fseek(pInfile, 0, SEEK_END);
|
||||
file_loc = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
if ((file_loc < 0) || (file_loc > INT_MAX))
|
||||
{
|
||||
// This is not a limitation of miniz or tinfl, but this example.
|
||||
printf("File is too large to be processed by this example.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
|
||||
{
|
||||
// This is not a limitation of miniz or tinfl, but this example.
|
||||
printf("File is too large to be processed by this example.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
infile_size = (uint)file_loc;
|
||||
infile_size = (uint)file_loc;
|
||||
|
||||
pCmp_data = (uint8 *)malloc(infile_size);
|
||||
if (!pCmp_data)
|
||||
{
|
||||
printf("Out of memory!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (fread(pCmp_data, 1, infile_size, pInfile) != infile_size)
|
||||
{
|
||||
printf("Failed reading input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
pCmp_data = (uint8 *)malloc(infile_size);
|
||||
if (!pCmp_data)
|
||||
{
|
||||
printf("Out of memory!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (fread(pCmp_data, 1, infile_size, pInfile) != infile_size)
|
||||
{
|
||||
printf("Failed reading input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Open output file.
|
||||
pOutfile = fopen(argv[2], "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Open output file.
|
||||
pOutfile = fopen(argv[2], "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Input file size: %u\n", infile_size);
|
||||
printf("Input file size: %u\n", infile_size);
|
||||
|
||||
in_buf_size = infile_size;
|
||||
status = tinfl_decompress_mem_to_callback(pCmp_data, &in_buf_size, tinfl_put_buf_func, pOutfile, TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||
if (!status)
|
||||
{
|
||||
printf("tinfl_decompress_mem_to_callback() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
in_buf_size = infile_size;
|
||||
status = tinfl_decompress_mem_to_callback(pCmp_data, &in_buf_size, tinfl_put_buf_func, pOutfile, TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||
if (!status)
|
||||
{
|
||||
printf("tinfl_decompress_mem_to_callback() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
outfile_size = ftell(pOutfile);
|
||||
outfile_size = ftell(pOutfile);
|
||||
|
||||
fclose(pInfile);
|
||||
if (EOF == fclose(pOutfile))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
fclose(pInfile);
|
||||
if (EOF == fclose(pOutfile))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Total input bytes: %u\n", (uint)in_buf_size);
|
||||
printf("Total output bytes: %u\n", outfile_size);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
printf("Total input bytes: %u\n", (uint)in_buf_size);
|
||||
printf("Total output bytes: %u\n", outfile_size);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -19,22 +19,22 @@ typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint;
|
||||
|
||||
#define my_max(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#define my_min(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#define my_max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define my_min(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
// IN_BUF_SIZE is the size of the file read buffer.
|
||||
// IN_BUF_SIZE must be >= 1
|
||||
#define IN_BUF_SIZE (1024*512)
|
||||
#define IN_BUF_SIZE (1024 * 512)
|
||||
static uint8 s_inbuf[IN_BUF_SIZE];
|
||||
|
||||
// COMP_OUT_BUF_SIZE is the size of the output buffer used during compression.
|
||||
// COMP_OUT_BUF_SIZE must be >= 1 and <= OUT_BUF_SIZE
|
||||
#define COMP_OUT_BUF_SIZE (1024*512)
|
||||
#define COMP_OUT_BUF_SIZE (1024 * 512)
|
||||
|
||||
// OUT_BUF_SIZE is the size of the output buffer used during decompression.
|
||||
// OUT_BUF_SIZE must be a power of 2 >= TINFL_LZ_DICT_SIZE (because the low-level decompressor not only writes, but reads from the output buffer as it decompresses)
|
||||
//#define OUT_BUF_SIZE (TINFL_LZ_DICT_SIZE)
|
||||
#define OUT_BUF_SIZE (1024*512)
|
||||
#define OUT_BUF_SIZE (1024 * 512)
|
||||
static uint8 s_outbuf[OUT_BUF_SIZE];
|
||||
|
||||
// tdefl_compressor contains all the state needed by the low-level compressor so it's a pretty big struct (~300k).
|
||||
@ -43,285 +43,285 @@ tdefl_compressor g_deflator;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *pMode;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size;
|
||||
int level = 9;
|
||||
int p = 1;
|
||||
const char *pSrc_filename;
|
||||
const char *pDst_filename;
|
||||
const void *next_in = s_inbuf;
|
||||
size_t avail_in = 0;
|
||||
void *next_out = s_outbuf;
|
||||
size_t avail_out = OUT_BUF_SIZE;
|
||||
size_t total_in = 0, total_out = 0;
|
||||
long file_loc;
|
||||
const char *pMode;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size;
|
||||
int level = 9;
|
||||
int p = 1;
|
||||
const char *pSrc_filename;
|
||||
const char *pDst_filename;
|
||||
const void *next_in = s_inbuf;
|
||||
size_t avail_in = 0;
|
||||
void *next_out = s_outbuf;
|
||||
size_t avail_out = OUT_BUF_SIZE;
|
||||
size_t total_in = 0, total_out = 0;
|
||||
long file_loc;
|
||||
|
||||
assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE);
|
||||
assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE);
|
||||
|
||||
printf("miniz.c example5 (demonstrates tinfl/tdefl)\n");
|
||||
printf("miniz.c example5 (demonstrates tinfl/tdefl)\n");
|
||||
|
||||
if (argc < 4)
|
||||
{
|
||||
printf("File to file compression/decompression using the low-level tinfl/tdefl API's.\n");
|
||||
printf("Usage: example5 [options] [mode:c or d] infile outfile\n");
|
||||
printf("\nModes:\n");
|
||||
printf("c - Compresses file infile to a zlib stream in file outfile\n");
|
||||
printf("d - Decompress zlib stream in file infile to file outfile\n");
|
||||
printf("\nOptions:\n");
|
||||
printf("-l[0-10] - Compression level, higher values are slower, 0 is none.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (argc < 4)
|
||||
{
|
||||
printf("File to file compression/decompression using the low-level tinfl/tdefl API's.\n");
|
||||
printf("Usage: example5 [options] [mode:c or d] infile outfile\n");
|
||||
printf("\nModes:\n");
|
||||
printf("c - Compresses file infile to a zlib stream in file outfile\n");
|
||||
printf("d - Decompress zlib stream in file infile to file outfile\n");
|
||||
printf("\nOptions:\n");
|
||||
printf("-l[0-10] - Compression level, higher values are slower, 0 is none.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while ((p < argc) && (argv[p][0] == '-'))
|
||||
{
|
||||
switch (argv[p][1])
|
||||
{
|
||||
case 'l':
|
||||
{
|
||||
level = atoi(&argv[1][2]);
|
||||
if ((level < 0) || (level > 10))
|
||||
while ((p < argc) && (argv[p][0] == '-'))
|
||||
{
|
||||
switch (argv[p][1])
|
||||
{
|
||||
case 'l':
|
||||
{
|
||||
printf("Invalid level!\n");
|
||||
return EXIT_FAILURE;
|
||||
level = atoi(&argv[1][2]);
|
||||
if ((level < 0) || (level > 10))
|
||||
{
|
||||
printf("Invalid level!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
printf("Invalid option: %s\n", argv[p]);
|
||||
default:
|
||||
{
|
||||
printf("Invalid option: %s\n", argv[p]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
if ((argc - p) < 3)
|
||||
{
|
||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if ((argc - p) > 3)
|
||||
{
|
||||
printf("Too many filenames!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pMode = argv[p++];
|
||||
if (!strchr("cCdD", pMode[0]))
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pSrc_filename = argv[p++];
|
||||
pDst_filename = argv[p++];
|
||||
|
||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||
|
||||
// Open input file.
|
||||
pInfile = fopen(pSrc_filename, "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Determine input file's size.
|
||||
fseek(pInfile, 0, SEEK_END);
|
||||
file_loc = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
|
||||
{
|
||||
// This is not a limitation of miniz or tinfl, but this example.
|
||||
printf("File is too large to be processed by this example.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
infile_size = (uint)file_loc;
|
||||
|
||||
// Open output file.
|
||||
pOutfile = fopen(pDst_filename, "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Input file size: %u\n", infile_size);
|
||||
|
||||
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
||||
{
|
||||
// The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing.
|
||||
static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
|
||||
|
||||
tdefl_status status;
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
// create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined).
|
||||
mz_uint comp_flags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, level)] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
|
||||
if (!level)
|
||||
comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
|
||||
|
||||
// Initialize the low-level compressor.
|
||||
status = tdefl_init(&g_deflator, NULL, NULL, comp_flags);
|
||||
if (status != TDEFL_STATUS_OKAY)
|
||||
{
|
||||
printf("tdefl_init() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
if ((argc - p) < 3)
|
||||
{
|
||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if ((argc - p) > 3)
|
||||
{
|
||||
printf("Too many filenames!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
avail_out = COMP_OUT_BUF_SIZE;
|
||||
|
||||
pMode = argv[p++];
|
||||
if (!strchr("cCdD", pMode[0]))
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Compression.
|
||||
for (;;)
|
||||
{
|
||||
size_t in_bytes, out_bytes;
|
||||
|
||||
pSrc_filename = argv[p++];
|
||||
pDst_filename = argv[p++];
|
||||
|
||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||
|
||||
// Open input file.
|
||||
pInfile = fopen(pSrc_filename, "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Determine input file's size.
|
||||
fseek(pInfile, 0, SEEK_END);
|
||||
file_loc = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
if ((file_loc < 0) || (file_loc > INT_MAX))
|
||||
{
|
||||
// This is not a limitation of miniz or tinfl, but this example.
|
||||
printf("File is too large to be processed by this example.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
infile_size = (uint)file_loc;
|
||||
|
||||
// Open output file.
|
||||
pOutfile = fopen(pDst_filename, "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Input file size: %u\n", infile_size);
|
||||
|
||||
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
||||
{
|
||||
// The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing.
|
||||
static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
|
||||
|
||||
tdefl_status status;
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
// create tdefl() compatible flags (we have to compose the low-level flags ourselves, or use tdefl_create_comp_flags_from_zip_params() but that means MINIZ_NO_ZLIB_APIS can't be defined).
|
||||
mz_uint comp_flags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, level)] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
|
||||
if (!level)
|
||||
comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
|
||||
|
||||
// Initialize the low-level compressor.
|
||||
status = tdefl_init(&g_deflator, NULL, NULL, comp_flags);
|
||||
if (status != TDEFL_STATUS_OKAY)
|
||||
{
|
||||
printf("tdefl_init() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
avail_out = COMP_OUT_BUF_SIZE;
|
||||
|
||||
// Compression.
|
||||
for ( ; ; )
|
||||
{
|
||||
size_t in_bytes, out_bytes;
|
||||
|
||||
if (!avail_in)
|
||||
{
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(IN_BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
if (!avail_in)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(IN_BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
next_in = s_inbuf;
|
||||
avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
// printf("Input bytes remaining: %u\n", infile_remaining);
|
||||
}
|
||||
|
||||
next_in = s_inbuf;
|
||||
avail_in = n;
|
||||
in_bytes = avail_in;
|
||||
out_bytes = avail_out;
|
||||
// Compress as much of the input as possible (or all of it) to the output buffer.
|
||||
status = tdefl_compress(&g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
|
||||
|
||||
infile_remaining -= n;
|
||||
//printf("Input bytes remaining: %u\n", infile_remaining);
|
||||
}
|
||||
next_in = (const char *)next_in + in_bytes;
|
||||
avail_in -= in_bytes;
|
||||
total_in += in_bytes;
|
||||
|
||||
in_bytes = avail_in;
|
||||
out_bytes = avail_out;
|
||||
// Compress as much of the input as possible (or all of it) to the output buffer.
|
||||
status = tdefl_compress(&g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
|
||||
next_out = (char *)next_out + out_bytes;
|
||||
avail_out -= out_bytes;
|
||||
total_out += out_bytes;
|
||||
|
||||
next_in = (const char *)next_in + in_bytes;
|
||||
avail_in -= in_bytes;
|
||||
total_in += in_bytes;
|
||||
|
||||
next_out = (char *)next_out + out_bytes;
|
||||
avail_out -= out_bytes;
|
||||
total_out += out_bytes;
|
||||
|
||||
if ((status != TDEFL_STATUS_OKAY) || (!avail_out))
|
||||
{
|
||||
// Output buffer is full, or compression is done or failed, so write buffer to output file.
|
||||
uint n = COMP_OUT_BUF_SIZE - (uint)avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
if ((status != TDEFL_STATUS_OKAY) || (!avail_out))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
next_out = s_outbuf;
|
||||
avail_out = COMP_OUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
if (status == TDEFL_STATUS_DONE)
|
||||
{
|
||||
// Compression completed successfully.
|
||||
break;
|
||||
}
|
||||
else if (status != TDEFL_STATUS_OKAY)
|
||||
{
|
||||
// Compression somehow failed.
|
||||
printf("tdefl_compress() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((pMode[0] == 'd') || (pMode[0] == 'D'))
|
||||
{
|
||||
// Decompression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
tinfl_decompressor inflator;
|
||||
tinfl_init(&inflator);
|
||||
|
||||
for ( ; ; )
|
||||
{
|
||||
size_t in_bytes, out_bytes;
|
||||
tinfl_status status;
|
||||
if (!avail_in)
|
||||
{
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(IN_BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
// Output buffer is full, or compression is done or failed, so write buffer to output file.
|
||||
uint n = COMP_OUT_BUF_SIZE - (uint)avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
next_out = s_outbuf;
|
||||
avail_out = COMP_OUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
next_in = s_inbuf;
|
||||
avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
}
|
||||
|
||||
in_bytes = avail_in;
|
||||
out_bytes = avail_out;
|
||||
status = tinfl_decompress(&inflator, (const mz_uint8 *)next_in, &in_bytes, s_outbuf, (mz_uint8 *)next_out, &out_bytes, (infile_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0) | TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||
|
||||
avail_in -= in_bytes;
|
||||
next_in = (const mz_uint8 *)next_in + in_bytes;
|
||||
total_in += in_bytes;
|
||||
|
||||
avail_out -= out_bytes;
|
||||
next_out = (mz_uint8 *)next_out + out_bytes;
|
||||
total_out += out_bytes;
|
||||
|
||||
if ((status <= TINFL_STATUS_DONE) || (!avail_out))
|
||||
{
|
||||
// Output buffer is full, or decompression is done, so write buffer to output file.
|
||||
uint n = OUT_BUF_SIZE - (uint)avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
if (status == TDEFL_STATUS_DONE)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
// Compression completed successfully.
|
||||
break;
|
||||
}
|
||||
next_out = s_outbuf;
|
||||
avail_out = OUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
// If status is <= TINFL_STATUS_DONE then either decompression is done or something went wrong.
|
||||
if (status <= TINFL_STATUS_DONE)
|
||||
{
|
||||
if (status == TINFL_STATUS_DONE)
|
||||
else if (status != TDEFL_STATUS_OKAY)
|
||||
{
|
||||
// Decompression completed successfully.
|
||||
break;
|
||||
// Compression somehow failed.
|
||||
printf("tdefl_compress() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else
|
||||
}
|
||||
}
|
||||
else if ((pMode[0] == 'd') || (pMode[0] == 'D'))
|
||||
{
|
||||
// Decompression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
tinfl_decompressor inflator;
|
||||
tinfl_init(&inflator);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
size_t in_bytes, out_bytes;
|
||||
tinfl_status status;
|
||||
if (!avail_in)
|
||||
{
|
||||
// Decompression failed.
|
||||
printf("tinfl_decompress() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
// Input buffer is empty, so read more bytes from input file.
|
||||
uint n = my_min(IN_BUF_SIZE, infile_remaining);
|
||||
|
||||
if (fread(s_inbuf, 1, n, pInfile) != n)
|
||||
{
|
||||
printf("Failed reading from input file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
next_in = s_inbuf;
|
||||
avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fclose(pInfile);
|
||||
if (EOF == fclose(pOutfile))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
in_bytes = avail_in;
|
||||
out_bytes = avail_out;
|
||||
status = tinfl_decompress(&inflator, (const mz_uint8 *)next_in, &in_bytes, s_outbuf, (mz_uint8 *)next_out, &out_bytes, (infile_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0) | TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||
|
||||
printf("Total input bytes: %u\n", (mz_uint32)total_in);
|
||||
printf("Total output bytes: %u\n", (mz_uint32)total_out);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
avail_in -= in_bytes;
|
||||
next_in = (const mz_uint8 *)next_in + in_bytes;
|
||||
total_in += in_bytes;
|
||||
|
||||
avail_out -= out_bytes;
|
||||
next_out = (mz_uint8 *)next_out + out_bytes;
|
||||
total_out += out_bytes;
|
||||
|
||||
if ((status <= TINFL_STATUS_DONE) || (!avail_out))
|
||||
{
|
||||
// Output buffer is full, or decompression is done, so write buffer to output file.
|
||||
uint n = OUT_BUF_SIZE - (uint)avail_out;
|
||||
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
next_out = s_outbuf;
|
||||
avail_out = OUT_BUF_SIZE;
|
||||
}
|
||||
|
||||
// If status is <= TINFL_STATUS_DONE then either decompression is done or something went wrong.
|
||||
if (status <= TINFL_STATUS_DONE)
|
||||
{
|
||||
if (status == TINFL_STATUS_DONE)
|
||||
{
|
||||
// Decompression completed successfully.
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decompression failed.
|
||||
printf("tinfl_decompress() failed with status %i!\n", status);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fclose(pInfile);
|
||||
if (EOF == fclose(pOutfile))
|
||||
{
|
||||
printf("Failed writing to output file!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Total input bytes: %u\n", (mz_uint32)total_in);
|
||||
printf("Total output bytes: %u\n", (mz_uint32)total_out);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -20,143 +20,170 @@ typedef unsigned int uint;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 r, g, b;
|
||||
uint8 r, g, b;
|
||||
} rgb_t;
|
||||
|
||||
static void hsv_to_rgb(int hue, int min, int max, rgb_t *p)
|
||||
{
|
||||
const int invert = 0;
|
||||
const int saturation = 1;
|
||||
const int color_rotate = 0;
|
||||
const int invert = 0;
|
||||
const int saturation = 1;
|
||||
const int color_rotate = 0;
|
||||
|
||||
if (min == max) max = min + 1;
|
||||
if (invert) hue = max - (hue - min);
|
||||
if (!saturation) {
|
||||
p->r = p->g = p->b = 255 * (max - hue) / (max - min);
|
||||
return;
|
||||
}
|
||||
double h = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6);
|
||||
double c = 255.0f * saturation;
|
||||
double X = c * (1 - fabs(fmod(h, 2) - 1));
|
||||
if (min == max)
|
||||
max = min + 1;
|
||||
if (invert)
|
||||
hue = max - (hue - min);
|
||||
if (!saturation)
|
||||
{
|
||||
p->r = p->g = p->b = 255 * (max - hue) / (max - min);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
const double h_dbl = fmod(color_rotate + 1e-4 + 4.0 * (hue - min) / (max - min), 6);
|
||||
const double c_dbl = 255 * saturation;
|
||||
const double X_dbl = c_dbl * (1 - fabs(fmod(h_dbl, 2) - 1));
|
||||
const int h = (int)h_dbl;
|
||||
const int c = (int)c_dbl;
|
||||
const int X = (int)X_dbl;
|
||||
|
||||
p->r = p->g = p->b = 0;
|
||||
p->r = p->g = p->b = 0;
|
||||
|
||||
switch((int)h) {
|
||||
case 0: p->r = c; p->g = X; return;
|
||||
case 1: p->r = X; p->g = c; return;
|
||||
case 2: p->g = c; p->b = X; return;
|
||||
case 3: p->g = X; p->b = c; return;
|
||||
case 4: p->r = X; p->b = c; return;
|
||||
default:p->r = c; p->b = X;
|
||||
}
|
||||
switch (h)
|
||||
{
|
||||
case 0:
|
||||
p->r = c;
|
||||
p->g = X;
|
||||
return;
|
||||
case 1:
|
||||
p->r = X;
|
||||
p->g = c;
|
||||
return;
|
||||
case 2:
|
||||
p->g = c;
|
||||
p->b = X;
|
||||
return;
|
||||
case 3:
|
||||
p->g = X;
|
||||
p->b = c;
|
||||
return;
|
||||
case 4:
|
||||
p->r = X;
|
||||
p->b = c;
|
||||
return;
|
||||
default:
|
||||
p->r = c;
|
||||
p->b = X;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
(void)argc, (void)argv;
|
||||
// Image resolution
|
||||
const int iXmax = 4096;
|
||||
const int iYmax = 4096;
|
||||
|
||||
// Image resolution
|
||||
const int iXmax = 4096;
|
||||
const int iYmax = 4096;
|
||||
// Output filename
|
||||
static const char *pFilename = "mandelbrot.png";
|
||||
|
||||
// Output filename
|
||||
static const char *pFilename = "mandelbrot.png";
|
||||
int iX, iY;
|
||||
const double CxMin = -2.5;
|
||||
const double CxMax = 1.5;
|
||||
const double CyMin = -2.0;
|
||||
const double CyMax = 2.0;
|
||||
|
||||
int iX, iY;
|
||||
const double CxMin = -2.5;
|
||||
const double CxMax = 1.5;
|
||||
const double CyMin = -2.0;
|
||||
const double CyMax = 2.0;
|
||||
double PixelWidth = (CxMax - CxMin) / iXmax;
|
||||
double PixelHeight = (CyMax - CyMin) / iYmax;
|
||||
|
||||
double PixelWidth = (CxMax - CxMin) / iXmax;
|
||||
double PixelHeight = (CyMax - CyMin) / iYmax;
|
||||
// Z=Zx+Zy*i ; Z0 = 0
|
||||
double Zx, Zy;
|
||||
double Zx2, Zy2; // Zx2=Zx*Zx; Zy2=Zy*Zy
|
||||
|
||||
// Z=Zx+Zy*i ; Z0 = 0
|
||||
double Zx, Zy;
|
||||
double Zx2, Zy2; // Zx2=Zx*Zx; Zy2=Zy*Zy
|
||||
int Iteration;
|
||||
const int IterationMax = 200;
|
||||
|
||||
int Iteration;
|
||||
const int IterationMax = 200;
|
||||
// bail-out value , radius of circle
|
||||
const double EscapeRadius = 2;
|
||||
double ER2 = EscapeRadius * EscapeRadius;
|
||||
|
||||
// bail-out value , radius of circle
|
||||
const double EscapeRadius = 2;
|
||||
double ER2=EscapeRadius * EscapeRadius;
|
||||
uint8 *pImage = (uint8 *)malloc(iXmax * 3 * iYmax);
|
||||
|
||||
uint8 *pImage = (uint8 *)malloc(iXmax * 3 * iYmax);
|
||||
// world ( double) coordinate = parameter plane
|
||||
double Cx, Cy;
|
||||
|
||||
// world ( double) coordinate = parameter plane
|
||||
double Cx,Cy;
|
||||
int MinIter = 9999, MaxIter = 0;
|
||||
|
||||
int MinIter = 9999, MaxIter = 0;
|
||||
(void)argc, (void)argv;
|
||||
|
||||
for(iY = 0; iY < iYmax; iY++)
|
||||
{
|
||||
Cy = CyMin + iY * PixelHeight;
|
||||
if (fabs(Cy) < PixelHeight/2)
|
||||
Cy = 0.0; // Main antenna
|
||||
|
||||
for(iX = 0; iX < iXmax; iX++)
|
||||
for (iY = 0; iY < iYmax; iY++)
|
||||
{
|
||||
uint8 *color = pImage + (iX * 3) + (iY * iXmax * 3);
|
||||
Cy = CyMin + iY * PixelHeight;
|
||||
if (fabs(Cy) < PixelHeight / 2)
|
||||
Cy = 0.0; // Main antenna
|
||||
|
||||
Cx = CxMin + iX * PixelWidth;
|
||||
for (iX = 0; iX < iXmax; iX++)
|
||||
{
|
||||
uint8 *color = pImage + (iX * 3) + (iY * iXmax * 3);
|
||||
|
||||
// initial value of orbit = critical point Z= 0
|
||||
Zx = 0.0;
|
||||
Zy = 0.0;
|
||||
Zx2 = Zx * Zx;
|
||||
Zy2 = Zy * Zy;
|
||||
Cx = CxMin + iX * PixelWidth;
|
||||
|
||||
for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++)
|
||||
{
|
||||
Zy = 2 * Zx * Zy + Cy;
|
||||
Zx =Zx2 - Zy2 + Cx;
|
||||
Zx2 = Zx * Zx;
|
||||
Zy2 = Zy * Zy;
|
||||
};
|
||||
// initial value of orbit = critical point Z= 0
|
||||
Zx = 0.0;
|
||||
Zy = 0.0;
|
||||
Zx2 = Zx * Zx;
|
||||
Zy2 = Zy * Zy;
|
||||
|
||||
color[0] = (uint8)Iteration;
|
||||
color[1] = (uint8)Iteration >> 8;
|
||||
color[2] = 0;
|
||||
for (Iteration = 0; Iteration < IterationMax && ((Zx2 + Zy2) < ER2); Iteration++)
|
||||
{
|
||||
Zy = 2 * Zx * Zy + Cy;
|
||||
Zx = Zx2 - Zy2 + Cx;
|
||||
Zx2 = Zx * Zx;
|
||||
Zy2 = Zy * Zy;
|
||||
};
|
||||
|
||||
if (Iteration < MinIter)
|
||||
MinIter = Iteration;
|
||||
if (Iteration > MaxIter)
|
||||
MaxIter = Iteration;
|
||||
}
|
||||
}
|
||||
color[0] = (uint8)Iteration;
|
||||
color[1] = (uint8)Iteration >> 8;
|
||||
color[2] = 0;
|
||||
|
||||
for(iY = 0; iY < iYmax; iY++)
|
||||
{
|
||||
for(iX = 0; iX < iXmax; iX++)
|
||||
{
|
||||
uint8 *color = (uint8 *)(pImage + (iX * 3) + (iY * iXmax * 3));
|
||||
|
||||
uint Iterations = color[0] | (color[1] << 8U);
|
||||
|
||||
hsv_to_rgb(Iterations, MinIter, MaxIter, (rgb_t *)color);
|
||||
}
|
||||
}
|
||||
|
||||
// Now write the PNG image.
|
||||
{
|
||||
size_t png_data_size = 0;
|
||||
void *pPNG_data = tdefl_write_image_to_png_file_in_memory_ex(pImage, iXmax, iYmax, 3, &png_data_size, 6, MZ_FALSE);
|
||||
if (!pPNG_data)
|
||||
fprintf(stderr, "tdefl_write_image_to_png_file_in_memory_ex() failed!\n");
|
||||
else
|
||||
{
|
||||
FILE *pFile = fopen(pFilename, "wb");
|
||||
fwrite(pPNG_data, 1, png_data_size, pFile);
|
||||
fclose(pFile);
|
||||
printf("Wrote %s\n", pFilename);
|
||||
if (Iteration < MinIter)
|
||||
MinIter = Iteration;
|
||||
if (Iteration > MaxIter)
|
||||
MaxIter = Iteration;
|
||||
}
|
||||
}
|
||||
|
||||
// mz_free() is by default just an alias to free() internally, but if you've overridden miniz's allocation funcs you'll probably need to call mz_free().
|
||||
mz_free(pPNG_data);
|
||||
}
|
||||
for (iY = 0; iY < iYmax; iY++)
|
||||
{
|
||||
for (iX = 0; iX < iXmax; iX++)
|
||||
{
|
||||
uint8 *color = (uint8 *)(pImage + (iX * 3) + (iY * iXmax * 3));
|
||||
|
||||
free(pImage);
|
||||
uint Iterations = color[0] | (color[1] << 8U);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
hsv_to_rgb((int)Iterations, MinIter, MaxIter, (rgb_t *)color);
|
||||
}
|
||||
}
|
||||
|
||||
// Now write the PNG image.
|
||||
{
|
||||
size_t png_data_size = 0;
|
||||
void *pPNG_data = tdefl_write_image_to_png_file_in_memory_ex(pImage, iXmax, iYmax, 3, &png_data_size, 6, MZ_FALSE);
|
||||
if (!pPNG_data)
|
||||
fprintf(stderr, "tdefl_write_image_to_png_file_in_memory_ex() failed!\n");
|
||||
else
|
||||
{
|
||||
FILE *pFile = fopen(pFilename, "wb");
|
||||
fwrite(pPNG_data, 1, png_data_size, pFile);
|
||||
fclose(pFile);
|
||||
printf("Wrote %s\n", pFilename);
|
||||
}
|
||||
|
||||
// mz_free() is by default just an alias to free() internally, but if you've overridden miniz's allocation funcs you'll probably need to call mz_free().
|
||||
mz_free(pPNG_data);
|
||||
}
|
||||
|
||||
free(pImage);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
21
meson.build
Normal file
21
meson.build
Normal file
@ -0,0 +1,21 @@
|
||||
project('miniz', 'c')
|
||||
|
||||
miniz_includes = include_directories('.')
|
||||
|
||||
cfg = configuration_data()
|
||||
cfg.set('MINIZ_EXPORT', '')
|
||||
miniz_export_h = configure_file(output: 'miniz_export.h',
|
||||
configuration: cfg)
|
||||
|
||||
libminiz = static_library('miniz',
|
||||
miniz_export_h, 'miniz.c', 'miniz_zip.c', 'miniz_tinfl.c', 'miniz_tdef.c',
|
||||
include_directories: miniz_includes)
|
||||
|
||||
miniz_dependency = declare_dependency(link_with: libminiz,
|
||||
include_directories: miniz_includes)
|
||||
|
||||
miniz_dep = miniz_dependency # Compatibility for WrapDB users
|
||||
|
||||
if meson.version().version_compare('>= 0.54.0')
|
||||
meson.override_dependency('miniz', miniz_dep)
|
||||
endif
|
||||
933
miniz.c
933
miniz.c
@ -31,38 +31,39 @@ typedef unsigned char mz_validate_uint32[sizeof(mz_uint32) == 4 ? 1 : -1];
|
||||
typedef unsigned char mz_validate_uint64[sizeof(mz_uint64) == 8 ? 1 : -1];
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* ------------------- zlib-style API's */
|
||||
/* ------------------- zlib-style API's */
|
||||
|
||||
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
|
||||
{
|
||||
mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16);
|
||||
size_t block_len = buf_len % 5552;
|
||||
if (!ptr)
|
||||
return MZ_ADLER32_INIT;
|
||||
while (buf_len)
|
||||
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
|
||||
{
|
||||
for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
|
||||
mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16);
|
||||
size_t block_len = buf_len % 5552;
|
||||
if (!ptr)
|
||||
return MZ_ADLER32_INIT;
|
||||
while (buf_len)
|
||||
{
|
||||
s1 += ptr[0], s2 += s1;
|
||||
s1 += ptr[1], s2 += s1;
|
||||
s1 += ptr[2], s2 += s1;
|
||||
s1 += ptr[3], s2 += s1;
|
||||
s1 += ptr[4], s2 += s1;
|
||||
s1 += ptr[5], s2 += s1;
|
||||
s1 += ptr[6], s2 += s1;
|
||||
s1 += ptr[7], s2 += s1;
|
||||
for (i = 0; i + 7 < block_len; i += 8, ptr += 8)
|
||||
{
|
||||
s1 += ptr[0], s2 += s1;
|
||||
s1 += ptr[1], s2 += s1;
|
||||
s1 += ptr[2], s2 += s1;
|
||||
s1 += ptr[3], s2 += s1;
|
||||
s1 += ptr[4], s2 += s1;
|
||||
s1 += ptr[5], s2 += s1;
|
||||
s1 += ptr[6], s2 += s1;
|
||||
s1 += ptr[7], s2 += s1;
|
||||
}
|
||||
for (; i < block_len; ++i)
|
||||
s1 += *ptr++, s2 += s1;
|
||||
s1 %= 65521U, s2 %= 65521U;
|
||||
buf_len -= block_len;
|
||||
block_len = 5552;
|
||||
}
|
||||
for (; i < block_len; ++i)
|
||||
s1 += *ptr++, s2 += s1;
|
||||
s1 %= 65521U, s2 %= 65521U;
|
||||
buf_len -= block_len;
|
||||
block_len = 5552;
|
||||
return (s2 << 16) + s1;
|
||||
}
|
||||
return (s2 << 16) + s1;
|
||||
}
|
||||
|
||||
/* Karl Malbrain's compact CRC-32. See "A compact CCITT crc16 and crc32 C implementation that balances processor cache usage against speed": http://www.geocities.com/malbrain/ */
|
||||
#if 0
|
||||
@ -82,51 +83,56 @@ mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
|
||||
}
|
||||
return ~crcu32;
|
||||
}
|
||||
#elif defined(USE_EXTERNAL_MZCRC)
|
||||
/* If USE_EXTERNAL_CRC is defined, an external module will export the
|
||||
* mz_crc32() symbol for us to use, e.g. an SSE-accelerated version.
|
||||
* Depending on the impl, it may be necessary to ~ the input/output crc values.
|
||||
*/
|
||||
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len);
|
||||
#else
|
||||
/* Faster, but larger CPU cache footprint.
|
||||
*/
|
||||
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
|
||||
{
|
||||
static const mz_uint32 s_crc_table[256] =
|
||||
{
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
|
||||
0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
|
||||
0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
|
||||
0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
|
||||
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
|
||||
0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
|
||||
0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC,
|
||||
0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
||||
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
|
||||
0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
|
||||
0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB,
|
||||
0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA,
|
||||
0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE,
|
||||
0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
|
||||
0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
||||
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409,
|
||||
0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
|
||||
0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739,
|
||||
0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268,
|
||||
0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0,
|
||||
0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8,
|
||||
0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
|
||||
0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
|
||||
0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
|
||||
0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
|
||||
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE,
|
||||
0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
|
||||
0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6,
|
||||
0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
||||
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D,
|
||||
0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
|
||||
0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
|
||||
0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
|
||||
};
|
||||
static const mz_uint32 s_crc_table[256] = {
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535,
|
||||
0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
|
||||
0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D,
|
||||
0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
|
||||
0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4,
|
||||
0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C,
|
||||
0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC,
|
||||
0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
|
||||
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB,
|
||||
0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
|
||||
0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB,
|
||||
0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
|
||||
0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA,
|
||||
0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE,
|
||||
0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A,
|
||||
0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
|
||||
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409,
|
||||
0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
|
||||
0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739,
|
||||
0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
|
||||
0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268,
|
||||
0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0,
|
||||
0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8,
|
||||
0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
|
||||
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF,
|
||||
0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
|
||||
0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7,
|
||||
0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
|
||||
0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE,
|
||||
0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242,
|
||||
0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6,
|
||||
0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
|
||||
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D,
|
||||
0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
|
||||
0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605,
|
||||
0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
|
||||
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
|
||||
};
|
||||
|
||||
mz_uint32 crc32 = (mz_uint32)crc ^ 0xFFFFFFFF;
|
||||
const mz_uint8 *pByte_buf = (const mz_uint8 *)ptr;
|
||||
@ -152,422 +158,459 @@ mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
|
||||
}
|
||||
#endif
|
||||
|
||||
void mz_free(void *p)
|
||||
{
|
||||
MZ_FREE(p);
|
||||
}
|
||||
void mz_free(void *p)
|
||||
{
|
||||
MZ_FREE(p);
|
||||
}
|
||||
|
||||
void *miniz_def_alloc_func(void *opaque, size_t items, size_t size)
|
||||
{
|
||||
(void)opaque, (void)items, (void)size;
|
||||
return MZ_MALLOC(items * size);
|
||||
}
|
||||
void miniz_def_free_func(void *opaque, void *address)
|
||||
{
|
||||
(void)opaque, (void)address;
|
||||
MZ_FREE(address);
|
||||
}
|
||||
void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
|
||||
{
|
||||
(void)opaque, (void)address, (void)items, (void)size;
|
||||
return MZ_REALLOC(address, items * size);
|
||||
}
|
||||
MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size)
|
||||
{
|
||||
(void)opaque, (void)items, (void)size;
|
||||
return MZ_MALLOC(items * size);
|
||||
}
|
||||
MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address)
|
||||
{
|
||||
(void)opaque, (void)address;
|
||||
MZ_FREE(address);
|
||||
}
|
||||
MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size)
|
||||
{
|
||||
(void)opaque, (void)address, (void)items, (void)size;
|
||||
return MZ_REALLOC(address, items * size);
|
||||
}
|
||||
|
||||
const char *mz_version(void)
|
||||
{
|
||||
return MZ_VERSION;
|
||||
}
|
||||
const char *mz_version(void)
|
||||
{
|
||||
return MZ_VERSION;
|
||||
}
|
||||
|
||||
#ifndef MINIZ_NO_ZLIB_APIS
|
||||
|
||||
int mz_deflateInit(mz_streamp pStream, int level)
|
||||
{
|
||||
return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
|
||||
}
|
||||
#ifndef MINIZ_NO_DEFLATE_APIS
|
||||
|
||||
int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
|
||||
{
|
||||
tdefl_compressor *pComp;
|
||||
mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy);
|
||||
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
pStream->data_type = 0;
|
||||
pStream->adler = MZ_ADLER32_INIT;
|
||||
pStream->msg = NULL;
|
||||
pStream->reserved = 0;
|
||||
pStream->total_in = 0;
|
||||
pStream->total_out = 0;
|
||||
if (!pStream->zalloc)
|
||||
pStream->zalloc = miniz_def_alloc_func;
|
||||
if (!pStream->zfree)
|
||||
pStream->zfree = miniz_def_free_func;
|
||||
|
||||
pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor));
|
||||
if (!pComp)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
pStream->state = (struct mz_internal_state *)pComp;
|
||||
|
||||
if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY)
|
||||
int mz_deflateInit(mz_streamp pStream, int level)
|
||||
{
|
||||
mz_deflateEnd(pStream);
|
||||
return MZ_PARAM_ERROR;
|
||||
return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int mz_deflateReset(mz_streamp pStream)
|
||||
{
|
||||
if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree))
|
||||
return MZ_STREAM_ERROR;
|
||||
pStream->total_in = pStream->total_out = 0;
|
||||
tdefl_init((tdefl_compressor *)pStream->state, NULL, NULL, ((tdefl_compressor *)pStream->state)->m_flags);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int mz_deflate(mz_streamp pStream, int flush)
|
||||
{
|
||||
size_t in_bytes, out_bytes;
|
||||
mz_ulong orig_total_in, orig_total_out;
|
||||
int mz_status = MZ_OK;
|
||||
|
||||
if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out))
|
||||
return MZ_STREAM_ERROR;
|
||||
if (!pStream->avail_out)
|
||||
return MZ_BUF_ERROR;
|
||||
|
||||
if (flush == MZ_PARTIAL_FLUSH)
|
||||
flush = MZ_SYNC_FLUSH;
|
||||
|
||||
if (((tdefl_compressor *)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE)
|
||||
return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR;
|
||||
|
||||
orig_total_in = pStream->total_in;
|
||||
orig_total_out = pStream->total_out;
|
||||
for (;;)
|
||||
int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
|
||||
{
|
||||
tdefl_status defl_status;
|
||||
in_bytes = pStream->avail_in;
|
||||
out_bytes = pStream->avail_out;
|
||||
tdefl_compressor *pComp;
|
||||
mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy);
|
||||
|
||||
defl_status = tdefl_compress((tdefl_compressor *)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush);
|
||||
pStream->next_in += (mz_uint)in_bytes;
|
||||
pStream->avail_in -= (mz_uint)in_bytes;
|
||||
pStream->total_in += (mz_uint)in_bytes;
|
||||
pStream->adler = tdefl_get_adler32((tdefl_compressor *)pStream->state);
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
pStream->next_out += (mz_uint)out_bytes;
|
||||
pStream->avail_out -= (mz_uint)out_bytes;
|
||||
pStream->total_out += (mz_uint)out_bytes;
|
||||
pStream->data_type = 0;
|
||||
pStream->adler = MZ_ADLER32_INIT;
|
||||
pStream->msg = NULL;
|
||||
pStream->reserved = 0;
|
||||
pStream->total_in = 0;
|
||||
pStream->total_out = 0;
|
||||
if (!pStream->zalloc)
|
||||
pStream->zalloc = miniz_def_alloc_func;
|
||||
if (!pStream->zfree)
|
||||
pStream->zfree = miniz_def_free_func;
|
||||
|
||||
if (defl_status < 0)
|
||||
pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor));
|
||||
if (!pComp)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
pStream->state = (struct mz_internal_state *)pComp;
|
||||
|
||||
if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY)
|
||||
{
|
||||
mz_status = MZ_STREAM_ERROR;
|
||||
break;
|
||||
mz_deflateEnd(pStream);
|
||||
return MZ_PARAM_ERROR;
|
||||
}
|
||||
else if (defl_status == TDEFL_STATUS_DONE)
|
||||
{
|
||||
mz_status = MZ_STREAM_END;
|
||||
break;
|
||||
}
|
||||
else if (!pStream->avail_out)
|
||||
break;
|
||||
else if ((!pStream->avail_in) && (flush != MZ_FINISH))
|
||||
{
|
||||
if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out))
|
||||
break;
|
||||
return MZ_BUF_ERROR; /* Can't make forward progress without some input.
|
||||
*/
|
||||
}
|
||||
}
|
||||
return mz_status;
|
||||
}
|
||||
|
||||
int mz_deflateEnd(mz_streamp pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (pStream->state)
|
||||
{
|
||||
pStream->zfree(pStream->opaque, pStream->state);
|
||||
pStream->state = NULL;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
|
||||
{
|
||||
(void)pStream;
|
||||
/* This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.) */
|
||||
return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
|
||||
}
|
||||
|
||||
int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
|
||||
{
|
||||
int status;
|
||||
mz_stream stream;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
|
||||
/* In case mz_ulong is 64-bits (argh I hate longs). */
|
||||
if ((source_len | *pDest_len) > 0xFFFFFFFFU)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
stream.next_in = pSource;
|
||||
stream.avail_in = (mz_uint32)source_len;
|
||||
stream.next_out = pDest;
|
||||
stream.avail_out = (mz_uint32) * pDest_len;
|
||||
|
||||
status = mz_deflateInit(&stream, level);
|
||||
if (status != MZ_OK)
|
||||
return status;
|
||||
|
||||
status = mz_deflate(&stream, MZ_FINISH);
|
||||
if (status != MZ_STREAM_END)
|
||||
{
|
||||
mz_deflateEnd(&stream);
|
||||
return (status == MZ_OK) ? MZ_BUF_ERROR : status;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
*pDest_len = stream.total_out;
|
||||
return mz_deflateEnd(&stream);
|
||||
}
|
||||
|
||||
int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
|
||||
{
|
||||
return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
mz_ulong mz_compressBound(mz_ulong source_len)
|
||||
{
|
||||
return mz_deflateBound(NULL, source_len);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tinfl_decompressor m_decomp;
|
||||
mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed;
|
||||
int m_window_bits;
|
||||
mz_uint8 m_dict[TINFL_LZ_DICT_SIZE];
|
||||
tinfl_status m_last_status;
|
||||
} inflate_state;
|
||||
|
||||
int mz_inflateInit2(mz_streamp pStream, int window_bits)
|
||||
{
|
||||
inflate_state *pDecomp;
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
pStream->data_type = 0;
|
||||
pStream->adler = 0;
|
||||
pStream->msg = NULL;
|
||||
pStream->total_in = 0;
|
||||
pStream->total_out = 0;
|
||||
pStream->reserved = 0;
|
||||
if (!pStream->zalloc)
|
||||
pStream->zalloc = miniz_def_alloc_func;
|
||||
if (!pStream->zfree)
|
||||
pStream->zfree = miniz_def_free_func;
|
||||
|
||||
pDecomp = (inflate_state *)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state));
|
||||
if (!pDecomp)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
pStream->state = (struct mz_internal_state *)pDecomp;
|
||||
|
||||
tinfl_init(&pDecomp->m_decomp);
|
||||
pDecomp->m_dict_ofs = 0;
|
||||
pDecomp->m_dict_avail = 0;
|
||||
pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
|
||||
pDecomp->m_first_call = 1;
|
||||
pDecomp->m_has_flushed = 0;
|
||||
pDecomp->m_window_bits = window_bits;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int mz_inflateInit(mz_streamp pStream)
|
||||
{
|
||||
return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
|
||||
}
|
||||
|
||||
int mz_inflate(mz_streamp pStream, int flush)
|
||||
{
|
||||
inflate_state *pState;
|
||||
mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
|
||||
size_t in_bytes, out_bytes, orig_avail_in;
|
||||
tinfl_status status;
|
||||
|
||||
if ((!pStream) || (!pStream->state))
|
||||
return MZ_STREAM_ERROR;
|
||||
if (flush == MZ_PARTIAL_FLUSH)
|
||||
flush = MZ_SYNC_FLUSH;
|
||||
if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH))
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
pState = (inflate_state *)pStream->state;
|
||||
if (pState->m_window_bits > 0)
|
||||
decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
|
||||
orig_avail_in = pStream->avail_in;
|
||||
|
||||
first_call = pState->m_first_call;
|
||||
pState->m_first_call = 0;
|
||||
if (pState->m_last_status < 0)
|
||||
return MZ_DATA_ERROR;
|
||||
|
||||
if (pState->m_has_flushed && (flush != MZ_FINISH))
|
||||
return MZ_STREAM_ERROR;
|
||||
pState->m_has_flushed |= (flush == MZ_FINISH);
|
||||
|
||||
if ((flush == MZ_FINISH) && (first_call))
|
||||
int mz_deflateReset(mz_streamp pStream)
|
||||
{
|
||||
/* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */
|
||||
decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
|
||||
in_bytes = pStream->avail_in;
|
||||
out_bytes = pStream->avail_out;
|
||||
status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
|
||||
pState->m_last_status = status;
|
||||
pStream->next_in += (mz_uint)in_bytes;
|
||||
pStream->avail_in -= (mz_uint)in_bytes;
|
||||
pStream->total_in += (mz_uint)in_bytes;
|
||||
pStream->adler = tinfl_get_adler32(&pState->m_decomp);
|
||||
pStream->next_out += (mz_uint)out_bytes;
|
||||
pStream->avail_out -= (mz_uint)out_bytes;
|
||||
pStream->total_out += (mz_uint)out_bytes;
|
||||
if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree))
|
||||
return MZ_STREAM_ERROR;
|
||||
pStream->total_in = pStream->total_out = 0;
|
||||
tdefl_init((tdefl_compressor *)pStream->state, NULL, NULL, ((tdefl_compressor *)pStream->state)->m_flags);
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
if (status < 0)
|
||||
return MZ_DATA_ERROR;
|
||||
else if (status != TINFL_STATUS_DONE)
|
||||
{
|
||||
pState->m_last_status = TINFL_STATUS_FAILED;
|
||||
int mz_deflate(mz_streamp pStream, int flush)
|
||||
{
|
||||
size_t in_bytes, out_bytes;
|
||||
mz_ulong orig_total_in, orig_total_out;
|
||||
int mz_status = MZ_OK;
|
||||
|
||||
if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out))
|
||||
return MZ_STREAM_ERROR;
|
||||
if (!pStream->avail_out)
|
||||
return MZ_BUF_ERROR;
|
||||
}
|
||||
return MZ_STREAM_END;
|
||||
}
|
||||
/* flush != MZ_FINISH then we must assume there's more input. */
|
||||
if (flush != MZ_FINISH)
|
||||
decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
|
||||
|
||||
if (pState->m_dict_avail)
|
||||
{
|
||||
n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
|
||||
memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
|
||||
pStream->next_out += n;
|
||||
pStream->avail_out -= n;
|
||||
pStream->total_out += n;
|
||||
pState->m_dict_avail -= n;
|
||||
pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
|
||||
return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
|
||||
}
|
||||
if (flush == MZ_PARTIAL_FLUSH)
|
||||
flush = MZ_SYNC_FLUSH;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
in_bytes = pStream->avail_in;
|
||||
out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
|
||||
if (((tdefl_compressor *)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE)
|
||||
return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR;
|
||||
|
||||
status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
|
||||
pState->m_last_status = status;
|
||||
|
||||
pStream->next_in += (mz_uint)in_bytes;
|
||||
pStream->avail_in -= (mz_uint)in_bytes;
|
||||
pStream->total_in += (mz_uint)in_bytes;
|
||||
pStream->adler = tinfl_get_adler32(&pState->m_decomp);
|
||||
|
||||
pState->m_dict_avail = (mz_uint)out_bytes;
|
||||
|
||||
n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
|
||||
memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
|
||||
pStream->next_out += n;
|
||||
pStream->avail_out -= n;
|
||||
pStream->total_out += n;
|
||||
pState->m_dict_avail -= n;
|
||||
pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
|
||||
|
||||
if (status < 0)
|
||||
return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */
|
||||
else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
|
||||
return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */
|
||||
else if (flush == MZ_FINISH)
|
||||
orig_total_in = pStream->total_in;
|
||||
orig_total_out = pStream->total_out;
|
||||
for (;;)
|
||||
{
|
||||
/* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */
|
||||
if (status == TINFL_STATUS_DONE)
|
||||
return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
|
||||
/* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */
|
||||
tdefl_status defl_status;
|
||||
in_bytes = pStream->avail_in;
|
||||
out_bytes = pStream->avail_out;
|
||||
|
||||
defl_status = tdefl_compress((tdefl_compressor *)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush);
|
||||
pStream->next_in += (mz_uint)in_bytes;
|
||||
pStream->avail_in -= (mz_uint)in_bytes;
|
||||
pStream->total_in += (mz_uint)in_bytes;
|
||||
pStream->adler = tdefl_get_adler32((tdefl_compressor *)pStream->state);
|
||||
|
||||
pStream->next_out += (mz_uint)out_bytes;
|
||||
pStream->avail_out -= (mz_uint)out_bytes;
|
||||
pStream->total_out += (mz_uint)out_bytes;
|
||||
|
||||
if (defl_status < 0)
|
||||
{
|
||||
mz_status = MZ_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
else if (defl_status == TDEFL_STATUS_DONE)
|
||||
{
|
||||
mz_status = MZ_STREAM_END;
|
||||
break;
|
||||
}
|
||||
else if (!pStream->avail_out)
|
||||
return MZ_BUF_ERROR;
|
||||
break;
|
||||
else if ((!pStream->avail_in) && (flush != MZ_FINISH))
|
||||
{
|
||||
if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out))
|
||||
break;
|
||||
return MZ_BUF_ERROR; /* Can't make forward progress without some input.
|
||||
*/
|
||||
}
|
||||
}
|
||||
else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
|
||||
break;
|
||||
return mz_status;
|
||||
}
|
||||
|
||||
return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
|
||||
}
|
||||
|
||||
int mz_inflateEnd(mz_streamp pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (pStream->state)
|
||||
int mz_deflateEnd(mz_streamp pStream)
|
||||
{
|
||||
pStream->zfree(pStream->opaque, pStream->state);
|
||||
pStream->state = NULL;
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (pStream->state)
|
||||
{
|
||||
pStream->zfree(pStream->opaque, pStream->state);
|
||||
pStream->state = NULL;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
|
||||
{
|
||||
mz_stream stream;
|
||||
int status;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
|
||||
/* In case mz_ulong is 64-bits (argh I hate longs). */
|
||||
if ((source_len | *pDest_len) > 0xFFFFFFFFU)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
stream.next_in = pSource;
|
||||
stream.avail_in = (mz_uint32)source_len;
|
||||
stream.next_out = pDest;
|
||||
stream.avail_out = (mz_uint32) * pDest_len;
|
||||
|
||||
status = mz_inflateInit(&stream);
|
||||
if (status != MZ_OK)
|
||||
return status;
|
||||
|
||||
status = mz_inflate(&stream, MZ_FINISH);
|
||||
if (status != MZ_STREAM_END)
|
||||
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len)
|
||||
{
|
||||
mz_inflateEnd(&stream);
|
||||
return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status;
|
||||
(void)pStream;
|
||||
/* This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.) */
|
||||
return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5);
|
||||
}
|
||||
*pDest_len = stream.total_out;
|
||||
|
||||
return mz_inflateEnd(&stream);
|
||||
}
|
||||
|
||||
const char *mz_error(int err)
|
||||
{
|
||||
static struct
|
||||
int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
|
||||
{
|
||||
int m_err;
|
||||
const char *m_pDesc;
|
||||
} s_error_descs[] =
|
||||
{
|
||||
{ MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" },
|
||||
{ MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
|
||||
};
|
||||
mz_uint i;
|
||||
for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i)
|
||||
if (s_error_descs[i].m_err == err)
|
||||
return s_error_descs[i].m_pDesc;
|
||||
return NULL;
|
||||
}
|
||||
int status;
|
||||
mz_stream stream;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
|
||||
/* In case mz_ulong is 64-bits (argh I hate longs). */
|
||||
if ((mz_uint64)(source_len | *pDest_len) > 0xFFFFFFFFU)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
stream.next_in = pSource;
|
||||
stream.avail_in = (mz_uint32)source_len;
|
||||
stream.next_out = pDest;
|
||||
stream.avail_out = (mz_uint32)*pDest_len;
|
||||
|
||||
status = mz_deflateInit(&stream, level);
|
||||
if (status != MZ_OK)
|
||||
return status;
|
||||
|
||||
status = mz_deflate(&stream, MZ_FINISH);
|
||||
if (status != MZ_STREAM_END)
|
||||
{
|
||||
mz_deflateEnd(&stream);
|
||||
return (status == MZ_OK) ? MZ_BUF_ERROR : status;
|
||||
}
|
||||
|
||||
*pDest_len = stream.total_out;
|
||||
return mz_deflateEnd(&stream);
|
||||
}
|
||||
|
||||
int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
|
||||
{
|
||||
return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
mz_ulong mz_compressBound(mz_ulong source_len)
|
||||
{
|
||||
return mz_deflateBound(NULL, source_len);
|
||||
}
|
||||
|
||||
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
|
||||
|
||||
#ifndef MINIZ_NO_INFLATE_APIS
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tinfl_decompressor m_decomp;
|
||||
mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed;
|
||||
int m_window_bits;
|
||||
mz_uint8 m_dict[TINFL_LZ_DICT_SIZE];
|
||||
tinfl_status m_last_status;
|
||||
} inflate_state;
|
||||
|
||||
int mz_inflateInit2(mz_streamp pStream, int window_bits)
|
||||
{
|
||||
inflate_state *pDecomp;
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
pStream->data_type = 0;
|
||||
pStream->adler = 0;
|
||||
pStream->msg = NULL;
|
||||
pStream->total_in = 0;
|
||||
pStream->total_out = 0;
|
||||
pStream->reserved = 0;
|
||||
if (!pStream->zalloc)
|
||||
pStream->zalloc = miniz_def_alloc_func;
|
||||
if (!pStream->zfree)
|
||||
pStream->zfree = miniz_def_free_func;
|
||||
|
||||
pDecomp = (inflate_state *)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state));
|
||||
if (!pDecomp)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
pStream->state = (struct mz_internal_state *)pDecomp;
|
||||
|
||||
tinfl_init(&pDecomp->m_decomp);
|
||||
pDecomp->m_dict_ofs = 0;
|
||||
pDecomp->m_dict_avail = 0;
|
||||
pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
|
||||
pDecomp->m_first_call = 1;
|
||||
pDecomp->m_has_flushed = 0;
|
||||
pDecomp->m_window_bits = window_bits;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int mz_inflateInit(mz_streamp pStream)
|
||||
{
|
||||
return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS);
|
||||
}
|
||||
|
||||
int mz_inflateReset(mz_streamp pStream)
|
||||
{
|
||||
inflate_state *pDecomp;
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
pStream->data_type = 0;
|
||||
pStream->adler = 0;
|
||||
pStream->msg = NULL;
|
||||
pStream->total_in = 0;
|
||||
pStream->total_out = 0;
|
||||
pStream->reserved = 0;
|
||||
|
||||
pDecomp = (inflate_state *)pStream->state;
|
||||
|
||||
tinfl_init(&pDecomp->m_decomp);
|
||||
pDecomp->m_dict_ofs = 0;
|
||||
pDecomp->m_dict_avail = 0;
|
||||
pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT;
|
||||
pDecomp->m_first_call = 1;
|
||||
pDecomp->m_has_flushed = 0;
|
||||
/* pDecomp->m_window_bits = window_bits */;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int mz_inflate(mz_streamp pStream, int flush)
|
||||
{
|
||||
inflate_state *pState;
|
||||
mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32;
|
||||
size_t in_bytes, out_bytes, orig_avail_in;
|
||||
tinfl_status status;
|
||||
|
||||
if ((!pStream) || (!pStream->state))
|
||||
return MZ_STREAM_ERROR;
|
||||
if (flush == MZ_PARTIAL_FLUSH)
|
||||
flush = MZ_SYNC_FLUSH;
|
||||
if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH))
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
pState = (inflate_state *)pStream->state;
|
||||
if (pState->m_window_bits > 0)
|
||||
decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER;
|
||||
orig_avail_in = pStream->avail_in;
|
||||
|
||||
first_call = pState->m_first_call;
|
||||
pState->m_first_call = 0;
|
||||
if (pState->m_last_status < 0)
|
||||
return MZ_DATA_ERROR;
|
||||
|
||||
if (pState->m_has_flushed && (flush != MZ_FINISH))
|
||||
return MZ_STREAM_ERROR;
|
||||
pState->m_has_flushed |= (flush == MZ_FINISH);
|
||||
|
||||
if ((flush == MZ_FINISH) && (first_call))
|
||||
{
|
||||
/* MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. */
|
||||
decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF;
|
||||
in_bytes = pStream->avail_in;
|
||||
out_bytes = pStream->avail_out;
|
||||
status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags);
|
||||
pState->m_last_status = status;
|
||||
pStream->next_in += (mz_uint)in_bytes;
|
||||
pStream->avail_in -= (mz_uint)in_bytes;
|
||||
pStream->total_in += (mz_uint)in_bytes;
|
||||
pStream->adler = tinfl_get_adler32(&pState->m_decomp);
|
||||
pStream->next_out += (mz_uint)out_bytes;
|
||||
pStream->avail_out -= (mz_uint)out_bytes;
|
||||
pStream->total_out += (mz_uint)out_bytes;
|
||||
|
||||
if (status < 0)
|
||||
return MZ_DATA_ERROR;
|
||||
else if (status != TINFL_STATUS_DONE)
|
||||
{
|
||||
pState->m_last_status = TINFL_STATUS_FAILED;
|
||||
return MZ_BUF_ERROR;
|
||||
}
|
||||
return MZ_STREAM_END;
|
||||
}
|
||||
/* flush != MZ_FINISH then we must assume there's more input. */
|
||||
if (flush != MZ_FINISH)
|
||||
decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT;
|
||||
|
||||
if (pState->m_dict_avail)
|
||||
{
|
||||
n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
|
||||
memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
|
||||
pStream->next_out += n;
|
||||
pStream->avail_out -= n;
|
||||
pStream->total_out += n;
|
||||
pState->m_dict_avail -= n;
|
||||
pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
|
||||
return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
in_bytes = pStream->avail_in;
|
||||
out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs;
|
||||
|
||||
status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags);
|
||||
pState->m_last_status = status;
|
||||
|
||||
pStream->next_in += (mz_uint)in_bytes;
|
||||
pStream->avail_in -= (mz_uint)in_bytes;
|
||||
pStream->total_in += (mz_uint)in_bytes;
|
||||
pStream->adler = tinfl_get_adler32(&pState->m_decomp);
|
||||
|
||||
pState->m_dict_avail = (mz_uint)out_bytes;
|
||||
|
||||
n = MZ_MIN(pState->m_dict_avail, pStream->avail_out);
|
||||
memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n);
|
||||
pStream->next_out += n;
|
||||
pStream->avail_out -= n;
|
||||
pStream->total_out += n;
|
||||
pState->m_dict_avail -= n;
|
||||
pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1);
|
||||
|
||||
if (status < 0)
|
||||
return MZ_DATA_ERROR; /* Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). */
|
||||
else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in))
|
||||
return MZ_BUF_ERROR; /* Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. */
|
||||
else if (flush == MZ_FINISH)
|
||||
{
|
||||
/* The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. */
|
||||
if (status == TINFL_STATUS_DONE)
|
||||
return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END;
|
||||
/* status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. */
|
||||
else if (!pStream->avail_out)
|
||||
return MZ_BUF_ERROR;
|
||||
}
|
||||
else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail))
|
||||
break;
|
||||
}
|
||||
|
||||
return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK;
|
||||
}
|
||||
|
||||
int mz_inflateEnd(mz_streamp pStream)
|
||||
{
|
||||
if (!pStream)
|
||||
return MZ_STREAM_ERROR;
|
||||
if (pStream->state)
|
||||
{
|
||||
pStream->zfree(pStream->opaque, pStream->state);
|
||||
pStream->state = NULL;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len)
|
||||
{
|
||||
mz_stream stream;
|
||||
int status;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
|
||||
/* In case mz_ulong is 64-bits (argh I hate longs). */
|
||||
if ((mz_uint64)(*pSource_len | *pDest_len) > 0xFFFFFFFFU)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
stream.next_in = pSource;
|
||||
stream.avail_in = (mz_uint32)*pSource_len;
|
||||
stream.next_out = pDest;
|
||||
stream.avail_out = (mz_uint32)*pDest_len;
|
||||
|
||||
status = mz_inflateInit(&stream);
|
||||
if (status != MZ_OK)
|
||||
return status;
|
||||
|
||||
status = mz_inflate(&stream, MZ_FINISH);
|
||||
*pSource_len = *pSource_len - stream.avail_in;
|
||||
if (status != MZ_STREAM_END)
|
||||
{
|
||||
mz_inflateEnd(&stream);
|
||||
return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status;
|
||||
}
|
||||
*pDest_len = stream.total_out;
|
||||
|
||||
return mz_inflateEnd(&stream);
|
||||
}
|
||||
|
||||
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
|
||||
{
|
||||
return mz_uncompress2(pDest, pDest_len, pSource, &source_len);
|
||||
}
|
||||
|
||||
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
|
||||
|
||||
const char *mz_error(int err)
|
||||
{
|
||||
static struct
|
||||
{
|
||||
int m_err;
|
||||
const char *m_pDesc;
|
||||
} s_error_descs[] = {
|
||||
{ MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" }
|
||||
};
|
||||
mz_uint i;
|
||||
for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i)
|
||||
if (s_error_descs[i].m_err == err)
|
||||
return s_error_descs[i].m_pDesc;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /*MINIZ_NO_ZLIB_APIS */
|
||||
|
||||
|
||||
536
miniz.h
536
miniz.h
@ -1,4 +1,4 @@
|
||||
/* miniz.c v1.16 beta r1 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
||||
/* miniz.c 3.0.2 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing
|
||||
See "unlicense" statement at the end of this file.
|
||||
Rich Geldreich <richgel99@gmail.com>, last updated Oct. 13, 2013
|
||||
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
|
||||
@ -24,7 +24,7 @@
|
||||
zlib replacement in many apps:
|
||||
The z_stream struct, optional memory allocation callbacks
|
||||
deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound
|
||||
inflateInit/inflateInit2/inflate/inflateEnd
|
||||
inflateInit/inflateInit2/inflate/inflateReset/inflateEnd
|
||||
compress, compress2, compressBound, uncompress
|
||||
CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines.
|
||||
Supports raw deflate streams or standard zlib streams with adler-32 checking.
|
||||
@ -95,7 +95,7 @@
|
||||
possibility that the archive's central directory could be lost with this method if anything goes wrong, though.
|
||||
|
||||
- ZIP archive support limitations:
|
||||
No zip64 or spanning support. Extraction functions can only handle unencrypted, stored or deflated files.
|
||||
No spanning support. Extraction functions can only handle unencrypted, stored or deflated files.
|
||||
Requires streams capable of seeking.
|
||||
|
||||
* This is a header file library, like stb_image.c. To get only a header file, either cut and paste the
|
||||
@ -112,12 +112,10 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "miniz_common.h"
|
||||
#include "miniz_tdef.h"
|
||||
#include "miniz_tinfl.h"
|
||||
#include "miniz_export.h"
|
||||
|
||||
/* Defines to completely disable specific portions of miniz.c:
|
||||
If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */
|
||||
/* Defines to completely disable specific portions of miniz.c:
|
||||
If all macros here are defined the only functionality remaining will be CRC-32 and adler-32. */
|
||||
|
||||
/* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */
|
||||
/*#define MINIZ_NO_STDIO */
|
||||
@ -127,6 +125,12 @@
|
||||
/* The current downside is the times written to your archives will be from 1979. */
|
||||
/*#define MINIZ_NO_TIME */
|
||||
|
||||
/* Define MINIZ_NO_DEFLATE_APIS to disable all compression API's. */
|
||||
/*#define MINIZ_NO_DEFLATE_APIS */
|
||||
|
||||
/* Define MINIZ_NO_INFLATE_APIS to disable all decompression API's. */
|
||||
/*#define MINIZ_NO_INFLATE_APIS */
|
||||
|
||||
/* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */
|
||||
/*#define MINIZ_NO_ARCHIVE_APIS */
|
||||
|
||||
@ -139,12 +143,20 @@
|
||||
/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */
|
||||
/*#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
|
||||
|
||||
/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
|
||||
/* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
|
||||
Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
|
||||
callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
|
||||
functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */
|
||||
/*#define MINIZ_NO_MALLOC */
|
||||
|
||||
#ifdef MINIZ_NO_INFLATE_APIS
|
||||
#define MINIZ_NO_ARCHIVE_APIS
|
||||
#endif
|
||||
|
||||
#ifdef MINIZ_NO_DEFLATE_APIS
|
||||
#define MINIZ_NO_ARCHIVE_WRITING_APIS
|
||||
#endif
|
||||
|
||||
#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
|
||||
/* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */
|
||||
#define MINIZ_NO_TIME
|
||||
@ -159,240 +171,286 @@
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
|
||||
/* MINIZ_X86_OR_X64_CPU is only used to help set the below macros. */
|
||||
#define MINIZ_X86_OR_X64_CPU 1
|
||||
#else
|
||||
#define MINIZ_X86_OR_X64_CPU 0
|
||||
#endif
|
||||
|
||||
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
|
||||
/* Set MINIZ_LITTLE_ENDIAN only if not set */
|
||||
#if !defined(MINIZ_LITTLE_ENDIAN)
|
||||
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__)
|
||||
|
||||
#if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||
/* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */
|
||||
#define MINIZ_LITTLE_ENDIAN 1
|
||||
#else
|
||||
#define MINIZ_LITTLE_ENDIAN 0
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if MINIZ_X86_OR_X64_CPU
|
||||
#define MINIZ_LITTLE_ENDIAN 1
|
||||
#else
|
||||
#define MINIZ_LITTLE_ENDIAN 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Using unaligned loads and stores causes errors when using UBSan */
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(undefined_behavior_sanitizer)
|
||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */
|
||||
#if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES)
|
||||
#if MINIZ_X86_OR_X64_CPU
|
||||
/* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */
|
||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
|
||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
|
||||
#define MINIZ_UNALIGNED_USE_MEMCPY
|
||||
#else
|
||||
#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
|
||||
/* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). */
|
||||
#define MINIZ_HAS_64BIT_REGISTERS 1
|
||||
#else
|
||||
#define MINIZ_HAS_64BIT_REGISTERS 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* ------------------- zlib-style API Definitions. */
|
||||
/* ------------------- zlib-style API Definitions. */
|
||||
|
||||
/* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! */
|
||||
typedef unsigned long mz_ulong;
|
||||
/* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! */
|
||||
typedef unsigned long mz_ulong;
|
||||
|
||||
/* mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. */
|
||||
void mz_free(void *p);
|
||||
/* mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. */
|
||||
MINIZ_EXPORT void mz_free(void *p);
|
||||
|
||||
#define MZ_ADLER32_INIT (1)
|
||||
/* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */
|
||||
mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
|
||||
/* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */
|
||||
MINIZ_EXPORT mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
|
||||
|
||||
#define MZ_CRC32_INIT (0)
|
||||
/* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */
|
||||
mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
|
||||
/* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */
|
||||
MINIZ_EXPORT mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
|
||||
|
||||
/* Compression strategies. */
|
||||
enum
|
||||
{
|
||||
MZ_DEFAULT_STRATEGY = 0,
|
||||
MZ_FILTERED = 1,
|
||||
MZ_HUFFMAN_ONLY = 2,
|
||||
MZ_RLE = 3,
|
||||
MZ_FIXED = 4
|
||||
};
|
||||
/* Compression strategies. */
|
||||
enum
|
||||
{
|
||||
MZ_DEFAULT_STRATEGY = 0,
|
||||
MZ_FILTERED = 1,
|
||||
MZ_HUFFMAN_ONLY = 2,
|
||||
MZ_RLE = 3,
|
||||
MZ_FIXED = 4
|
||||
};
|
||||
|
||||
/* Method */
|
||||
#define MZ_DEFLATED 8
|
||||
|
||||
/* Heap allocation callbacks.
|
||||
Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */
|
||||
typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
|
||||
typedef void(*mz_free_func)(void *opaque, void *address);
|
||||
typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
|
||||
/* Heap allocation callbacks.
|
||||
Note that mz_alloc_func parameter types purposely differ from zlib's: items/size is size_t, not unsigned long. */
|
||||
typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
|
||||
typedef void (*mz_free_func)(void *opaque, void *address);
|
||||
typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
|
||||
|
||||
/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */
|
||||
enum
|
||||
{
|
||||
MZ_NO_COMPRESSION = 0,
|
||||
MZ_BEST_SPEED = 1,
|
||||
MZ_BEST_COMPRESSION = 9,
|
||||
MZ_UBER_COMPRESSION = 10,
|
||||
MZ_DEFAULT_LEVEL = 6,
|
||||
MZ_DEFAULT_COMPRESSION = -1
|
||||
};
|
||||
/* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */
|
||||
enum
|
||||
{
|
||||
MZ_NO_COMPRESSION = 0,
|
||||
MZ_BEST_SPEED = 1,
|
||||
MZ_BEST_COMPRESSION = 9,
|
||||
MZ_UBER_COMPRESSION = 10,
|
||||
MZ_DEFAULT_LEVEL = 6,
|
||||
MZ_DEFAULT_COMPRESSION = -1
|
||||
};
|
||||
|
||||
#define MZ_VERSION "10.0.0"
|
||||
#define MZ_VERNUM 0xA000
|
||||
#define MZ_VER_MAJOR 10
|
||||
#define MZ_VER_MINOR 0
|
||||
#define MZ_VERSION "11.0.2"
|
||||
#define MZ_VERNUM 0xB002
|
||||
#define MZ_VER_MAJOR 11
|
||||
#define MZ_VER_MINOR 2
|
||||
#define MZ_VER_REVISION 0
|
||||
#define MZ_VER_SUBREVISION 0
|
||||
|
||||
#ifndef MINIZ_NO_ZLIB_APIS
|
||||
|
||||
/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). */
|
||||
enum
|
||||
{
|
||||
MZ_NO_FLUSH = 0,
|
||||
MZ_PARTIAL_FLUSH = 1,
|
||||
MZ_SYNC_FLUSH = 2,
|
||||
MZ_FULL_FLUSH = 3,
|
||||
MZ_FINISH = 4,
|
||||
MZ_BLOCK = 5
|
||||
};
|
||||
/* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). */
|
||||
enum
|
||||
{
|
||||
MZ_NO_FLUSH = 0,
|
||||
MZ_PARTIAL_FLUSH = 1,
|
||||
MZ_SYNC_FLUSH = 2,
|
||||
MZ_FULL_FLUSH = 3,
|
||||
MZ_FINISH = 4,
|
||||
MZ_BLOCK = 5
|
||||
};
|
||||
|
||||
/* Return status codes. MZ_PARAM_ERROR is non-standard. */
|
||||
enum
|
||||
{
|
||||
MZ_OK = 0,
|
||||
MZ_STREAM_END = 1,
|
||||
MZ_NEED_DICT = 2,
|
||||
MZ_ERRNO = -1,
|
||||
MZ_STREAM_ERROR = -2,
|
||||
MZ_DATA_ERROR = -3,
|
||||
MZ_MEM_ERROR = -4,
|
||||
MZ_BUF_ERROR = -5,
|
||||
MZ_VERSION_ERROR = -6,
|
||||
MZ_PARAM_ERROR = -10000
|
||||
};
|
||||
/* Return status codes. MZ_PARAM_ERROR is non-standard. */
|
||||
enum
|
||||
{
|
||||
MZ_OK = 0,
|
||||
MZ_STREAM_END = 1,
|
||||
MZ_NEED_DICT = 2,
|
||||
MZ_ERRNO = -1,
|
||||
MZ_STREAM_ERROR = -2,
|
||||
MZ_DATA_ERROR = -3,
|
||||
MZ_MEM_ERROR = -4,
|
||||
MZ_BUF_ERROR = -5,
|
||||
MZ_VERSION_ERROR = -6,
|
||||
MZ_PARAM_ERROR = -10000
|
||||
};
|
||||
|
||||
/* Window bits */
|
||||
#define MZ_DEFAULT_WINDOW_BITS 15
|
||||
|
||||
struct mz_internal_state;
|
||||
struct mz_internal_state;
|
||||
|
||||
/* Compression/decompression stream struct. */
|
||||
typedef struct mz_stream_s
|
||||
{
|
||||
const unsigned char *next_in; /* pointer to next byte to read */
|
||||
unsigned int avail_in; /* number of bytes available at next_in */
|
||||
mz_ulong total_in; /* total number of bytes consumed so far */
|
||||
/* Compression/decompression stream struct. */
|
||||
typedef struct mz_stream_s
|
||||
{
|
||||
const unsigned char *next_in; /* pointer to next byte to read */
|
||||
unsigned int avail_in; /* number of bytes available at next_in */
|
||||
mz_ulong total_in; /* total number of bytes consumed so far */
|
||||
|
||||
unsigned char *next_out; /* pointer to next byte to write */
|
||||
unsigned int avail_out; /* number of bytes that can be written to next_out */
|
||||
mz_ulong total_out; /* total number of bytes produced so far */
|
||||
unsigned char *next_out; /* pointer to next byte to write */
|
||||
unsigned int avail_out; /* number of bytes that can be written to next_out */
|
||||
mz_ulong total_out; /* total number of bytes produced so far */
|
||||
|
||||
char *msg; /* error msg (unused) */
|
||||
struct mz_internal_state *state; /* internal state, allocated by zalloc/zfree */
|
||||
char *msg; /* error msg (unused) */
|
||||
struct mz_internal_state *state; /* internal state, allocated by zalloc/zfree */
|
||||
|
||||
mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */
|
||||
mz_free_func zfree; /* optional heap free function (defaults to free) */
|
||||
void *opaque; /* heap alloc function user pointer */
|
||||
mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */
|
||||
mz_free_func zfree; /* optional heap free function (defaults to free) */
|
||||
void *opaque; /* heap alloc function user pointer */
|
||||
|
||||
int data_type; /* data_type (unused) */
|
||||
mz_ulong adler; /* adler32 of the source or uncompressed data */
|
||||
mz_ulong reserved; /* not used */
|
||||
} mz_stream;
|
||||
int data_type; /* data_type (unused) */
|
||||
mz_ulong adler; /* adler32 of the source or uncompressed data */
|
||||
mz_ulong reserved; /* not used */
|
||||
} mz_stream;
|
||||
|
||||
typedef mz_stream *mz_streamp;
|
||||
typedef mz_stream *mz_streamp;
|
||||
|
||||
/* Returns the version string of miniz.c. */
|
||||
const char *mz_version(void);
|
||||
/* Returns the version string of miniz.c. */
|
||||
MINIZ_EXPORT const char *mz_version(void);
|
||||
|
||||
/* mz_deflateInit() initializes a compressor with default options: */
|
||||
/* Parameters: */
|
||||
/* pStream must point to an initialized mz_stream struct. */
|
||||
/* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */
|
||||
/* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. */
|
||||
/* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
/* MZ_PARAM_ERROR if the input parameters are bogus. */
|
||||
/* MZ_MEM_ERROR on out of memory. */
|
||||
int mz_deflateInit(mz_streamp pStream, int level);
|
||||
#ifndef MINIZ_NO_DEFLATE_APIS
|
||||
|
||||
/* mz_deflateInit2() is like mz_deflate(), except with more control: */
|
||||
/* Additional parameters: */
|
||||
/* method must be MZ_DEFLATED */
|
||||
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) */
|
||||
/* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */
|
||||
int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
|
||||
/* mz_deflateInit() initializes a compressor with default options: */
|
||||
/* Parameters: */
|
||||
/* pStream must point to an initialized mz_stream struct. */
|
||||
/* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */
|
||||
/* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. */
|
||||
/* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
/* MZ_PARAM_ERROR if the input parameters are bogus. */
|
||||
/* MZ_MEM_ERROR on out of memory. */
|
||||
MINIZ_EXPORT int mz_deflateInit(mz_streamp pStream, int level);
|
||||
|
||||
/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */
|
||||
int mz_deflateReset(mz_streamp pStream);
|
||||
/* mz_deflateInit2() is like mz_deflate(), except with more control: */
|
||||
/* Additional parameters: */
|
||||
/* method must be MZ_DEFLATED */
|
||||
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) */
|
||||
/* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */
|
||||
MINIZ_EXPORT int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
|
||||
|
||||
/* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */
|
||||
/* Parameters: */
|
||||
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
|
||||
/* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full). */
|
||||
/* MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
/* MZ_PARAM_ERROR if one of the parameters is invalid. */
|
||||
/* MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) */
|
||||
int mz_deflate(mz_streamp pStream, int flush);
|
||||
/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */
|
||||
MINIZ_EXPORT int mz_deflateReset(mz_streamp pStream);
|
||||
|
||||
/* mz_deflateEnd() deinitializes a compressor: */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
int mz_deflateEnd(mz_streamp pStream);
|
||||
/* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */
|
||||
/* Parameters: */
|
||||
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
|
||||
/* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full). */
|
||||
/* MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
/* MZ_PARAM_ERROR if one of the parameters is invalid. */
|
||||
/* MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) */
|
||||
MINIZ_EXPORT int mz_deflate(mz_streamp pStream, int flush);
|
||||
|
||||
/* mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. */
|
||||
mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
|
||||
/* mz_deflateEnd() deinitializes a compressor: */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
MINIZ_EXPORT int mz_deflateEnd(mz_streamp pStream);
|
||||
|
||||
/* Single-call compression functions mz_compress() and mz_compress2(): */
|
||||
/* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */
|
||||
int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
|
||||
int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
|
||||
/* mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. */
|
||||
MINIZ_EXPORT mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
|
||||
|
||||
/* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */
|
||||
mz_ulong mz_compressBound(mz_ulong source_len);
|
||||
/* Single-call compression functions mz_compress() and mz_compress2(): */
|
||||
/* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */
|
||||
MINIZ_EXPORT int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
|
||||
MINIZ_EXPORT int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
|
||||
|
||||
/* Initializes a decompressor. */
|
||||
int mz_inflateInit(mz_streamp pStream);
|
||||
/* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */
|
||||
MINIZ_EXPORT mz_ulong mz_compressBound(mz_ulong source_len);
|
||||
|
||||
/* mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: */
|
||||
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
|
||||
int mz_inflateInit2(mz_streamp pStream, int window_bits);
|
||||
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
|
||||
|
||||
/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */
|
||||
/* Parameters: */
|
||||
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
|
||||
/* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */
|
||||
/* On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster). */
|
||||
/* MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data. */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full. */
|
||||
/* MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
/* MZ_DATA_ERROR if the deflate stream is invalid. */
|
||||
/* MZ_PARAM_ERROR if one of the parameters is invalid. */
|
||||
/* MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again */
|
||||
/* with more input data, or with more room in the output buffer (except when using single call decompression, described above). */
|
||||
int mz_inflate(mz_streamp pStream, int flush);
|
||||
#ifndef MINIZ_NO_INFLATE_APIS
|
||||
|
||||
/* Deinitializes a decompressor. */
|
||||
int mz_inflateEnd(mz_streamp pStream);
|
||||
/* Initializes a decompressor. */
|
||||
MINIZ_EXPORT int mz_inflateInit(mz_streamp pStream);
|
||||
|
||||
/* Single-call decompression. */
|
||||
/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
|
||||
int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
|
||||
/* mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: */
|
||||
/* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */
|
||||
MINIZ_EXPORT int mz_inflateInit2(mz_streamp pStream, int window_bits);
|
||||
|
||||
/* Returns a string description of the specified error code, or NULL if the error code is invalid. */
|
||||
const char *mz_error(int err);
|
||||
/* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */
|
||||
MINIZ_EXPORT int mz_inflateReset(mz_streamp pStream);
|
||||
|
||||
/* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */
|
||||
/* Parameters: */
|
||||
/* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */
|
||||
/* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */
|
||||
/* On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster). */
|
||||
/* MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data. */
|
||||
/* Return values: */
|
||||
/* MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full. */
|
||||
/* MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified. */
|
||||
/* MZ_STREAM_ERROR if the stream is bogus. */
|
||||
/* MZ_DATA_ERROR if the deflate stream is invalid. */
|
||||
/* MZ_PARAM_ERROR if one of the parameters is invalid. */
|
||||
/* MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again */
|
||||
/* with more input data, or with more room in the output buffer (except when using single call decompression, described above). */
|
||||
MINIZ_EXPORT int mz_inflate(mz_streamp pStream, int flush);
|
||||
|
||||
/* Deinitializes a decompressor. */
|
||||
MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream);
|
||||
|
||||
/* Single-call decompression. */
|
||||
/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
|
||||
MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
|
||||
MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len);
|
||||
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
|
||||
|
||||
/* Returns a string description of the specified error code, or NULL if the error code is invalid. */
|
||||
MINIZ_EXPORT const char *mz_error(int err);
|
||||
|
||||
/* Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports. */
|
||||
/* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */
|
||||
#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
|
||||
typedef unsigned char Byte;
|
||||
typedef unsigned int uInt;
|
||||
typedef mz_ulong uLong;
|
||||
typedef Byte Bytef;
|
||||
typedef uInt uIntf;
|
||||
typedef char charf;
|
||||
typedef int intf;
|
||||
typedef void *voidpf;
|
||||
typedef uLong uLongf;
|
||||
typedef void *voidp;
|
||||
typedef void *const voidpc;
|
||||
typedef unsigned char Byte;
|
||||
typedef unsigned int uInt;
|
||||
typedef mz_ulong uLong;
|
||||
typedef Byte Bytef;
|
||||
typedef uInt uIntf;
|
||||
typedef char charf;
|
||||
typedef int intf;
|
||||
typedef void *voidpf;
|
||||
typedef uLong uLongf;
|
||||
typedef void *voidp;
|
||||
typedef void *const voidpc;
|
||||
#define Z_NULL 0
|
||||
#define Z_NO_FLUSH MZ_NO_FLUSH
|
||||
#define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
|
||||
@ -421,35 +479,116 @@ typedef void *const voidpc;
|
||||
#define Z_FIXED MZ_FIXED
|
||||
#define Z_DEFLATED MZ_DEFLATED
|
||||
#define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
|
||||
#define alloc_func mz_alloc_func
|
||||
#define free_func mz_free_func
|
||||
/* See mz_alloc_func */
|
||||
typedef void *(*alloc_func)(void *opaque, size_t items, size_t size);
|
||||
/* See mz_free_func */
|
||||
typedef void (*free_func)(void *opaque, void *address);
|
||||
|
||||
#define internal_state mz_internal_state
|
||||
#define z_stream mz_stream
|
||||
#define deflateInit mz_deflateInit
|
||||
#define deflateInit2 mz_deflateInit2
|
||||
#define deflateReset mz_deflateReset
|
||||
#define deflate mz_deflate
|
||||
#define deflateEnd mz_deflateEnd
|
||||
#define deflateBound mz_deflateBound
|
||||
#define compress mz_compress
|
||||
#define compress2 mz_compress2
|
||||
#define compressBound mz_compressBound
|
||||
#define inflateInit mz_inflateInit
|
||||
#define inflateInit2 mz_inflateInit2
|
||||
#define inflate mz_inflate
|
||||
#define inflateEnd mz_inflateEnd
|
||||
#define uncompress mz_uncompress
|
||||
#define crc32 mz_crc32
|
||||
#define adler32 mz_adler32
|
||||
|
||||
#ifndef MINIZ_NO_DEFLATE_APIS
|
||||
/* Compatiblity with zlib API. See called functions for documentation */
|
||||
static int deflateInit(mz_streamp pStream, int level)
|
||||
{
|
||||
return mz_deflateInit(pStream, level);
|
||||
}
|
||||
static int deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy)
|
||||
{
|
||||
return mz_deflateInit2(pStream, level, method, window_bits, mem_level, strategy);
|
||||
}
|
||||
static int deflateReset(mz_streamp pStream)
|
||||
{
|
||||
return mz_deflateReset(pStream);
|
||||
}
|
||||
static int deflate(mz_streamp pStream, int flush)
|
||||
{
|
||||
return mz_deflate(pStream, flush);
|
||||
}
|
||||
static int deflateEnd(mz_streamp pStream)
|
||||
{
|
||||
return mz_deflateEnd(pStream);
|
||||
}
|
||||
static mz_ulong deflateBound(mz_streamp pStream, mz_ulong source_len)
|
||||
{
|
||||
return mz_deflateBound(pStream, source_len);
|
||||
}
|
||||
static int compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
|
||||
{
|
||||
return mz_compress(pDest, pDest_len, pSource, source_len);
|
||||
}
|
||||
static int compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level)
|
||||
{
|
||||
return mz_compress2(pDest, pDest_len, pSource, source_len, level);
|
||||
}
|
||||
static mz_ulong compressBound(mz_ulong source_len)
|
||||
{
|
||||
return mz_compressBound(source_len);
|
||||
}
|
||||
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
|
||||
|
||||
#ifndef MINIZ_NO_INFLATE_APIS
|
||||
/* Compatiblity with zlib API. See called functions for documentation */
|
||||
static int inflateInit(mz_streamp pStream)
|
||||
{
|
||||
return mz_inflateInit(pStream);
|
||||
}
|
||||
|
||||
static int inflateInit2(mz_streamp pStream, int window_bits)
|
||||
{
|
||||
return mz_inflateInit2(pStream, window_bits);
|
||||
}
|
||||
|
||||
static int inflateReset(mz_streamp pStream)
|
||||
{
|
||||
return mz_inflateReset(pStream);
|
||||
}
|
||||
|
||||
static int inflate(mz_streamp pStream, int flush)
|
||||
{
|
||||
return mz_inflate(pStream, flush);
|
||||
}
|
||||
|
||||
static int inflateEnd(mz_streamp pStream)
|
||||
{
|
||||
return mz_inflateEnd(pStream);
|
||||
}
|
||||
|
||||
static int uncompress(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong source_len)
|
||||
{
|
||||
return mz_uncompress(pDest, pDest_len, pSource, source_len);
|
||||
}
|
||||
|
||||
static int uncompress2(unsigned char* pDest, mz_ulong* pDest_len, const unsigned char* pSource, mz_ulong* pSource_len)
|
||||
{
|
||||
return mz_uncompress2(pDest, pDest_len, pSource, pSource_len);
|
||||
}
|
||||
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
|
||||
|
||||
static mz_ulong crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len)
|
||||
{
|
||||
return mz_crc32(crc, ptr, buf_len);
|
||||
}
|
||||
|
||||
static mz_ulong adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len)
|
||||
{
|
||||
return mz_adler32(adler, ptr, buf_len);
|
||||
}
|
||||
|
||||
#define MAX_WBITS 15
|
||||
#define MAX_MEM_LEVEL 9
|
||||
#define zError mz_error
|
||||
|
||||
static const char* zError(int err)
|
||||
{
|
||||
return mz_error(err);
|
||||
}
|
||||
#define ZLIB_VERSION MZ_VERSION
|
||||
#define ZLIB_VERNUM MZ_VERNUM
|
||||
#define ZLIB_VER_MAJOR MZ_VER_MAJOR
|
||||
#define ZLIB_VER_MINOR MZ_VER_MINOR
|
||||
#define ZLIB_VER_REVISION MZ_VER_REVISION
|
||||
#define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
|
||||
|
||||
#define zlibVersion mz_version
|
||||
#define zlib_version mz_version()
|
||||
#endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */
|
||||
@ -459,3 +598,8 @@ typedef void *const voidpc;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "miniz_common.h"
|
||||
#include "miniz_tdef.h"
|
||||
#include "miniz_tinfl.h"
|
||||
#include "miniz_zip.h"
|
||||
13
miniz.pc.in
Normal file
13
miniz.pc.in
Normal file
@ -0,0 +1,13 @@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
|
||||
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@/@PROJECT_NAME@
|
||||
|
||||
Name: @PROJECT_NAME@
|
||||
Description: @PROJECT_DESCRIPTION@
|
||||
Version: @MINIZ_VERSION@
|
||||
URL: @PROJECT_HOMEPAGE_URL@
|
||||
|
||||
Requires:
|
||||
Libs: -L${libdir} -lminiz
|
||||
Cflags: -I${includedir}
|
||||
@ -1,15 +1,17 @@
|
||||
#pragma once
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "miniz_export.h"
|
||||
|
||||
/* ------------------- Types and macros */
|
||||
typedef unsigned char mz_uint8;
|
||||
typedef signed short mz_int16;
|
||||
typedef unsigned short mz_uint16;
|
||||
typedef unsigned int mz_uint32;
|
||||
typedef unsigned int mz_uint;
|
||||
typedef int16_t mz_int16;
|
||||
typedef uint16_t mz_uint16;
|
||||
typedef uint32_t mz_uint32;
|
||||
typedef uint32_t mz_uint;
|
||||
typedef int64_t mz_int64;
|
||||
typedef uint64_t mz_uint64;
|
||||
typedef int mz_bool;
|
||||
@ -34,7 +36,8 @@ typedef int mz_bool;
|
||||
#ifdef MINIZ_NO_TIME
|
||||
typedef struct mz_dummy_time_t_tag
|
||||
{
|
||||
int m_dummy;
|
||||
mz_uint32 m_dummy1;
|
||||
mz_uint32 m_dummy2;
|
||||
} mz_dummy_time_t;
|
||||
#define MZ_TIME_T mz_dummy_time_t
|
||||
#else
|
||||
@ -45,7 +48,7 @@ typedef struct mz_dummy_time_t_tag
|
||||
|
||||
#ifdef MINIZ_NO_MALLOC
|
||||
#define MZ_MALLOC(x) NULL
|
||||
#define MZ_FREE(x) (void) x, ((void)0)
|
||||
#define MZ_FREE(x) (void)x, ((void)0)
|
||||
#define MZ_REALLOC(p, x) NULL
|
||||
#else
|
||||
#define MZ_MALLOC(x) malloc(x)
|
||||
@ -56,8 +59,10 @@ typedef struct mz_dummy_time_t_tag
|
||||
#define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj))
|
||||
#define MZ_CLEAR_ARR(obj) memset((obj), 0, sizeof(obj))
|
||||
#define MZ_CLEAR_PTR(obj) memset((obj), 0, sizeof(*obj))
|
||||
|
||||
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES &&MINIZ_LITTLE_ENDIAN
|
||||
#if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN
|
||||
#define MZ_READ_LE16(p) *((const mz_uint16 *)(p))
|
||||
#define MZ_READ_LE32(p) *((const mz_uint32 *)(p))
|
||||
#else
|
||||
@ -76,12 +81,13 @@ typedef struct mz_dummy_time_t_tag
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size);
|
||||
extern void miniz_def_free_func(void *opaque, void *address);
|
||||
extern void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size);
|
||||
extern MINIZ_EXPORT void *miniz_def_alloc_func(void *opaque, size_t items, size_t size);
|
||||
extern MINIZ_EXPORT void miniz_def_free_func(void *opaque, void *address);
|
||||
extern MINIZ_EXPORT void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size);
|
||||
|
||||
#define MZ_UINT16_MAX (0xFFFFU)
|
||||
#define MZ_UINT32_MAX (0xFFFFFFFFU)
|
||||
|
||||
2310
miniz_tdef.c
2310
miniz_tdef.c
File diff suppressed because it is too large
Load Diff
301
miniz_tdef.h
301
miniz_tdef.h
@ -1,107 +1,112 @@
|
||||
#pragma once
|
||||
#include "miniz_common.h"
|
||||
|
||||
#ifndef MINIZ_NO_DEFLATE_APIS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* ------------------- Low-level Compression API Definitions */
|
||||
|
||||
/* Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). */
|
||||
#ifndef TDEFL_LESS_MEMORY
|
||||
#define TDEFL_LESS_MEMORY 0
|
||||
#endif
|
||||
|
||||
/* tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): */
|
||||
/* TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). */
|
||||
enum
|
||||
{
|
||||
TDEFL_HUFFMAN_ONLY = 0,
|
||||
TDEFL_DEFAULT_MAX_PROBES = 128,
|
||||
TDEFL_MAX_PROBES_MASK = 0xFFF
|
||||
};
|
||||
/* tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): */
|
||||
/* TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). */
|
||||
enum
|
||||
{
|
||||
TDEFL_HUFFMAN_ONLY = 0,
|
||||
TDEFL_DEFAULT_MAX_PROBES = 128,
|
||||
TDEFL_MAX_PROBES_MASK = 0xFFF
|
||||
};
|
||||
|
||||
/* TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. */
|
||||
/* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). */
|
||||
/* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. */
|
||||
/* TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). */
|
||||
/* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) */
|
||||
/* TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. */
|
||||
/* TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. */
|
||||
/* TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. */
|
||||
/* The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK). */
|
||||
enum
|
||||
{
|
||||
TDEFL_WRITE_ZLIB_HEADER = 0x01000,
|
||||
TDEFL_COMPUTE_ADLER32 = 0x02000,
|
||||
TDEFL_GREEDY_PARSING_FLAG = 0x04000,
|
||||
TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
|
||||
TDEFL_RLE_MATCHES = 0x10000,
|
||||
TDEFL_FILTER_MATCHES = 0x20000,
|
||||
TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
|
||||
TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
|
||||
};
|
||||
/* TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. */
|
||||
/* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). */
|
||||
/* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. */
|
||||
/* TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). */
|
||||
/* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) */
|
||||
/* TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. */
|
||||
/* TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. */
|
||||
/* TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. */
|
||||
/* The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK). */
|
||||
enum
|
||||
{
|
||||
TDEFL_WRITE_ZLIB_HEADER = 0x01000,
|
||||
TDEFL_COMPUTE_ADLER32 = 0x02000,
|
||||
TDEFL_GREEDY_PARSING_FLAG = 0x04000,
|
||||
TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
|
||||
TDEFL_RLE_MATCHES = 0x10000,
|
||||
TDEFL_FILTER_MATCHES = 0x20000,
|
||||
TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
|
||||
TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
|
||||
};
|
||||
|
||||
/* High level compression functions: */
|
||||
/* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). */
|
||||
/* On entry: */
|
||||
/* pSrc_buf, src_buf_len: Pointer and size of source block to compress. */
|
||||
/* flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. */
|
||||
/* On return: */
|
||||
/* Function returns a pointer to the compressed data, or NULL on failure. */
|
||||
/* *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. */
|
||||
/* The caller must free() the returned block when it's no longer needed. */
|
||||
void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
|
||||
/* High level compression functions: */
|
||||
/* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). */
|
||||
/* On entry: */
|
||||
/* pSrc_buf, src_buf_len: Pointer and size of source block to compress. */
|
||||
/* flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. */
|
||||
/* On return: */
|
||||
/* Function returns a pointer to the compressed data, or NULL on failure. */
|
||||
/* *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. */
|
||||
/* The caller must free() the returned block when it's no longer needed. */
|
||||
MINIZ_EXPORT void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
|
||||
|
||||
/* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */
|
||||
/* Returns 0 on failure. */
|
||||
size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
|
||||
/* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */
|
||||
/* Returns 0 on failure. */
|
||||
MINIZ_EXPORT size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
|
||||
|
||||
/* Compresses an image to a compressed PNG file in memory. */
|
||||
/* On entry: */
|
||||
/* pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. */
|
||||
/* The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. */
|
||||
/* level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL */
|
||||
/* If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). */
|
||||
/* On return: */
|
||||
/* Function returns a pointer to the compressed data, or NULL on failure. */
|
||||
/* *pLen_out will be set to the size of the PNG image file. */
|
||||
/* The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. */
|
||||
void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
|
||||
void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
|
||||
/* Compresses an image to a compressed PNG file in memory. */
|
||||
/* On entry: */
|
||||
/* pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. */
|
||||
/* The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. */
|
||||
/* level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL */
|
||||
/* If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). */
|
||||
/* On return: */
|
||||
/* Function returns a pointer to the compressed data, or NULL on failure. */
|
||||
/* *pLen_out will be set to the size of the PNG image file. */
|
||||
/* The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. */
|
||||
MINIZ_EXPORT void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip);
|
||||
MINIZ_EXPORT void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
|
||||
|
||||
/* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */
|
||||
typedef mz_bool (*tdefl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser);
|
||||
/* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */
|
||||
typedef mz_bool (*tdefl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser);
|
||||
|
||||
/* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. */
|
||||
mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
|
||||
/* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. */
|
||||
MINIZ_EXPORT mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
|
||||
|
||||
enum
|
||||
{
|
||||
TDEFL_MAX_HUFF_TABLES = 3,
|
||||
TDEFL_MAX_HUFF_SYMBOLS_0 = 288,
|
||||
TDEFL_MAX_HUFF_SYMBOLS_1 = 32,
|
||||
TDEFL_MAX_HUFF_SYMBOLS_2 = 19,
|
||||
TDEFL_LZ_DICT_SIZE = 32768,
|
||||
TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1,
|
||||
TDEFL_MIN_MATCH_LEN = 3,
|
||||
TDEFL_MAX_MATCH_LEN = 258
|
||||
};
|
||||
enum
|
||||
{
|
||||
TDEFL_MAX_HUFF_TABLES = 3,
|
||||
TDEFL_MAX_HUFF_SYMBOLS_0 = 288,
|
||||
TDEFL_MAX_HUFF_SYMBOLS_1 = 32,
|
||||
TDEFL_MAX_HUFF_SYMBOLS_2 = 19,
|
||||
TDEFL_LZ_DICT_SIZE = 32768,
|
||||
TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1,
|
||||
TDEFL_MIN_MATCH_LEN = 3,
|
||||
TDEFL_MAX_MATCH_LEN = 258
|
||||
};
|
||||
|
||||
/* TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes). */
|
||||
#if TDEFL_LESS_MEMORY
|
||||
enum
|
||||
{
|
||||
TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024,
|
||||
TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
|
||||
TDEFL_MAX_HUFF_SYMBOLS = 288,
|
||||
TDEFL_LZ_HASH_BITS = 12,
|
||||
TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
|
||||
TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3,
|
||||
TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS
|
||||
};
|
||||
enum
|
||||
{
|
||||
TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024,
|
||||
TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
|
||||
TDEFL_MAX_HUFF_SYMBOLS = 288,
|
||||
TDEFL_LZ_HASH_BITS = 12,
|
||||
TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
|
||||
TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3,
|
||||
TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS
|
||||
};
|
||||
#else
|
||||
enum
|
||||
{
|
||||
TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024,
|
||||
TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10,
|
||||
TDEFL_OUT_BUF_SIZE = (mz_uint)((TDEFL_LZ_CODE_BUF_SIZE * 13) / 10),
|
||||
TDEFL_MAX_HUFF_SYMBOLS = 288,
|
||||
TDEFL_LZ_HASH_BITS = 15,
|
||||
TDEFL_LEVEL1_HASH_SIZE_MASK = 4095,
|
||||
@ -110,81 +115,85 @@ enum
|
||||
};
|
||||
#endif
|
||||
|
||||
/* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. */
|
||||
typedef enum
|
||||
{
|
||||
TDEFL_STATUS_BAD_PARAM = -2,
|
||||
TDEFL_STATUS_PUT_BUF_FAILED = -1,
|
||||
TDEFL_STATUS_OKAY = 0,
|
||||
TDEFL_STATUS_DONE = 1
|
||||
} tdefl_status;
|
||||
/* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. */
|
||||
typedef enum
|
||||
{
|
||||
TDEFL_STATUS_BAD_PARAM = -2,
|
||||
TDEFL_STATUS_PUT_BUF_FAILED = -1,
|
||||
TDEFL_STATUS_OKAY = 0,
|
||||
TDEFL_STATUS_DONE = 1
|
||||
} tdefl_status;
|
||||
|
||||
/* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */
|
||||
typedef enum
|
||||
{
|
||||
TDEFL_NO_FLUSH = 0,
|
||||
TDEFL_SYNC_FLUSH = 2,
|
||||
TDEFL_FULL_FLUSH = 3,
|
||||
TDEFL_FINISH = 4
|
||||
} tdefl_flush;
|
||||
/* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */
|
||||
typedef enum
|
||||
{
|
||||
TDEFL_NO_FLUSH = 0,
|
||||
TDEFL_SYNC_FLUSH = 2,
|
||||
TDEFL_FULL_FLUSH = 3,
|
||||
TDEFL_FINISH = 4
|
||||
} tdefl_flush;
|
||||
|
||||
/* tdefl's compression state structure. */
|
||||
typedef struct
|
||||
{
|
||||
tdefl_put_buf_func_ptr m_pPut_buf_func;
|
||||
void *m_pPut_buf_user;
|
||||
mz_uint m_flags, m_max_probes[2];
|
||||
int m_greedy_parsing;
|
||||
mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
|
||||
mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
|
||||
mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
|
||||
mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
|
||||
tdefl_status m_prev_return_status;
|
||||
const void *m_pIn_buf;
|
||||
void *m_pOut_buf;
|
||||
size_t *m_pIn_buf_size, *m_pOut_buf_size;
|
||||
tdefl_flush m_flush;
|
||||
const mz_uint8 *m_pSrc;
|
||||
size_t m_src_buf_left, m_out_buf_ofs;
|
||||
mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
|
||||
mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
|
||||
mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
|
||||
mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
|
||||
mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
|
||||
mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
|
||||
mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
|
||||
mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
|
||||
} tdefl_compressor;
|
||||
/* tdefl's compression state structure. */
|
||||
typedef struct
|
||||
{
|
||||
tdefl_put_buf_func_ptr m_pPut_buf_func;
|
||||
void *m_pPut_buf_user;
|
||||
mz_uint m_flags, m_max_probes[2];
|
||||
int m_greedy_parsing;
|
||||
mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
|
||||
mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
|
||||
mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
|
||||
mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish;
|
||||
tdefl_status m_prev_return_status;
|
||||
const void *m_pIn_buf;
|
||||
void *m_pOut_buf;
|
||||
size_t *m_pIn_buf_size, *m_pOut_buf_size;
|
||||
tdefl_flush m_flush;
|
||||
const mz_uint8 *m_pSrc;
|
||||
size_t m_src_buf_left, m_out_buf_ofs;
|
||||
mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
|
||||
mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
|
||||
mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
|
||||
mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
|
||||
mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
|
||||
mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
|
||||
mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
|
||||
mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
|
||||
} tdefl_compressor;
|
||||
|
||||
/* Initializes the compressor. */
|
||||
/* There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. */
|
||||
/* pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. */
|
||||
/* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */
|
||||
/* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */
|
||||
tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
|
||||
/* Initializes the compressor. */
|
||||
/* There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. */
|
||||
/* pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. */
|
||||
/* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */
|
||||
/* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */
|
||||
MINIZ_EXPORT tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
|
||||
|
||||
/* Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. */
|
||||
tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush);
|
||||
/* Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. */
|
||||
MINIZ_EXPORT tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush);
|
||||
|
||||
/* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */
|
||||
/* tdefl_compress_buffer() always consumes the entire input buffer. */
|
||||
tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
|
||||
/* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */
|
||||
/* tdefl_compress_buffer() always consumes the entire input buffer. */
|
||||
MINIZ_EXPORT tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
|
||||
|
||||
tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
|
||||
mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
|
||||
MINIZ_EXPORT tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
|
||||
MINIZ_EXPORT mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
|
||||
|
||||
/* Create tdefl_compress() flags given zlib-style compression parameters. */
|
||||
/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */
|
||||
/* window_bits may be -15 (raw deflate) or 15 (zlib) */
|
||||
/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
|
||||
mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
|
||||
/* Create tdefl_compress() flags given zlib-style compression parameters. */
|
||||
/* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */
|
||||
/* window_bits may be -15 (raw deflate) or 15 (zlib) */
|
||||
/* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */
|
||||
MINIZ_EXPORT mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
|
||||
|
||||
/* Allocate the tdefl_compressor structure in C so that */
|
||||
/* non-C language bindings to tdefl_ API don't need to worry about */
|
||||
/* structure size and allocation mechanism. */
|
||||
tdefl_compressor *tdefl_compressor_alloc();
|
||||
void tdefl_compressor_free(tdefl_compressor *pComp);
|
||||
#ifndef MINIZ_NO_MALLOC
|
||||
/* Allocate the tdefl_compressor structure in C so that */
|
||||
/* non-C language bindings to tdefl_ API don't need to worry about */
|
||||
/* structure size and allocation mechanism. */
|
||||
MINIZ_EXPORT tdefl_compressor *tdefl_compressor_alloc(void);
|
||||
MINIZ_EXPORT void tdefl_compressor_free(tdefl_compressor *pComp);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
|
||||
|
||||
1080
miniz_tinfl.c
1080
miniz_tinfl.c
File diff suppressed because it is too large
Load Diff
192
miniz_tinfl.h
192
miniz_tinfl.h
@ -2,89 +2,93 @@
|
||||
#include "miniz_common.h"
|
||||
/* ------------------- Low-level Decompression API Definitions */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Decompression flags used by tinfl_decompress(). */
|
||||
/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */
|
||||
/* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. */
|
||||
/* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */
|
||||
/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
|
||||
enum
|
||||
{
|
||||
TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
|
||||
TINFL_FLAG_HAS_MORE_INPUT = 2,
|
||||
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
|
||||
TINFL_FLAG_COMPUTE_ADLER32 = 8
|
||||
};
|
||||
#ifndef MINIZ_NO_INFLATE_APIS
|
||||
|
||||
/* High level decompression functions: */
|
||||
/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */
|
||||
/* On entry: */
|
||||
/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */
|
||||
/* On return: */
|
||||
/* Function returns a pointer to the decompressed data, or NULL on failure. */
|
||||
/* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */
|
||||
/* The caller must call mz_free() on the returned block when it's no longer needed. */
|
||||
void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* Decompression flags used by tinfl_decompress(). */
|
||||
/* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */
|
||||
/* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. */
|
||||
/* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */
|
||||
/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
|
||||
enum
|
||||
{
|
||||
TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
|
||||
TINFL_FLAG_HAS_MORE_INPUT = 2,
|
||||
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
|
||||
TINFL_FLAG_COMPUTE_ADLER32 = 8
|
||||
};
|
||||
|
||||
/* High level decompression functions: */
|
||||
/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */
|
||||
/* On entry: */
|
||||
/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */
|
||||
/* On return: */
|
||||
/* Function returns a pointer to the decompressed data, or NULL on failure. */
|
||||
/* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */
|
||||
/* The caller must call mz_free() on the returned block when it's no longer needed. */
|
||||
MINIZ_EXPORT void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
|
||||
|
||||
/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */
|
||||
/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */
|
||||
#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
|
||||
size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
|
||||
MINIZ_EXPORT size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
|
||||
|
||||
/* tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. */
|
||||
/* Returns 1 on success or 0 on failure. */
|
||||
typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser);
|
||||
int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
|
||||
/* tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. */
|
||||
/* Returns 1 on success or 0 on failure. */
|
||||
typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser);
|
||||
MINIZ_EXPORT int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
|
||||
|
||||
struct tinfl_decompressor_tag;
|
||||
typedef struct tinfl_decompressor_tag tinfl_decompressor;
|
||||
struct tinfl_decompressor_tag;
|
||||
typedef struct tinfl_decompressor_tag tinfl_decompressor;
|
||||
|
||||
/* Allocate the tinfl_decompressor structure in C so that */
|
||||
/* non-C language bindings to tinfl_ API don't need to worry about */
|
||||
/* structure size and allocation mechanism. */
|
||||
|
||||
tinfl_decompressor *tinfl_decompressor_alloc();
|
||||
void tinfl_decompressor_free(tinfl_decompressor *pDecomp);
|
||||
#ifndef MINIZ_NO_MALLOC
|
||||
/* Allocate the tinfl_decompressor structure in C so that */
|
||||
/* non-C language bindings to tinfl_ API don't need to worry about */
|
||||
/* structure size and allocation mechanism. */
|
||||
MINIZ_EXPORT tinfl_decompressor *tinfl_decompressor_alloc(void);
|
||||
MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor *pDecomp);
|
||||
#endif
|
||||
|
||||
/* Max size of LZ dictionary. */
|
||||
#define TINFL_LZ_DICT_SIZE 32768
|
||||
|
||||
/* Return status. */
|
||||
typedef enum
|
||||
{
|
||||
/* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
|
||||
/* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
|
||||
/* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
|
||||
TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
|
||||
/* Return status. */
|
||||
typedef enum
|
||||
{
|
||||
/* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
|
||||
/* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
|
||||
/* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
|
||||
TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
|
||||
|
||||
/* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
|
||||
TINFL_STATUS_BAD_PARAM = -3,
|
||||
/* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
|
||||
TINFL_STATUS_BAD_PARAM = -3,
|
||||
|
||||
/* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
|
||||
TINFL_STATUS_ADLER32_MISMATCH = -2,
|
||||
/* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
|
||||
TINFL_STATUS_ADLER32_MISMATCH = -2,
|
||||
|
||||
/* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
|
||||
TINFL_STATUS_FAILED = -1,
|
||||
/* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
|
||||
TINFL_STATUS_FAILED = -1,
|
||||
|
||||
/* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
|
||||
/* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
|
||||
|
||||
/* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
|
||||
/* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
|
||||
TINFL_STATUS_DONE = 0,
|
||||
/* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
|
||||
/* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
|
||||
TINFL_STATUS_DONE = 0,
|
||||
|
||||
/* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
|
||||
/* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
|
||||
/* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
|
||||
TINFL_STATUS_NEEDS_MORE_INPUT = 1,
|
||||
/* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
|
||||
/* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
|
||||
/* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
|
||||
TINFL_STATUS_NEEDS_MORE_INPUT = 1,
|
||||
|
||||
/* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
|
||||
/* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
|
||||
/* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
|
||||
/* so I may need to add some code to address this. */
|
||||
TINFL_STATUS_HAS_MORE_OUTPUT = 2
|
||||
} tinfl_status;
|
||||
/* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
|
||||
/* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
|
||||
/* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
|
||||
/* so I may need to add some code to address this. */
|
||||
TINFL_STATUS_HAS_MORE_OUTPUT = 2
|
||||
} tinfl_status;
|
||||
|
||||
/* Initializes the decompressor to its initial state. */
|
||||
#define tinfl_init(r) \
|
||||
@ -95,48 +99,52 @@ typedef enum
|
||||
MZ_MACRO_END
|
||||
#define tinfl_get_adler32(r) (r)->m_check_adler32
|
||||
|
||||
/* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */
|
||||
/* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */
|
||||
tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
|
||||
/* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */
|
||||
/* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */
|
||||
MINIZ_EXPORT tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags);
|
||||
|
||||
/* Internal/private bits follow. */
|
||||
enum
|
||||
{
|
||||
TINFL_MAX_HUFF_TABLES = 3,
|
||||
TINFL_MAX_HUFF_SYMBOLS_0 = 288,
|
||||
TINFL_MAX_HUFF_SYMBOLS_1 = 32,
|
||||
TINFL_MAX_HUFF_SYMBOLS_2 = 19,
|
||||
TINFL_FAST_LOOKUP_BITS = 10,
|
||||
TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
|
||||
mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
|
||||
} tinfl_huff_table;
|
||||
/* Internal/private bits follow. */
|
||||
enum
|
||||
{
|
||||
TINFL_MAX_HUFF_TABLES = 3,
|
||||
TINFL_MAX_HUFF_SYMBOLS_0 = 288,
|
||||
TINFL_MAX_HUFF_SYMBOLS_1 = 32,
|
||||
TINFL_MAX_HUFF_SYMBOLS_2 = 19,
|
||||
TINFL_FAST_LOOKUP_BITS = 10,
|
||||
TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
|
||||
};
|
||||
|
||||
#if MINIZ_HAS_64BIT_REGISTERS
|
||||
#define TINFL_USE_64BIT_BITBUF 1
|
||||
#else
|
||||
#define TINFL_USE_64BIT_BITBUF 0
|
||||
#endif
|
||||
|
||||
#if TINFL_USE_64BIT_BITBUF
|
||||
typedef mz_uint64 tinfl_bit_buf_t;
|
||||
typedef mz_uint64 tinfl_bit_buf_t;
|
||||
#define TINFL_BITBUF_SIZE (64)
|
||||
#else
|
||||
typedef mz_uint32 tinfl_bit_buf_t;
|
||||
#define TINFL_BITBUF_SIZE (32)
|
||||
#endif
|
||||
|
||||
struct tinfl_decompressor_tag
|
||||
{
|
||||
mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
|
||||
tinfl_bit_buf_t m_bit_buf;
|
||||
size_t m_dist_from_out_buf_start;
|
||||
tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
|
||||
mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
|
||||
};
|
||||
struct tinfl_decompressor_tag
|
||||
{
|
||||
mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES];
|
||||
tinfl_bit_buf_t m_bit_buf;
|
||||
size_t m_dist_from_out_buf_start;
|
||||
mz_int16 m_look_up[TINFL_MAX_HUFF_TABLES][TINFL_FAST_LOOKUP_SIZE];
|
||||
mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
|
||||
mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 * 2];
|
||||
mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 * 2];
|
||||
mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0];
|
||||
mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1];
|
||||
mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2];
|
||||
mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
|
||||
|
||||
8142
miniz_zip.c
8142
miniz_zip.c
File diff suppressed because it is too large
Load Diff
698
miniz_zip.h
698
miniz_zip.h
@ -1,408 +1,454 @@
|
||||
|
||||
#pragma once
|
||||
#include "miniz.h"
|
||||
#include "miniz_common.h"
|
||||
|
||||
/* ------------------- ZIP archive reading/writing */
|
||||
|
||||
#ifndef MINIZ_NO_ARCHIVE_APIS
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
/* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */
|
||||
MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
|
||||
MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
|
||||
MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
|
||||
};
|
||||
enum
|
||||
{
|
||||
/* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */
|
||||
MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024,
|
||||
MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512,
|
||||
MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* Central directory file index. */
|
||||
mz_uint32 m_file_index;
|
||||
typedef struct
|
||||
{
|
||||
/* Central directory file index. */
|
||||
mz_uint32 m_file_index;
|
||||
|
||||
/* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less bytes in the central dir. */
|
||||
mz_uint64 m_central_dir_ofs;
|
||||
/* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less bytes in the central dir. */
|
||||
mz_uint64 m_central_dir_ofs;
|
||||
|
||||
/* These fields are copied directly from the zip's central dir. */
|
||||
mz_uint16 m_version_made_by;
|
||||
mz_uint16 m_version_needed;
|
||||
mz_uint16 m_bit_flag;
|
||||
mz_uint16 m_method;
|
||||
/* These fields are copied directly from the zip's central dir. */
|
||||
mz_uint16 m_version_made_by;
|
||||
mz_uint16 m_version_needed;
|
||||
mz_uint16 m_bit_flag;
|
||||
mz_uint16 m_method;
|
||||
|
||||
#ifndef MINIZ_NO_TIME
|
||||
/* CRC-32 of uncompressed data. */
|
||||
mz_uint32 m_crc32;
|
||||
|
||||
/* File's compressed size. */
|
||||
mz_uint64 m_comp_size;
|
||||
|
||||
/* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */
|
||||
mz_uint64 m_uncomp_size;
|
||||
|
||||
/* Zip internal and external file attributes. */
|
||||
mz_uint16 m_internal_attr;
|
||||
mz_uint32 m_external_attr;
|
||||
|
||||
/* Entry's local header file offset in bytes. */
|
||||
mz_uint64 m_local_header_ofs;
|
||||
|
||||
/* Size of comment in bytes. */
|
||||
mz_uint32 m_comment_size;
|
||||
|
||||
/* MZ_TRUE if the entry appears to be a directory. */
|
||||
mz_bool m_is_directory;
|
||||
|
||||
/* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */
|
||||
mz_bool m_is_encrypted;
|
||||
|
||||
/* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */
|
||||
mz_bool m_is_supported;
|
||||
|
||||
/* Filename. If string ends in '/' it's a subdirectory entry. */
|
||||
/* Guaranteed to be zero terminated, may be truncated to fit. */
|
||||
char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
|
||||
|
||||
/* Comment field. */
|
||||
/* Guaranteed to be zero terminated, may be truncated to fit. */
|
||||
char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
|
||||
|
||||
#ifdef MINIZ_NO_TIME
|
||||
MZ_TIME_T m_padding;
|
||||
#else
|
||||
MZ_TIME_T m_time;
|
||||
#endif
|
||||
} mz_zip_archive_file_stat;
|
||||
|
||||
/* CRC-32 of uncompressed data. */
|
||||
mz_uint32 m_crc32;
|
||||
typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
|
||||
typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
|
||||
typedef mz_bool (*mz_file_needs_keepalive)(void *pOpaque);
|
||||
|
||||
/* File's compressed size. */
|
||||
mz_uint64 m_comp_size;
|
||||
struct mz_zip_internal_state_tag;
|
||||
typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
|
||||
|
||||
/* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */
|
||||
mz_uint64 m_uncomp_size;
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_MODE_INVALID = 0,
|
||||
MZ_ZIP_MODE_READING = 1,
|
||||
MZ_ZIP_MODE_WRITING = 2,
|
||||
MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
|
||||
} mz_zip_mode;
|
||||
|
||||
/* Zip internal and external file attributes. */
|
||||
mz_uint16 m_internal_attr;
|
||||
mz_uint32 m_external_attr;
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
|
||||
MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
|
||||
MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
|
||||
MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
|
||||
MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */
|
||||
MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */
|
||||
MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */
|
||||
MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
|
||||
MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000,
|
||||
/*After adding a compressed file, seek back
|
||||
to local file header and set the correct sizes*/
|
||||
MZ_ZIP_FLAG_WRITE_HEADER_SET_SIZE = 0x20000,
|
||||
MZ_ZIP_FLAG_READ_ALLOW_WRITING = 0x40000
|
||||
} mz_zip_flags;
|
||||
|
||||
/* Entry's local header file offset in bytes. */
|
||||
mz_uint64 m_local_header_ofs;
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_TYPE_INVALID = 0,
|
||||
MZ_ZIP_TYPE_USER,
|
||||
MZ_ZIP_TYPE_MEMORY,
|
||||
MZ_ZIP_TYPE_HEAP,
|
||||
MZ_ZIP_TYPE_FILE,
|
||||
MZ_ZIP_TYPE_CFILE,
|
||||
MZ_ZIP_TOTAL_TYPES
|
||||
} mz_zip_type;
|
||||
|
||||
/* Size of comment in bytes. */
|
||||
mz_uint32 m_comment_size;
|
||||
/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_NO_ERROR = 0,
|
||||
MZ_ZIP_UNDEFINED_ERROR,
|
||||
MZ_ZIP_TOO_MANY_FILES,
|
||||
MZ_ZIP_FILE_TOO_LARGE,
|
||||
MZ_ZIP_UNSUPPORTED_METHOD,
|
||||
MZ_ZIP_UNSUPPORTED_ENCRYPTION,
|
||||
MZ_ZIP_UNSUPPORTED_FEATURE,
|
||||
MZ_ZIP_FAILED_FINDING_CENTRAL_DIR,
|
||||
MZ_ZIP_NOT_AN_ARCHIVE,
|
||||
MZ_ZIP_INVALID_HEADER_OR_CORRUPTED,
|
||||
MZ_ZIP_UNSUPPORTED_MULTIDISK,
|
||||
MZ_ZIP_DECOMPRESSION_FAILED,
|
||||
MZ_ZIP_COMPRESSION_FAILED,
|
||||
MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE,
|
||||
MZ_ZIP_CRC_CHECK_FAILED,
|
||||
MZ_ZIP_UNSUPPORTED_CDIR_SIZE,
|
||||
MZ_ZIP_ALLOC_FAILED,
|
||||
MZ_ZIP_FILE_OPEN_FAILED,
|
||||
MZ_ZIP_FILE_CREATE_FAILED,
|
||||
MZ_ZIP_FILE_WRITE_FAILED,
|
||||
MZ_ZIP_FILE_READ_FAILED,
|
||||
MZ_ZIP_FILE_CLOSE_FAILED,
|
||||
MZ_ZIP_FILE_SEEK_FAILED,
|
||||
MZ_ZIP_FILE_STAT_FAILED,
|
||||
MZ_ZIP_INVALID_PARAMETER,
|
||||
MZ_ZIP_INVALID_FILENAME,
|
||||
MZ_ZIP_BUF_TOO_SMALL,
|
||||
MZ_ZIP_INTERNAL_ERROR,
|
||||
MZ_ZIP_FILE_NOT_FOUND,
|
||||
MZ_ZIP_ARCHIVE_TOO_LARGE,
|
||||
MZ_ZIP_VALIDATION_FAILED,
|
||||
MZ_ZIP_WRITE_CALLBACK_FAILED,
|
||||
MZ_ZIP_TOTAL_ERRORS
|
||||
} mz_zip_error;
|
||||
|
||||
/* MZ_TRUE if the entry appears to be a directory. */
|
||||
mz_bool m_is_directory;
|
||||
typedef struct
|
||||
{
|
||||
mz_uint64 m_archive_size;
|
||||
mz_uint64 m_central_directory_file_ofs;
|
||||
|
||||
/* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */
|
||||
mz_bool m_is_encrypted;
|
||||
/* We only support up to UINT32_MAX files in zip64 mode. */
|
||||
mz_uint32 m_total_files;
|
||||
mz_zip_mode m_zip_mode;
|
||||
mz_zip_type m_zip_type;
|
||||
mz_zip_error m_last_error;
|
||||
|
||||
/* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */
|
||||
mz_bool m_is_supported;
|
||||
mz_uint64 m_file_offset_alignment;
|
||||
|
||||
/* Filename. If string ends in '/' it's a subdirectory entry. */
|
||||
/* Guaranteed to be zero terminated, may be truncated to fit. */
|
||||
char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
|
||||
mz_alloc_func m_pAlloc;
|
||||
mz_free_func m_pFree;
|
||||
mz_realloc_func m_pRealloc;
|
||||
void *m_pAlloc_opaque;
|
||||
|
||||
/* Comment field. */
|
||||
/* Guaranteed to be zero terminated, may be truncated to fit. */
|
||||
char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
|
||||
mz_file_read_func m_pRead;
|
||||
mz_file_write_func m_pWrite;
|
||||
mz_file_needs_keepalive m_pNeeds_keepalive;
|
||||
void *m_pIO_opaque;
|
||||
|
||||
} mz_zip_archive_file_stat;
|
||||
mz_zip_internal_state *m_pState;
|
||||
|
||||
typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
|
||||
typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
|
||||
typedef mz_bool (*mz_file_needs_keepalive)(void *pOpaque);
|
||||
} mz_zip_archive;
|
||||
|
||||
struct mz_zip_internal_state_tag;
|
||||
typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
|
||||
typedef struct
|
||||
{
|
||||
mz_zip_archive *pZip;
|
||||
mz_uint flags;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_MODE_INVALID = 0,
|
||||
MZ_ZIP_MODE_READING = 1,
|
||||
MZ_ZIP_MODE_WRITING = 2,
|
||||
MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
|
||||
} mz_zip_mode;
|
||||
int status;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
|
||||
MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
|
||||
MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
|
||||
MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800,
|
||||
MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */
|
||||
MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */
|
||||
MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* use the zip64 file format, instead of the original zip file format */
|
||||
MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000,
|
||||
MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000
|
||||
} mz_zip_flags;
|
||||
mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs;
|
||||
mz_zip_archive_file_stat file_stat;
|
||||
void *pRead_buf;
|
||||
void *pWrite_buf;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_TYPE_INVALID = 0,
|
||||
MZ_ZIP_TYPE_USER,
|
||||
MZ_ZIP_TYPE_MEMORY,
|
||||
MZ_ZIP_TYPE_HEAP,
|
||||
MZ_ZIP_TYPE_FILE,
|
||||
MZ_ZIP_TYPE_CFILE,
|
||||
MZ_ZIP_TOTAL_TYPES
|
||||
} mz_zip_type;
|
||||
size_t out_blk_remain;
|
||||
|
||||
/* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */
|
||||
typedef enum
|
||||
{
|
||||
MZ_ZIP_NO_ERROR = 0,
|
||||
MZ_ZIP_UNDEFINED_ERROR,
|
||||
MZ_ZIP_TOO_MANY_FILES,
|
||||
MZ_ZIP_FILE_TOO_LARGE,
|
||||
MZ_ZIP_UNSUPPORTED_METHOD,
|
||||
MZ_ZIP_UNSUPPORTED_ENCRYPTION,
|
||||
MZ_ZIP_UNSUPPORTED_FEATURE,
|
||||
MZ_ZIP_FAILED_FINDING_CENTRAL_DIR,
|
||||
MZ_ZIP_NOT_AN_ARCHIVE,
|
||||
MZ_ZIP_INVALID_HEADER_OR_CORRUPTED,
|
||||
MZ_ZIP_UNSUPPORTED_MULTIDISK,
|
||||
MZ_ZIP_DECOMPRESSION_FAILED,
|
||||
MZ_ZIP_COMPRESSION_FAILED,
|
||||
MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE,
|
||||
MZ_ZIP_CRC_CHECK_FAILED,
|
||||
MZ_ZIP_UNSUPPORTED_CDIR_SIZE,
|
||||
MZ_ZIP_ALLOC_FAILED,
|
||||
MZ_ZIP_FILE_OPEN_FAILED,
|
||||
MZ_ZIP_FILE_CREATE_FAILED,
|
||||
MZ_ZIP_FILE_WRITE_FAILED,
|
||||
MZ_ZIP_FILE_READ_FAILED,
|
||||
MZ_ZIP_FILE_CLOSE_FAILED,
|
||||
MZ_ZIP_FILE_SEEK_FAILED,
|
||||
MZ_ZIP_FILE_STAT_FAILED,
|
||||
MZ_ZIP_INVALID_PARAMETER,
|
||||
MZ_ZIP_INVALID_FILENAME,
|
||||
MZ_ZIP_BUF_TOO_SMALL,
|
||||
MZ_ZIP_INTERNAL_ERROR,
|
||||
MZ_ZIP_FILE_NOT_FOUND,
|
||||
MZ_ZIP_ARCHIVE_TOO_LARGE,
|
||||
MZ_ZIP_VALIDATION_FAILED,
|
||||
MZ_ZIP_WRITE_CALLBACK_FAILED,
|
||||
MZ_ZIP_TOTAL_ERRORS
|
||||
} mz_zip_error;
|
||||
tinfl_decompressor inflator;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
mz_uint64 m_archive_size;
|
||||
mz_uint64 m_central_directory_file_ofs;
|
||||
|
||||
/* We only support up to UINT32_MAX files in zip64 mode. */
|
||||
mz_uint32 m_total_files;
|
||||
mz_zip_mode m_zip_mode;
|
||||
mz_zip_type m_zip_type;
|
||||
mz_zip_error m_last_error;
|
||||
|
||||
mz_uint64 m_file_offset_alignment;
|
||||
|
||||
mz_alloc_func m_pAlloc;
|
||||
mz_free_func m_pFree;
|
||||
mz_realloc_func m_pRealloc;
|
||||
void *m_pAlloc_opaque;
|
||||
|
||||
mz_file_read_func m_pRead;
|
||||
mz_file_write_func m_pWrite;
|
||||
mz_file_needs_keepalive m_pNeeds_keepalive;
|
||||
void *m_pIO_opaque;
|
||||
|
||||
mz_zip_internal_state *m_pState;
|
||||
|
||||
} mz_zip_archive;
|
||||
|
||||
/* -------- ZIP reading */
|
||||
|
||||
/* Inits a ZIP archive reader. */
|
||||
/* These functions read and validate the archive's central directory. */
|
||||
mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags);
|
||||
|
||||
mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags);
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
/* Read a archive from a disk file. */
|
||||
/* file_start_ofs is the file offset where the archive actually begins, or 0. */
|
||||
/* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */
|
||||
mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
|
||||
mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
|
||||
|
||||
/* Read an archive from an already opened FILE, beginning at the current file position. */
|
||||
/* The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. */
|
||||
/* The FILE will NOT be closed when mz_zip_reader_end() is called. */
|
||||
mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags);
|
||||
#ifdef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
|
||||
mz_uint padding;
|
||||
#else
|
||||
mz_uint file_crc32;
|
||||
#endif
|
||||
|
||||
/* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */
|
||||
mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
|
||||
} mz_zip_reader_extract_iter_state;
|
||||
|
||||
/* -------- ZIP reading or writing */
|
||||
/* -------- ZIP reading */
|
||||
|
||||
/* Clears a mz_zip_archive struct to all zeros. */
|
||||
/* Important: This must be done before passing the struct to any mz_zip functions. */
|
||||
void mz_zip_zero_struct(mz_zip_archive *pZip);
|
||||
/* Inits a ZIP archive reader. */
|
||||
/* These functions read and validate the archive's central directory. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags);
|
||||
|
||||
mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip);
|
||||
mz_zip_type mz_zip_get_type(mz_zip_archive *pZip);
|
||||
|
||||
/* Returns the total number of files in the archive. */
|
||||
mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
|
||||
|
||||
mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip);
|
||||
mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip);
|
||||
MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip);
|
||||
|
||||
/* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */
|
||||
size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n);
|
||||
|
||||
/* Attempts to locates a file in the archive's central directory. */
|
||||
/* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */
|
||||
/* Returns -1 if the file cannot be found. */
|
||||
int mz_zip_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
|
||||
/* Returns MZ_FALSE if the file cannot be found. */
|
||||
mz_bool mz_zip_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *pIndex);
|
||||
|
||||
/* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */
|
||||
/* Note that the m_last_error functionality is not thread safe. */
|
||||
mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num);
|
||||
mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip);
|
||||
mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip);
|
||||
mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip);
|
||||
const char *mz_zip_get_error_string(mz_zip_error mz_err);
|
||||
|
||||
/* MZ_TRUE if the archive file entry is a directory entry. */
|
||||
mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
|
||||
|
||||
/* MZ_TRUE if the file is encrypted/strong encrypted. */
|
||||
mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
|
||||
|
||||
/* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */
|
||||
mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index);
|
||||
|
||||
/* Retrieves the filename of an archive file entry. */
|
||||
/* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. */
|
||||
mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
|
||||
|
||||
/* Attempts to locates a file in the archive's central directory. */
|
||||
/* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */
|
||||
/* Returns -1 if the file cannot be found. */
|
||||
int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
|
||||
int mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index);
|
||||
|
||||
/* Returns detailed information about an archive file entry. */
|
||||
mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
|
||||
|
||||
/* MZ_TRUE if the file is in zip64 format. */
|
||||
/* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */
|
||||
mz_bool mz_zip_is_zip64(mz_zip_archive *pZip);
|
||||
|
||||
/* Returns the total central directory size in bytes. */
|
||||
/* The current max supported size is <= MZ_UINT32_MAX. */
|
||||
size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip);
|
||||
|
||||
/* Extracts a archive file to a memory buffer using no memory allocation. */
|
||||
/* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */
|
||||
mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
|
||||
mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
|
||||
|
||||
/* Extracts a archive file to a memory buffer. */
|
||||
mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
|
||||
mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
|
||||
|
||||
/* Extracts a archive file to a dynamically allocated heap buffer. */
|
||||
/* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */
|
||||
/* Returns NULL and sets the last error on failure. */
|
||||
void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
|
||||
void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
|
||||
|
||||
/* Extracts a archive file using a callback function to output the file's data. */
|
||||
mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
|
||||
mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags);
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
/* Extracts a archive file to a disk file and sets its last accessed and modified times. */
|
||||
/* This function only extracts files, not archive directory records. */
|
||||
mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
|
||||
mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
|
||||
/* Read a archive from a disk file. */
|
||||
/* file_start_ofs is the file offset where the archive actually begins, or 0. */
|
||||
/* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size);
|
||||
|
||||
/* Extracts a archive file starting at the current position in the destination FILE stream. */
|
||||
mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags);
|
||||
mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags);
|
||||
/* Read an archive from an already opened FILE, beginning at the current file position. */
|
||||
/* The archive is assumed to be archive_size bytes long. If archive_size is 0, then the entire rest of the file is assumed to contain the archive. */
|
||||
/* The FILE will NOT be closed when mz_zip_reader_end() is called. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags);
|
||||
#endif
|
||||
|
||||
/* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
|
||||
|
||||
/* -------- ZIP reading or writing */
|
||||
|
||||
/* Clears a mz_zip_archive struct to all zeros. */
|
||||
/* Important: This must be done before passing the struct to any mz_zip functions. */
|
||||
MINIZ_EXPORT void mz_zip_zero_struct(mz_zip_archive *pZip);
|
||||
|
||||
MINIZ_EXPORT mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip);
|
||||
MINIZ_EXPORT mz_zip_type mz_zip_get_type(mz_zip_archive *pZip);
|
||||
|
||||
/* Returns the total number of files in the archive. */
|
||||
MINIZ_EXPORT mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
|
||||
|
||||
MINIZ_EXPORT mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip);
|
||||
MINIZ_EXPORT mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip);
|
||||
MINIZ_EXPORT MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip);
|
||||
|
||||
/* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */
|
||||
MINIZ_EXPORT size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n);
|
||||
|
||||
/* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */
|
||||
/* Note that the m_last_error functionality is not thread safe. */
|
||||
MINIZ_EXPORT mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num);
|
||||
MINIZ_EXPORT mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip);
|
||||
MINIZ_EXPORT mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip);
|
||||
MINIZ_EXPORT mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip);
|
||||
MINIZ_EXPORT const char *mz_zip_get_error_string(mz_zip_error mz_err);
|
||||
|
||||
/* MZ_TRUE if the archive file entry is a directory entry. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
|
||||
|
||||
/* MZ_TRUE if the file is encrypted/strong encrypted. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
|
||||
|
||||
/* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index);
|
||||
|
||||
/* Retrieves the filename of an archive file entry. */
|
||||
/* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. */
|
||||
MINIZ_EXPORT mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
|
||||
|
||||
/* Attempts to locates a file in the archive's central directory. */
|
||||
/* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */
|
||||
/* Returns -1 if the file cannot be found. */
|
||||
MINIZ_EXPORT int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index);
|
||||
|
||||
/* Returns detailed information about an archive file entry. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
|
||||
|
||||
/* MZ_TRUE if the file is in zip64 format. */
|
||||
/* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_is_zip64(mz_zip_archive *pZip);
|
||||
|
||||
/* Returns the total central directory size in bytes. */
|
||||
/* The current max supported size is <= MZ_UINT32_MAX. */
|
||||
MINIZ_EXPORT size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip);
|
||||
|
||||
/* Extracts a archive file to a memory buffer using no memory allocation. */
|
||||
/* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size);
|
||||
|
||||
/* Extracts a archive file to a memory buffer. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags);
|
||||
|
||||
/* Extracts a archive file to a dynamically allocated heap buffer. */
|
||||
/* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */
|
||||
/* Returns NULL and sets the last error on failure. */
|
||||
MINIZ_EXPORT void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
|
||||
MINIZ_EXPORT void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
|
||||
|
||||
/* Extracts a archive file using a callback function to output the file's data. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags);
|
||||
|
||||
/* Extract a file iteratively */
|
||||
MINIZ_EXPORT mz_zip_reader_extract_iter_state *mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
|
||||
MINIZ_EXPORT mz_zip_reader_extract_iter_state *mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
|
||||
MINIZ_EXPORT size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state *pState, void *pvBuf, size_t buf_size);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state *pState);
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
/* Extracts a archive file to a disk file and sets its last accessed and modified times. */
|
||||
/* This function only extracts files, not archive directory records. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
|
||||
|
||||
/* Extracts a archive file starting at the current position in the destination FILE stream. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* TODO */
|
||||
typedef void *mz_zip_streaming_extract_state_ptr;
|
||||
mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
|
||||
uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
||||
uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
||||
mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs);
|
||||
mz_uint64 mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
||||
mz_uint64 mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
||||
mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, mz_uint64 new_ofs);
|
||||
size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size);
|
||||
mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState);
|
||||
#endif
|
||||
|
||||
/* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */
|
||||
/* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */
|
||||
mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
|
||||
/* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */
|
||||
/* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags);
|
||||
|
||||
/* Validates an entire archive by calling mz_zip_validate_file() on each file. */
|
||||
mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags);
|
||||
/* Validates an entire archive by calling mz_zip_validate_file() on each file. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags);
|
||||
|
||||
/* Misc utils/helpers, valid for ZIP reading or writing */
|
||||
mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr);
|
||||
mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr);
|
||||
/* Misc utils/helpers, valid for ZIP reading or writing */
|
||||
MINIZ_EXPORT mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr);
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
MINIZ_EXPORT mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr);
|
||||
#endif
|
||||
|
||||
/* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */
|
||||
mz_bool mz_zip_end(mz_zip_archive *pZip);
|
||||
/* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */
|
||||
MINIZ_EXPORT mz_bool mz_zip_end(mz_zip_archive *pZip);
|
||||
|
||||
/* -------- ZIP writing */
|
||||
/* -------- ZIP writing */
|
||||
|
||||
#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
|
||||
|
||||
/* Inits a ZIP archive writer. */
|
||||
mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
|
||||
mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags);
|
||||
mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
|
||||
mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags);
|
||||
/* Inits a ZIP archive writer. */
|
||||
/*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/
|
||||
/*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags);
|
||||
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags);
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
|
||||
mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
|
||||
mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags);
|
||||
#endif
|
||||
|
||||
/* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */
|
||||
/* For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called. */
|
||||
/* For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it). */
|
||||
/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */
|
||||
/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */
|
||||
/* the archive is finalized the file's central directory will be hosed. */
|
||||
mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
|
||||
mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
|
||||
/* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */
|
||||
/* For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called. */
|
||||
/* For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it). */
|
||||
/* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */
|
||||
/* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */
|
||||
/* the archive is finalized the file's central directory will be hosed. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags);
|
||||
|
||||
/* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */
|
||||
/* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */
|
||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||
mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
|
||||
/* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */
|
||||
/* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */
|
||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags);
|
||||
|
||||
/* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */
|
||||
/* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */
|
||||
mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
|
||||
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
|
||||
/* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */
|
||||
/* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
|
||||
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
|
||||
|
||||
mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
|
||||
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags,
|
||||
mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||
|
||||
/* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */
|
||||
/* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void *callback_opaque, mz_uint64 max_size,
|
||||
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
|
||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||
mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
|
||||
/* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */
|
||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
|
||||
|
||||
/* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */
|
||||
mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add,
|
||||
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||
/* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 max_size,
|
||||
const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len,
|
||||
const char *user_extra_data_central, mz_uint user_extra_data_central_len);
|
||||
#endif
|
||||
|
||||
/* Adds a file to an archive by fully cloning the data from another archive. */
|
||||
/* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */
|
||||
mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index);
|
||||
/* Adds a file to an archive by fully cloning the data from another archive. */
|
||||
/* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index);
|
||||
|
||||
/* Finalizes the archive by writing the central directory records followed by the end of central directory record. */
|
||||
/* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */
|
||||
/* An archive must be manually finalized by calling this function for it to be valid. */
|
||||
mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
|
||||
/* Finalizes the archive by writing the central directory records followed by the end of central directory record. */
|
||||
/* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */
|
||||
/* An archive must be manually finalized by calling this function for it to be valid. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
|
||||
|
||||
/* Finalizes a heap archive, returning a poiner to the heap block and its size. */
|
||||
/* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */
|
||||
mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize);
|
||||
/* Finalizes a heap archive, returning a pointer to the heap block and its size. */
|
||||
/* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize);
|
||||
|
||||
/* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */
|
||||
/* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */
|
||||
mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
|
||||
/* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */
|
||||
/* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */
|
||||
MINIZ_EXPORT mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
|
||||
|
||||
/* -------- Misc. high-level helper functions: */
|
||||
/* -------- Misc. high-level helper functions: */
|
||||
|
||||
/* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */
|
||||
/* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */
|
||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||
/* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */
|
||||
mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
|
||||
mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr);
|
||||
/* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */
|
||||
/* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */
|
||||
/* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */
|
||||
/* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */
|
||||
MINIZ_EXPORT mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags);
|
||||
MINIZ_EXPORT mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr);
|
||||
|
||||
/* Reads a single file from an archive into a heap block. */
|
||||
/* If pComment is not NULL, only the file with the specified comment will be extracted. */
|
||||
/* Returns NULL on failure. */
|
||||
void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags);
|
||||
void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr);
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
/* Reads a single file from an archive into a heap block. */
|
||||
/* If pComment is not NULL, only the file with the specified comment will be extracted. */
|
||||
/* Returns NULL on failure. */
|
||||
MINIZ_EXPORT void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags);
|
||||
MINIZ_EXPORT void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr);
|
||||
#endif
|
||||
|
||||
#endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MINIZ_NO_ARCHIVE_APIS */
|
||||
|
||||
23
readme.md
23
readme.md
@ -4,7 +4,7 @@ Miniz is a lossless, high performance data compression library in a single sourc
|
||||
|
||||
## Usage
|
||||
|
||||
Please use the files from the [releases page](https://github.com/richgel999/miniz/releases) in your projects. Do not use the git checkout directly! The different source and header files are [amalgamated](https://www.sqlite.org/amalgamation.html) into one `miniz.c`/`miniz.h` pair in a build step (`amalgamate.sh`). Include `miniz.c` and `miniz.h` in your project to use Miniz.
|
||||
Releases are available at the [releases page](https://github.com/richgel999/miniz/releases) as a pair of `miniz.c`/`miniz.h` files which can be simply added to a project. To create this file pair the different source and header files are [amalgamated](https://www.sqlite.org/amalgamation.html) during build. Alternatively use as cmake or meson module (or build system of your choice).
|
||||
|
||||
## Features
|
||||
|
||||
@ -14,13 +14,25 @@ Please use the files from the [releases page](https://github.com/richgel999/mini
|
||||
* A drop-in replacement for zlib's most used API's (tested in several open source projects that use zlib, such as libpng and libzip).
|
||||
* Fills a single threaded performance vs. compression ratio gap between several popular real-time compressors and zlib. For example, at level 1, miniz.c compresses around 5-9% better than minilzo, but is approx. 35% slower. At levels 2-9, miniz.c is designed to compare favorably against zlib's ratio and speed. See the miniz performance comparison page for example timings.
|
||||
* Not a block based compressor: miniz.c fully supports stream based processing using a coroutine-style implementation. The zlib-style API functions can be called a single byte at a time if that's all you've got.
|
||||
* Easy to use. The low-level compressor (tinfl) and decompressor (tdefl) have simple state structs which can be saved/restored as needed with simple memcpy's. The low-level codec API's don't use the heap in any way.
|
||||
* Easy to use. The low-level compressor (tdefl) and decompressor (tinfl) have simple state structs which can be saved/restored as needed with simple memcpy's. The low-level codec API's don't use the heap in any way.
|
||||
* Entire inflater (including optional zlib header parsing and Adler-32 checking) is implemented in a single function as a coroutine, which is separately available in a small (~550 line) source file: miniz_tinfl.c
|
||||
* A fairly complete (but totally optional) set of .ZIP archive manipulation and extraction API's. The archive functionality is intended to solve common problems encountered in embedded, mobile, or game development situations. (The archive API's are purposely just powerful enough to write an entire archiver given a bit of additional higher-level logic.)
|
||||
|
||||
## Building miniz - Using vcpkg
|
||||
|
||||
You can download and install miniz using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager:
|
||||
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh
|
||||
./vcpkg integrate install
|
||||
./vcpkg install miniz
|
||||
|
||||
The miniz port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||
|
||||
## Known Problems
|
||||
|
||||
* No support for encrypted archives. Not sure how useful this stuff is in practice. Zip encryption is very weak.
|
||||
* No support for encrypted archives. Not sure how useful this stuff is in practice.
|
||||
* Minimal documentation. The assumption is that the user is already familiar with the basic zlib API. I need to write an API wiki - for now I've tried to place key comments before each enum/API, and I've included 6 examples that demonstrate how to use the module's major features.
|
||||
|
||||
## Special Thanks
|
||||
@ -31,7 +43,4 @@ Thanks to Bruce Dawson for reporting a problem with the level_and_flags archive
|
||||
|
||||
## Patents
|
||||
|
||||
I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](http://www.gzip.org/zlib/rfc-deflate.html#algorithm). Also see the [gzip FAQ](http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too.
|
||||
|
||||
|
||||
[](https://travis-ci.org/uroni/miniz)
|
||||
I was recently asked if miniz avoids patent issues. miniz purposely uses the same core algorithms as the ones used by zlib. The compressor uses vanilla hash chaining as described [here](https://datatracker.ietf.org/doc/html/rfc1951#section-4). Also see the [gzip FAQ](https://web.archive.org/web/20160308045258/http://www.gzip.org/#faq11). In my opinion, if miniz falls prey to a patent attack then zlib/gzip are likely to be at serious risk too.
|
||||
|
||||
5
test.sh
5
test.sh
@ -4,6 +4,11 @@ set -e
|
||||
|
||||
. amalgamate.sh
|
||||
|
||||
cat << "EOF" > miniz_export.h
|
||||
#ifndef MINIZ_EXPORT
|
||||
#define MINIZ_EXPORT
|
||||
#endif
|
||||
EOF
|
||||
g++ tests/miniz_tester.cpp tests/timer.cpp amalgamation/miniz.c -o miniz_tester -I. -ggdb -O2
|
||||
|
||||
for i in 1 2 3 4 5 6
|
||||
|
||||
87
tests/add_in_place_fuzzer.c
Normal file
87
tests/add_in_place_fuzzer.c
Normal file
@ -0,0 +1,87 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "miniz.h"
|
||||
|
||||
static const mz_uint files_count = 5;
|
||||
static const mz_uint max_file_size = 1024 * 1024;
|
||||
static const char *zip_file_name = "/tmp/miniz-fuzzer-test.zip";
|
||||
|
||||
/* Read 32-bit integer from the fuzzer input with range [0, max] */
|
||||
static mz_uint read_uint32(const mz_uint8 **data, size_t *size, mz_uint max)
|
||||
{
|
||||
mz_uint value = 0;
|
||||
|
||||
if (*size >= sizeof(mz_uint))
|
||||
{
|
||||
memcpy(&value, *data, sizeof(mz_uint));
|
||||
*data += sizeof(mz_uint);
|
||||
*size -= sizeof(mz_uint);
|
||||
value = MZ_MIN(max == UINT_MAX ? value : value % (max + 1), *size);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/* Read random-length null terminated string from the fuzzer input */
|
||||
static mz_bool read_string(const mz_uint8 **data, size_t *size, char *destination, mz_uint max_len)
|
||||
{
|
||||
mz_uint filename_len = read_uint32(data, size, max_len - 1);
|
||||
memcpy(destination, *data, filename_len);
|
||||
destination[filename_len] = 0;
|
||||
*data += filename_len;
|
||||
*size -= filename_len;
|
||||
return filename_len > 0;
|
||||
}
|
||||
|
||||
/* Get random-length buffer from the fuzzer input */
|
||||
static mz_bool read_buffer(const mz_uint8 **data, size_t *size, const mz_uint8 **destination, mz_uint *len)
|
||||
{
|
||||
*len = read_uint32(data, size, max_file_size);
|
||||
*destination = *data;
|
||||
*data += *len;
|
||||
*size -= *len;
|
||||
return *len > 0;
|
||||
}
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
mz_uint i;
|
||||
char archive_file_name[FILENAME_MAX];
|
||||
const mz_uint8 *file_data;
|
||||
mz_uint file_length, flags;
|
||||
size_t extracted_size;
|
||||
mz_uint8 *extracted_data;
|
||||
const char *comment = mz_version();
|
||||
|
||||
/* Remove the temporary file for better reproducibility */
|
||||
remove(zip_file_name);
|
||||
|
||||
for (i = 0; i < files_count; ++i)
|
||||
{
|
||||
/* Fill archive file name */
|
||||
if (!read_string(&data, &size, archive_file_name, sizeof(archive_file_name)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Prepare file's content */
|
||||
if (!read_buffer(&data, &size, &file_data, &file_length))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Prepare flags for adding file */
|
||||
flags = read_uint32(&data, &size, UINT_MAX);
|
||||
|
||||
mz_zip_add_mem_to_archive_file_in_place(zip_file_name, archive_file_name, file_data, file_length, comment,
|
||||
(mz_uint16)strlen(comment), flags);
|
||||
|
||||
/* Prepare flags for extracting file */
|
||||
flags = read_uint32(&data, &size, UINT_MAX);
|
||||
extracted_data = mz_zip_extract_archive_file_to_heap(zip_file_name, archive_file_name, &extracted_size, flags);
|
||||
free(extracted_data);
|
||||
}
|
||||
|
||||
remove(zip_file_name);
|
||||
return 0;
|
||||
}
|
||||
10795
tests/catch_amalgamated.cpp
Normal file
10795
tests/catch_amalgamated.cpp
Normal file
File diff suppressed because it is too large
Load Diff
13143
tests/catch_amalgamated.hpp
Normal file
13143
tests/catch_amalgamated.hpp
Normal file
File diff suppressed because it is too large
Load Diff
26
tests/checksum_fuzzer.c
Normal file
26
tests/checksum_fuzzer.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
static const size_t kMaxSize = 1024 * 1024;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t dataLen)
|
||||
{
|
||||
/* Discard inputs larger than 1Mb. */
|
||||
if (dataLen < 1 || dataLen > kMaxSize)
|
||||
return 0;
|
||||
|
||||
uint32_t crc = crc32(0L, NULL, 0);
|
||||
uint32_t adler = adler32(0L, NULL, 0);
|
||||
|
||||
crc = crc32(crc, data, (uint32_t)dataLen);
|
||||
adler = adler32(adler, data, (uint32_t)dataLen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
91
tests/compress_fuzzer.c
Normal file
91
tests/compress_fuzzer.c
Normal file
@ -0,0 +1,91 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include "miniz.h"
|
||||
|
||||
static const uint8_t *data;
|
||||
static size_t dataLen;
|
||||
|
||||
static void check_compress_level(uint8_t *compr, size_t comprLen,
|
||||
uint8_t *uncompr, size_t uncomprLen,
|
||||
int level)
|
||||
{
|
||||
compress2(compr, &comprLen, data, dataLen, level);
|
||||
uncompress(uncompr, &uncomprLen, compr, comprLen);
|
||||
|
||||
/* Make sure compress + uncompress gives back the input data. */
|
||||
assert(dataLen == uncomprLen);
|
||||
assert(0 == memcmp(data, uncompr, dataLen));
|
||||
}
|
||||
|
||||
#define put_byte(s, i, c) \
|
||||
{ \
|
||||
s[i] = (unsigned char)(c); \
|
||||
}
|
||||
|
||||
static void write_zlib_header(uint8_t *s)
|
||||
{
|
||||
unsigned level_flags = 0; /* compression level (0..3) */
|
||||
unsigned w_bits = 8; /* window size log2(w_size) (8..16) */
|
||||
unsigned int header = (Z_DEFLATED + ((w_bits - 8) << 4)) << 8;
|
||||
header |= (level_flags << 6);
|
||||
|
||||
header += 31 - (header % 31);
|
||||
|
||||
/* s is guaranteed to be longer than 2 bytes. */
|
||||
put_byte(s, 0, (unsigned char)(header >> 8));
|
||||
put_byte(s, 1, (unsigned char)(header & 0xff));
|
||||
}
|
||||
|
||||
static void check_decompress(uint8_t *compr, size_t comprLen)
|
||||
{
|
||||
/* We need to write a valid zlib header of size two bytes. Copy the input data
|
||||
in a larger buffer. Do not modify the input data to avoid libFuzzer error:
|
||||
fuzz target overwrites its const input. */
|
||||
size_t copyLen = dataLen + 2;
|
||||
uint8_t *copy = malloc(copyLen);
|
||||
memcpy(copy + 2, data, dataLen);
|
||||
write_zlib_header(copy);
|
||||
|
||||
uncompress(compr, &comprLen, copy, copyLen);
|
||||
free(copy);
|
||||
}
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size)
|
||||
{
|
||||
/* compressBound does not provide enough space for low compression levels. */
|
||||
size_t comprLen = 100 + 2 * compressBound(size);
|
||||
size_t uncomprLen = size;
|
||||
uint8_t *compr, *uncompr;
|
||||
|
||||
/* Discard inputs larger than 1Mb. */
|
||||
static size_t kMaxSize = 1024 * 1024;
|
||||
|
||||
if (size < 1 || size > kMaxSize)
|
||||
return 0;
|
||||
|
||||
data = d;
|
||||
dataLen = size;
|
||||
compr = calloc(1, comprLen);
|
||||
uncompr = calloc(1, uncomprLen);
|
||||
|
||||
check_compress_level(compr, comprLen, uncompr, uncomprLen, 1);
|
||||
check_compress_level(compr, comprLen, uncompr, uncomprLen, 3);
|
||||
check_compress_level(compr, comprLen, uncompr, uncomprLen, 6);
|
||||
check_compress_level(compr, comprLen, uncompr, uncomprLen, 7);
|
||||
|
||||
check_decompress(compr, comprLen);
|
||||
|
||||
free(compr);
|
||||
free(uncompr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
88
tests/flush_fuzzer.c
Normal file
88
tests/flush_fuzzer.c
Normal file
@ -0,0 +1,88 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
#define CHECK_ERR(err, msg) \
|
||||
{ \
|
||||
if (err != Z_OK) \
|
||||
{ \
|
||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
static const uint8_t *data;
|
||||
static size_t dataLen;
|
||||
static alloc_func zalloc = NULL;
|
||||
static free_func zfree = NULL;
|
||||
|
||||
void test_flush(unsigned char *compr, size_t *comprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
unsigned int len = dataLen;
|
||||
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = NULL;
|
||||
|
||||
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_in = (Bytef *)data;
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_in = 3;
|
||||
c_stream.avail_out = (unsigned int)*comprLen;
|
||||
err = deflate(&c_stream, Z_FULL_FLUSH);
|
||||
CHECK_ERR(err, "deflate flush 1");
|
||||
|
||||
compr[3]++; /* force an error in first compressed block */
|
||||
c_stream.avail_in = len - 3;
|
||||
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
|
||||
if (err != Z_STREAM_END)
|
||||
{
|
||||
CHECK_ERR(err, "deflate flush 2");
|
||||
}
|
||||
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
|
||||
*comprLen = (size_t)c_stream.total_out;
|
||||
}
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size)
|
||||
{
|
||||
size_t comprLen = 100 + 2 * compressBound(size);
|
||||
size_t uncomprLen = size;
|
||||
uint8_t *compr, *uncompr;
|
||||
|
||||
/* Discard inputs larger than 1Mb. */
|
||||
static const size_t kMaxSize = 1024 * 1024;
|
||||
|
||||
/* This test requires at least 3 bytes of input data. */
|
||||
if (size <= 3 || size > kMaxSize)
|
||||
return 0;
|
||||
|
||||
data = d;
|
||||
dataLen = size;
|
||||
compr = calloc(1, comprLen);
|
||||
uncompr = calloc(1, uncomprLen);
|
||||
|
||||
test_flush(compr, &comprLen);
|
||||
|
||||
free(compr);
|
||||
free(uncompr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
tests/fuzz_main.c
Normal file
55
tests/fuzz_main.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Fuzz target entry point for building without libFuzzer */
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size);
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
FILE *f;
|
||||
char *buf = NULL;
|
||||
long siz_buf;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf(stderr, "no input file\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
f = fopen(argv[1], "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
fprintf(stderr, "error opening input file %s\n", argv[1]);
|
||||
goto err;
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
|
||||
siz_buf = ftell(f);
|
||||
rewind(f);
|
||||
|
||||
if (siz_buf < 1)
|
||||
goto err;
|
||||
|
||||
buf = (char *)malloc(siz_buf);
|
||||
if (buf == NULL)
|
||||
{
|
||||
fprintf(stderr, "malloc() failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (fread(buf, siz_buf, 1, f) != 1)
|
||||
{
|
||||
fprintf(stderr, "fread() failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
(void)LLVMFuzzerTestOneInput((uint8_t *)buf, siz_buf);
|
||||
|
||||
err:
|
||||
free(buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
133
tests/large_fuzzer.c
Normal file
133
tests/large_fuzzer.c
Normal file
@ -0,0 +1,133 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
#define CHECK_ERR(err, msg) \
|
||||
{ \
|
||||
if (err != Z_OK) \
|
||||
{ \
|
||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
static const uint8_t *data;
|
||||
static size_t dataLen;
|
||||
static alloc_func zalloc = NULL;
|
||||
static free_func zfree = NULL;
|
||||
static unsigned int diff;
|
||||
|
||||
/* Test deflate() with large buffers and dynamic change of compression level */
|
||||
void test_large_deflate(unsigned char *compr, size_t comprLen,
|
||||
unsigned char *uncompr, size_t uncomprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = NULL;
|
||||
|
||||
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_out = compr;
|
||||
c_stream.avail_out = (unsigned int)comprLen;
|
||||
|
||||
/* At this point, uncompr is still mostly zeroes, so it should compress
|
||||
* very well:
|
||||
*/
|
||||
c_stream.next_in = uncompr;
|
||||
c_stream.avail_in = (unsigned int)uncomprLen;
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate large 1");
|
||||
|
||||
if (c_stream.avail_in != 0)
|
||||
{
|
||||
fprintf(stderr, "deflate not greedy\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Feed in already compressed data: */
|
||||
c_stream.next_in = compr;
|
||||
diff = (unsigned int)(c_stream.next_out - compr);
|
||||
c_stream.avail_in = diff;
|
||||
|
||||
deflate(&c_stream, Z_NO_FLUSH);
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
|
||||
if (err != Z_STREAM_END)
|
||||
{
|
||||
fprintf(stderr, "deflate large should report Z_STREAM_END\n");
|
||||
exit(1);
|
||||
}
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
}
|
||||
|
||||
/* Test inflate() with large buffers */
|
||||
void test_large_inflate(unsigned char *compr, size_t comprLen,
|
||||
unsigned char *uncompr, size_t uncomprLen)
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
d_stream.zalloc = zalloc;
|
||||
d_stream.zfree = zfree;
|
||||
d_stream.opaque = NULL;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
d_stream.avail_in = (unsigned int)comprLen;
|
||||
|
||||
err = inflateInit(&d_stream);
|
||||
CHECK_ERR(err, "inflateInit");
|
||||
|
||||
for (;;)
|
||||
{
|
||||
d_stream.next_out = uncompr; /* discard the output */
|
||||
d_stream.avail_out = (unsigned int)uncomprLen;
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END)
|
||||
break;
|
||||
|
||||
CHECK_ERR(err, "large inflate");
|
||||
}
|
||||
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
}
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size)
|
||||
{
|
||||
size_t comprLen = 100 + 3 * size;
|
||||
size_t uncomprLen = comprLen;
|
||||
uint8_t *compr, *uncompr;
|
||||
|
||||
/* Discard inputs larger than 512Kb. */
|
||||
static size_t kMaxSize = 512 * 1024;
|
||||
|
||||
if (size < 1 || size > kMaxSize)
|
||||
return 0;
|
||||
|
||||
data = d;
|
||||
dataLen = size;
|
||||
compr = calloc(1, comprLen);
|
||||
uncompr = calloc(1, uncomprLen);
|
||||
|
||||
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
|
||||
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
free(compr);
|
||||
free(uncompr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
131
tests/main.cpp
Normal file
131
tests/main.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
#include "catch_amalgamated.hpp"
|
||||
#include "../miniz.h"
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define unlink _unlink
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifndef MINIZ_NO_STDIO
|
||||
bool create_test_zip()
|
||||
{
|
||||
unlink("test.zip");
|
||||
mz_zip_archive zip_archive = {};
|
||||
auto b = mz_zip_writer_init_file(&zip_archive, "test.zip", 0);
|
||||
if (!b)
|
||||
return false;
|
||||
|
||||
b = mz_zip_writer_add_mem(&zip_archive, "test.txt", "foo", 3, MZ_DEFAULT_COMPRESSION);
|
||||
if (!b)
|
||||
return false;
|
||||
|
||||
b = mz_zip_writer_finalize_archive(&zip_archive);
|
||||
if (!b)
|
||||
return false;
|
||||
|
||||
b = mz_zip_writer_end(&zip_archive);
|
||||
if (!b)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST_CASE("Zip writer tests")
|
||||
{
|
||||
auto b = create_test_zip();
|
||||
REQUIRE(b);
|
||||
|
||||
SECTION("Test test.txt content correct")
|
||||
{
|
||||
mz_zip_archive zip_archive = {};
|
||||
|
||||
auto b = mz_zip_reader_init_file(&zip_archive, "test.zip", 0);
|
||||
REQUIRE(b);
|
||||
|
||||
size_t content_size;
|
||||
auto content = mz_zip_reader_extract_file_to_heap(&zip_archive, "test.txt", &content_size, 0);
|
||||
|
||||
std::string_view content_view(reinterpret_cast<char *>(content), content_size);
|
||||
|
||||
REQUIRE(content_view == "foo");
|
||||
REQUIRE(content_view.size() == 3);
|
||||
|
||||
free(content);
|
||||
|
||||
mz_zip_reader_end(&zip_archive);
|
||||
}
|
||||
|
||||
SECTION("Test repeated file addition to zip")
|
||||
{
|
||||
mz_zip_archive zip_archive = {};
|
||||
auto b = mz_zip_writer_init_file(&zip_archive, "test2.zip", 0);
|
||||
REQUIRE(b);
|
||||
|
||||
b = mz_zip_writer_finalize_archive(&zip_archive);
|
||||
REQUIRE(b);
|
||||
|
||||
b = mz_zip_writer_end(&zip_archive);
|
||||
REQUIRE(b);
|
||||
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
const char *str = "hello world";
|
||||
b = mz_zip_add_mem_to_archive_file_in_place(
|
||||
std::string("test2.zip").c_str(), ("file1.txt" + std::to_string(i)).c_str(),
|
||||
str, (mz_uint16)strlen(str),
|
||||
NULL, 0,
|
||||
MZ_BEST_COMPRESSION);
|
||||
REQUIRE(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Tinfl / tdefl tests")
|
||||
{
|
||||
SECTION("simple_test1")
|
||||
{
|
||||
size_t cmp_len = 0;
|
||||
|
||||
const char *p = "This is a test.This is a test.This is a test.1234567This is a test.This is a test.123456";
|
||||
size_t uncomp_len = strlen(p);
|
||||
|
||||
void *pComp_data = tdefl_compress_mem_to_heap(p, uncomp_len, &cmp_len, TDEFL_WRITE_ZLIB_HEADER);
|
||||
REQUIRE(pComp_data);
|
||||
|
||||
size_t decomp_len = 0;
|
||||
void *pDecomp_data = tinfl_decompress_mem_to_heap(pComp_data, cmp_len, &decomp_len, TINFL_FLAG_PARSE_ZLIB_HEADER);
|
||||
|
||||
REQUIRE(pDecomp_data);
|
||||
REQUIRE(decomp_len == uncomp_len);
|
||||
REQUIRE(memcmp(pDecomp_data, p, uncomp_len) == 0);
|
||||
|
||||
free(pComp_data);
|
||||
free(pDecomp_data);
|
||||
}
|
||||
|
||||
SECTION("simple_test2")
|
||||
{
|
||||
uint8_t cmp_buf[1024], decomp_buf[1024];
|
||||
uLong cmp_len = sizeof(cmp_buf);
|
||||
|
||||
const char *p = "This is a test.This is a test.This is a test.1234567This is a test.This is a test.123456";
|
||||
uLong uncomp_len = (uLong)strlen(p);
|
||||
|
||||
int status = compress(cmp_buf, &cmp_len, (const uint8_t *)p, uncomp_len);
|
||||
REQUIRE(status == Z_OK);
|
||||
|
||||
REQUIRE(cmp_len <= compressBound(uncomp_len));
|
||||
|
||||
uLong decomp_len = sizeof(decomp_buf);
|
||||
status = uncompress(decomp_buf, &decomp_len, cmp_buf, cmp_len);
|
||||
;
|
||||
|
||||
REQUIRE(status == Z_OK);
|
||||
REQUIRE(decomp_len == uncomp_len);
|
||||
REQUIRE(memcmp(decomp_buf, p, uncomp_len) == 0);
|
||||
}
|
||||
}
|
||||
@ -993,6 +993,71 @@ static bool zip_extract(const char *pZip_filename, const char *pDst_filename)
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
if (stat.m_uncomp_size<100*1024*1024)
|
||||
{
|
||||
/* Use iterative reader to read onto heap in one big chunk */
|
||||
mz_zip_reader_extract_iter_state *pIter = mz_zip_reader_extract_iter_new(&zip, i, 0);
|
||||
void *p = malloc(stat.m_uncomp_size);
|
||||
if ((!pIter) && (0 != stat.m_uncomp_size))
|
||||
{
|
||||
print_error("Failed testing archive -4 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
|
||||
free(p);
|
||||
mz_zip_reader_end(&zip);
|
||||
return false;
|
||||
}
|
||||
if (pIter)
|
||||
{
|
||||
if (stat.m_uncomp_size != mz_zip_reader_extract_iter_read(pIter, p, stat.m_uncomp_size) )
|
||||
{
|
||||
print_error("Failed testing archive -5 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
|
||||
free(p);
|
||||
mz_zip_reader_extract_iter_free(pIter);
|
||||
mz_zip_reader_end(&zip);
|
||||
return false;
|
||||
}
|
||||
if (MZ_TRUE != mz_zip_reader_extract_iter_free(pIter))
|
||||
{
|
||||
print_error("Failed testing archive -6 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
|
||||
free(p);
|
||||
mz_zip_reader_end(&zip);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
if (stat.m_uncomp_size<100*1024)
|
||||
{
|
||||
/* Use iterative reader to read file one byte at a time */
|
||||
mz_zip_reader_extract_iter_state *pIter = mz_zip_reader_extract_iter_new(&zip, i, 0);
|
||||
uint8_t byBuffer;
|
||||
if ((!pIter) && (0 != stat.m_uncomp_size))
|
||||
{
|
||||
print_error("Failed testing archive -7 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
|
||||
mz_zip_reader_end(&zip);
|
||||
return false;
|
||||
}
|
||||
if (pIter)
|
||||
{
|
||||
for ( uint64_t uiIndex = 0; uiIndex < stat.m_uncomp_size; uiIndex++ )
|
||||
{
|
||||
if (sizeof(byBuffer) != mz_zip_reader_extract_iter_read(pIter, &byBuffer, sizeof(byBuffer)))
|
||||
{
|
||||
print_error("Failed testing archive -8 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
|
||||
mz_zip_reader_extract_iter_free(pIter);
|
||||
mz_zip_reader_end(&zip);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (MZ_TRUE != mz_zip_reader_extract_iter_free(pIter))
|
||||
{
|
||||
print_error("Failed testing archive -9 \"%s\" err: %s!\n", pZip_filename, mz_zip_get_error_string(mz_zip_get_last_error(&zip)));
|
||||
mz_zip_reader_end(&zip);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Verified %u files\n", mz_zip_reader_get_num_files(&zip));
|
||||
|
||||
@ -1446,6 +1511,15 @@ static bool test_archives(const char *pPath, comp_options options)
|
||||
if (mz_crc32(MZ_CRC32_INIT, (const uint8*)p, extracted_size) != extracted_crc32)
|
||||
status = false;
|
||||
|
||||
mz_zip_reader_extract_iter_state *pIter = mz_zip_reader_extract_file_iter_new(&src_archive, name, 0);
|
||||
void *q = malloc(extracted_size);
|
||||
mz_zip_reader_extract_iter_read(pIter, q, extracted_size);
|
||||
mz_zip_reader_extract_iter_free(pIter);
|
||||
|
||||
if (mz_crc32(MZ_CRC32_INIT, (const uint8*)q, extracted_size) != extracted_crc32)
|
||||
status = false;
|
||||
|
||||
free(q);
|
||||
free(p);
|
||||
|
||||
if (options.m_write_archives)
|
||||
|
||||
48
tests/ossfuzz.sh
Executable file
48
tests/ossfuzz.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/bash -eu
|
||||
# Copyright 2020 Google Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# This script is meant to be run by
|
||||
# https://github.com/google/oss-fuzz/blob/master/projects/miniz/Dockerfile
|
||||
|
||||
cat << "EOF" > miniz_export.h
|
||||
#ifndef MINIZ_EXPORT
|
||||
#define MINIZ_EXPORT
|
||||
#endif
|
||||
EOF
|
||||
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DAMALGAMATE_SOURCES=ON -DBUILD_SHARED_LIBS=OFF -DBUILD_FUZZERS=ON -DBUILD_TESTS=OFF
|
||||
make -j$(nproc)
|
||||
cd ..
|
||||
|
||||
zip $OUT/seed_corpus.zip *.*
|
||||
|
||||
for f in $(find $SRC -name '*_fuzzer.c'); do
|
||||
b=$(basename -s .c $f)
|
||||
$CC $CFLAGS -Ibuild/amalgamation $f -c -o /tmp/$b.o
|
||||
$CXX $CXXFLAGS -stdlib=libc++ -Ibuild/amalgamation /tmp/$b.o -o $OUT/$b $LIB_FUZZING_ENGINE ./build/libminiz.a
|
||||
rm -f /tmp/$b.o
|
||||
ln -sf $OUT/seed_corpus.zip $OUT/${b}_seed_corpus.zip
|
||||
done
|
||||
|
||||
|
||||
# Add .zip input file for the zip fuzzer
|
||||
rm -f $OUT/zip_fuzzer_seed_corpus.zip
|
||||
zip $OUT/zip_fuzzer_seed_corpus.zip $OUT/seed_corpus.zip
|
||||
|
||||
cp tests/zip.dict $OUT/zip_fuzzer.dict
|
||||
126
tests/small_fuzzer.c
Normal file
126
tests/small_fuzzer.c
Normal file
@ -0,0 +1,126 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
#define CHECK_ERR(err, msg) \
|
||||
{ \
|
||||
if (err != Z_OK) \
|
||||
{ \
|
||||
fprintf(stderr, "%s error: %d\n", msg, err); \
|
||||
exit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
static const uint8_t *data;
|
||||
static size_t dataLen;
|
||||
static alloc_func zalloc = NULL;
|
||||
static free_func zfree = NULL;
|
||||
|
||||
/* Test deflate() with small buffers */
|
||||
void test_deflate(unsigned char *compr, size_t comprLen)
|
||||
{
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
unsigned long len = dataLen;
|
||||
|
||||
c_stream.zalloc = zalloc;
|
||||
c_stream.zfree = zfree;
|
||||
c_stream.opaque = NULL;
|
||||
|
||||
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
|
||||
CHECK_ERR(err, "deflateInit");
|
||||
|
||||
c_stream.next_in = (Bytef *)data;
|
||||
c_stream.next_out = compr;
|
||||
|
||||
while (c_stream.total_in != len && c_stream.total_out < comprLen)
|
||||
{
|
||||
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate small 1");
|
||||
}
|
||||
|
||||
/* Finish the stream, still forcing small buffers: */
|
||||
for (;;)
|
||||
{
|
||||
c_stream.avail_out = 1;
|
||||
err = deflate(&c_stream, Z_FINISH);
|
||||
if (err == Z_STREAM_END)
|
||||
break;
|
||||
CHECK_ERR(err, "deflate small 2");
|
||||
}
|
||||
|
||||
err = deflateEnd(&c_stream);
|
||||
CHECK_ERR(err, "deflateEnd");
|
||||
}
|
||||
|
||||
/* Test inflate() with small buffers */
|
||||
void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen)
|
||||
{
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
d_stream.zalloc = zalloc;
|
||||
d_stream.zfree = zfree;
|
||||
d_stream.opaque = NULL;
|
||||
|
||||
d_stream.next_in = compr;
|
||||
d_stream.avail_in = 0;
|
||||
d_stream.next_out = uncompr;
|
||||
|
||||
err = inflateInit(&d_stream);
|
||||
CHECK_ERR(err, "inflateInit");
|
||||
|
||||
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen)
|
||||
{
|
||||
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
|
||||
err = inflate(&d_stream, Z_NO_FLUSH);
|
||||
if (err == Z_STREAM_END)
|
||||
break;
|
||||
CHECK_ERR(err, "inflate");
|
||||
}
|
||||
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
if (memcmp(uncompr, data, dataLen))
|
||||
{
|
||||
fprintf(stderr, "bad inflate\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *d, size_t size)
|
||||
{
|
||||
size_t comprLen = compressBound(size);
|
||||
size_t uncomprLen = size;
|
||||
uint8_t *compr, *uncompr;
|
||||
|
||||
/* Discard inputs larger than 1Mb. */
|
||||
static size_t kMaxSize = 1024 * 1024;
|
||||
|
||||
if (size < 1 || size > kMaxSize)
|
||||
return 0;
|
||||
|
||||
data = d;
|
||||
dataLen = size;
|
||||
compr = calloc(1, comprLen);
|
||||
uncompr = calloc(1, uncomprLen);
|
||||
|
||||
test_deflate(compr, comprLen);
|
||||
test_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
||||
free(compr);
|
||||
free(uncompr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
tests/uncompress2_fuzzer.c
Normal file
21
tests/uncompress2_fuzzer.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
static unsigned char buffer[256 * 1024] = { 0 };
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
unsigned long int buffer_length = sizeof(buffer);
|
||||
|
||||
if (Z_OK != uncompress2(buffer, &buffer_length, data, &size))
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
30
tests/uncompress_fuzzer.c
Normal file
30
tests/uncompress_fuzzer.c
Normal file
@ -0,0 +1,30 @@
|
||||
/* Derived from zlib fuzzers at http://github.com/google/oss-fuzz/tree/master/projects/zlib,
|
||||
* see ossfuzz.sh for full license text.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
unsigned long int buffer_length = 1;
|
||||
unsigned char *buffer = NULL;
|
||||
int z_status = 0;
|
||||
|
||||
if (size > 0)
|
||||
buffer_length *= data[0];
|
||||
if (size > 1)
|
||||
buffer_length *= data[1];
|
||||
|
||||
buffer = (unsigned char *)malloc(buffer_length);
|
||||
|
||||
z_status = uncompress(buffer, &buffer_length, data, size);
|
||||
free(buffer);
|
||||
|
||||
if (Z_OK != z_status)
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
9
tests/zip.dict
Normal file
9
tests/zip.dict
Normal file
@ -0,0 +1,9 @@
|
||||
# Fuzzing dictionary for .zip files
|
||||
|
||||
header_lfh="\x50\x4b\x03\x04"
|
||||
header_cd="\x50\x4b\x01\x02"
|
||||
header_eocd="\x50\x4b\x05\x06"
|
||||
header_eocd64="\x50\x4b\x06\x06"
|
||||
data_descriptor="\x50\x4b\x07\x08"
|
||||
extra_data_sig="\x50\x4b\x06\x08"
|
||||
digital_sig="\x50\x4b\x05\x05"
|
||||
63
tests/zip_fuzzer.c
Normal file
63
tests/zip_fuzzer.c
Normal file
@ -0,0 +1,63 @@
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "miniz.h"
|
||||
|
||||
static char filename[260];
|
||||
static unsigned char read_buf[1024 * 256];
|
||||
|
||||
static const size_t filename_max = sizeof(filename);
|
||||
static const size_t read_buf_size = sizeof(read_buf);
|
||||
static const size_t data_max = 1024 * 256;
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
|
||||
{
|
||||
if (size > data_max)
|
||||
return 0;
|
||||
|
||||
int ret = 0;
|
||||
mz_zip_archive zip;
|
||||
mz_zip_zero_struct(&zip);
|
||||
|
||||
mz_uint flags = 0;
|
||||
|
||||
if (!mz_zip_reader_init_mem(&zip, data, size, flags))
|
||||
return 0;
|
||||
|
||||
mz_uint i, files;
|
||||
|
||||
files = mz_zip_reader_get_num_files(&zip);
|
||||
|
||||
for (i = 0; i < files; i++)
|
||||
{
|
||||
mz_zip_clear_last_error(&zip);
|
||||
|
||||
if (mz_zip_reader_is_file_a_directory(&zip, i))
|
||||
continue;
|
||||
|
||||
mz_zip_validate_file(&zip, i, MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY);
|
||||
|
||||
if (mz_zip_reader_is_file_encrypted(&zip, i))
|
||||
continue;
|
||||
|
||||
mz_zip_clear_last_error(&zip);
|
||||
|
||||
mz_uint ret = mz_zip_reader_get_filename(&zip, i, filename, filename_max);
|
||||
|
||||
if (mz_zip_get_last_error(&zip))
|
||||
continue;
|
||||
|
||||
mz_zip_archive_file_stat file_stat = { 0 };
|
||||
mz_bool status = mz_zip_reader_file_stat(&zip, i, &file_stat) != 0;
|
||||
|
||||
if ((file_stat.m_method) && (file_stat.m_method != MZ_DEFLATED))
|
||||
continue;
|
||||
|
||||
mz_zip_reader_extract_file_to_mem(&zip, file_stat.m_filename, read_buf, read_buf_size, 0);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
mz_zip_reader_end(&zip);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user