koffi 2.3.6-beta.6 → 2.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/cnoke/cnoke.js +3 -7
- package/src/cnoke/src/builder.js +9 -6
- package/src/cnoke/src/index.js +2 -2
- package/src/koffi/build/2.3.7/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/src/ffi.cc +2 -2
- package/src/koffi/src/index.d.ts +2 -2
- package/src/koffi/src/index.js +1 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_arm64/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_ia32/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_x64/koffi.pdb +0 -0
- package/vendor/brotli/BUILD +0 -144
- package/vendor/brotli/CMakeLists.txt +0 -421
- package/vendor/brotli/CONTRIBUTING.md +0 -27
- package/vendor/brotli/LICENSE +0 -19
- package/vendor/brotli/MANIFEST.in +0 -17
- package/vendor/brotli/Makefile +0 -55
- package/vendor/brotli/Makefile.am +0 -38
- package/vendor/brotli/README +0 -15
- package/vendor/brotli/README.md +0 -104
- package/vendor/brotli/WORKSPACE +0 -21
- package/vendor/brotli/bootstrap +0 -35
- package/vendor/brotli/c/common/constants.c +0 -15
- package/vendor/brotli/c/common/constants.h +0 -200
- package/vendor/brotli/c/common/context.c +0 -156
- package/vendor/brotli/c/common/context.h +0 -113
- package/vendor/brotli/c/common/dictionary.c +0 -5914
- package/vendor/brotli/c/common/dictionary.h +0 -64
- package/vendor/brotli/c/common/platform.c +0 -22
- package/vendor/brotli/c/common/platform.h +0 -596
- package/vendor/brotli/c/common/transform.c +0 -291
- package/vendor/brotli/c/common/transform.h +0 -85
- package/vendor/brotli/c/common/version.h +0 -26
- package/vendor/brotli/c/dec/bit_reader.c +0 -76
- package/vendor/brotli/c/dec/bit_reader.h +0 -351
- package/vendor/brotli/c/dec/decode.c +0 -2608
- package/vendor/brotli/c/dec/huffman.c +0 -339
- package/vendor/brotli/c/dec/huffman.h +0 -121
- package/vendor/brotli/c/dec/prefix.h +0 -732
- package/vendor/brotli/c/dec/state.c +0 -159
- package/vendor/brotli/c/dec/state.h +0 -365
- package/vendor/brotli/c/enc/backward_references.c +0 -145
- package/vendor/brotli/c/enc/backward_references.h +0 -39
- package/vendor/brotli/c/enc/backward_references_hq.c +0 -843
- package/vendor/brotli/c/enc/backward_references_hq.h +0 -95
- package/vendor/brotli/c/enc/backward_references_inc.h +0 -163
- package/vendor/brotli/c/enc/bit_cost.c +0 -35
- package/vendor/brotli/c/enc/bit_cost.h +0 -63
- package/vendor/brotli/c/enc/bit_cost_inc.h +0 -127
- package/vendor/brotli/c/enc/block_encoder_inc.h +0 -34
- package/vendor/brotli/c/enc/block_splitter.c +0 -194
- package/vendor/brotli/c/enc/block_splitter.h +0 -51
- package/vendor/brotli/c/enc/block_splitter_inc.h +0 -440
- package/vendor/brotli/c/enc/brotli_bit_stream.c +0 -1314
- package/vendor/brotli/c/enc/brotli_bit_stream.h +0 -84
- package/vendor/brotli/c/enc/cluster.c +0 -56
- package/vendor/brotli/c/enc/cluster.h +0 -48
- package/vendor/brotli/c/enc/cluster_inc.h +0 -320
- package/vendor/brotli/c/enc/command.c +0 -28
- package/vendor/brotli/c/enc/command.h +0 -190
- package/vendor/brotli/c/enc/compress_fragment.c +0 -790
- package/vendor/brotli/c/enc/compress_fragment.h +0 -61
- package/vendor/brotli/c/enc/compress_fragment_two_pass.c +0 -645
- package/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -54
- package/vendor/brotli/c/enc/dictionary_hash.c +0 -1846
- package/vendor/brotli/c/enc/dictionary_hash.h +0 -25
- package/vendor/brotli/c/enc/encode.c +0 -1927
- package/vendor/brotli/c/enc/encoder_dict.c +0 -33
- package/vendor/brotli/c/enc/encoder_dict.h +0 -43
- package/vendor/brotli/c/enc/entropy_encode.c +0 -503
- package/vendor/brotli/c/enc/entropy_encode.h +0 -122
- package/vendor/brotli/c/enc/entropy_encode_static.h +0 -539
- package/vendor/brotli/c/enc/fast_log.c +0 -105
- package/vendor/brotli/c/enc/fast_log.h +0 -66
- package/vendor/brotli/c/enc/find_match_length.h +0 -79
- package/vendor/brotli/c/enc/hash.h +0 -488
- package/vendor/brotli/c/enc/hash_composite_inc.h +0 -125
- package/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +0 -293
- package/vendor/brotli/c/enc/hash_longest_match64_inc.h +0 -267
- package/vendor/brotli/c/enc/hash_longest_match_inc.h +0 -262
- package/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +0 -266
- package/vendor/brotli/c/enc/hash_rolling_inc.h +0 -212
- package/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +0 -329
- package/vendor/brotli/c/enc/histogram.c +0 -100
- package/vendor/brotli/c/enc/histogram.h +0 -63
- package/vendor/brotli/c/enc/histogram_inc.h +0 -51
- package/vendor/brotli/c/enc/literal_cost.c +0 -175
- package/vendor/brotli/c/enc/literal_cost.h +0 -30
- package/vendor/brotli/c/enc/memory.c +0 -170
- package/vendor/brotli/c/enc/memory.h +0 -114
- package/vendor/brotli/c/enc/metablock.c +0 -663
- package/vendor/brotli/c/enc/metablock.h +0 -105
- package/vendor/brotli/c/enc/metablock_inc.h +0 -183
- package/vendor/brotli/c/enc/params.h +0 -46
- package/vendor/brotli/c/enc/prefix.h +0 -53
- package/vendor/brotli/c/enc/quality.h +0 -165
- package/vendor/brotli/c/enc/ringbuffer.h +0 -167
- package/vendor/brotli/c/enc/static_dict.c +0 -486
- package/vendor/brotli/c/enc/static_dict.h +0 -40
- package/vendor/brotli/c/enc/static_dict_lut.h +0 -5864
- package/vendor/brotli/c/enc/utf8_util.c +0 -85
- package/vendor/brotli/c/enc/utf8_util.h +0 -32
- package/vendor/brotli/c/enc/write_bits.h +0 -87
- package/vendor/brotli/c/include/brotli/decode.h +0 -344
- package/vendor/brotli/c/include/brotli/encode.h +0 -448
- package/vendor/brotli/c/include/brotli/port.h +0 -288
- package/vendor/brotli/c/include/brotli/types.h +0 -83
- package/vendor/brotli/c/tools/brotli.c +0 -1116
- package/vendor/brotli/c/tools/brotli.md +0 -107
- package/vendor/brotli/compiler_config_setting.bzl +0 -28
- package/vendor/brotli/configure +0 -8
- package/vendor/brotli/configure-cmake +0 -318
- package/vendor/brotli/configure.ac +0 -14
- package/vendor/brotli/docs/brotli.1 +0 -132
- package/vendor/brotli/docs/constants.h.3 +0 -47
- package/vendor/brotli/docs/decode.h.3 +0 -415
- package/vendor/brotli/docs/encode.h.3 +0 -586
- package/vendor/brotli/docs/types.h.3 +0 -117
- package/vendor/brotli/premake5.lua +0 -78
- package/vendor/brotli/python/Makefile +0 -57
- package/vendor/brotli/python/README.md +0 -54
- package/vendor/brotli/python/_brotli.cc +0 -753
- package/vendor/brotli/python/bro.py +0 -160
- package/vendor/brotli/python/brotli.py +0 -56
- package/vendor/brotli/python/tests/__init__.py +0 -0
- package/vendor/brotli/python/tests/_test_utils.py +0 -112
- package/vendor/brotli/python/tests/bro_test.py +0 -102
- package/vendor/brotli/python/tests/compress_test.py +0 -41
- package/vendor/brotli/python/tests/compressor_test.py +0 -94
- package/vendor/brotli/python/tests/decompress_test.py +0 -42
- package/vendor/brotli/python/tests/decompressor_test.py +0 -59
- package/vendor/brotli/scripts/libbrotlicommon.pc.in +0 -11
- package/vendor/brotli/scripts/libbrotlidec.pc.in +0 -12
- package/vendor/brotli/scripts/libbrotlienc.pc.in +0 -12
- package/vendor/brotli/scripts/sources.lst +0 -104
- package/vendor/brotli/setup.cfg +0 -5
- package/vendor/brotli/setup.py +0 -293
- package/vendor/brotli/tests/Makefile +0 -17
- package/vendor/brotli/tests/compatibility_test.sh +0 -25
- package/vendor/brotli/tests/roundtrip_test.sh +0 -36
- package/vendor/brotli/tests/run-compatibility-test.cmake +0 -31
- package/vendor/brotli/tests/run-roundtrip-test.cmake +0 -36
- package/vendor/brotli/tests/testdata/empty +0 -0
- package/vendor/brotli/tests/testdata/empty.compressed +0 -1
- package/vendor/brotli/tests/testdata/ukkonooa +0 -1
- package/vendor/brotli/tests/testdata/ukkonooa.compressed +0 -0
- package/vendor/dragonbox/CMakeLists.txt +0 -123
- package/vendor/dragonbox/LICENSE-Apache2-LLVM +0 -218
- package/vendor/dragonbox/LICENSE-Boost +0 -23
- package/vendor/dragonbox/README.md +0 -277
- package/vendor/dragonbox/cmake/dragonboxConfig.cmake +0 -1
- package/vendor/dragonbox/include/dragonbox/dragonbox.h +0 -2674
- package/vendor/dragonbox/include/dragonbox/dragonbox_to_chars.h +0 -108
- package/vendor/dragonbox/other_files/Dragonbox.pdf +0 -0
- package/vendor/dragonbox/other_files/Dragonbox_old.pdf +0 -0
- package/vendor/dragonbox/other_files/milo_benchmark.png +0 -0
- package/vendor/dragonbox/other_files/unknown_win64_vc2019.html +0 -540
- package/vendor/dragonbox/other_files/unknown_win64_vc2019_randomdigit_time.png +0 -0
- package/vendor/dragonbox/source/dragonbox_to_chars.cpp +0 -303
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/CMakeLists.txt +0 -24
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.cpp +0 -238
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.h +0 -95
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/grisu_exact.h +0 -2666
- package/vendor/dragonbox/subproject/3rdparty/ryu/CMakeLists.txt +0 -16
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/common.h +0 -114
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s.c +0 -509
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_full_table.h +0 -367
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_intrinsics.h +0 -357
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/digit_table.h +0 -35
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s.c +0 -345
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_full_table.h +0 -55
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_intrinsics.h +0 -128
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/ryu.h +0 -46
- package/vendor/dragonbox/subproject/3rdparty/schubfach/CMakeLists.txt +0 -22
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.cc +0 -699
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.h +0 -31
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.cc +0 -1354
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.h +0 -31
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/example_shaded_plots.m +0 -68
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/license.txt +0 -25
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution.m +0 -92
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution_prctile.m +0 -121
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_histogram_shaded.m +0 -99
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_shaded.m +0 -93
- package/vendor/dragonbox/subproject/benchmark/CMakeLists.txt +0 -65
- package/vendor/dragonbox/subproject/benchmark/include/benchmark.h +0 -40
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_benchmarks.m +0 -22
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_digit_benchmark.m +0 -78
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_uniform_benchmark.m +0 -95
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/source/benchmark.cpp +0 -238
- package/vendor/dragonbox/subproject/benchmark/source/dragonbox.cpp +0 -30
- package/vendor/dragonbox/subproject/benchmark/source/grisu_exact.cpp +0 -36
- package/vendor/dragonbox/subproject/benchmark/source/ryu.cpp +0 -27
- package/vendor/dragonbox/subproject/benchmark/source/schubfach.cpp +0 -31
- package/vendor/dragonbox/subproject/common/CMakeLists.txt +0 -42
- package/vendor/dragonbox/subproject/common/include/best_rational_approx.h +0 -97
- package/vendor/dragonbox/subproject/common/include/big_uint.h +0 -218
- package/vendor/dragonbox/subproject/common/include/continued_fractions.h +0 -174
- package/vendor/dragonbox/subproject/common/include/good_rational_approx.h +0 -267
- package/vendor/dragonbox/subproject/common/include/random_float.h +0 -182
- package/vendor/dragonbox/subproject/common/include/rational_continued_fractions.h +0 -57
- package/vendor/dragonbox/subproject/common/source/big_uint.cpp +0 -602
- package/vendor/dragonbox/subproject/meta/CMakeLists.txt +0 -41
- package/vendor/dragonbox/subproject/meta/results/binary32_generated_cache.txt +0 -82
- package/vendor/dragonbox/subproject/meta/results/binary64_compressed_cache_error_table.txt +0 -10
- package/vendor/dragonbox/subproject/meta/results/binary64_generated_cache.txt +0 -623
- package/vendor/dragonbox/subproject/meta/source/generate_cache.cpp +0 -126
- package/vendor/dragonbox/subproject/meta/source/live_test.cpp +0 -81
- package/vendor/dragonbox/subproject/meta/source/perf_test.cpp +0 -104
- package/vendor/dragonbox/subproject/meta/source/sandbox.cpp +0 -20
- package/vendor/dragonbox/subproject/test/CMakeLists.txt +0 -70
- package/vendor/dragonbox/subproject/test/results/binary32.csv +0 -255
- package/vendor/dragonbox/subproject/test/results/binary64.csv +0 -2047
- package/vendor/dragonbox/subproject/test/results/plot_required_bits.m +0 -18
- package/vendor/dragonbox/subproject/test/source/test_all_shorter_interval_cases.cpp +0 -88
- package/vendor/dragonbox/subproject/test/source/uniform_random_test.cpp +0 -95
- package/vendor/dragonbox/subproject/test/source/verify_cache_precision.cpp +0 -338
- package/vendor/dragonbox/subproject/test/source/verify_compressed_cache.cpp +0 -154
- package/vendor/dragonbox/subproject/test/source/verify_fast_multiplication.cpp +0 -168
- package/vendor/dragonbox/subproject/test/source/verify_log_computation.cpp +0 -251
- package/vendor/dragonbox/subproject/test/source/verify_magic_division.cpp +0 -113
- package/vendor/miniz/ChangeLog.md +0 -239
- package/vendor/miniz/LICENSE +0 -22
- package/vendor/miniz/examples/example1.c +0 -105
- package/vendor/miniz/examples/example2.c +0 -164
- package/vendor/miniz/examples/example3.c +0 -269
- package/vendor/miniz/examples/example4.c +0 -102
- package/vendor/miniz/examples/example5.c +0 -327
- package/vendor/miniz/examples/example6.c +0 -166
- package/vendor/miniz/miniz.c +0 -7835
- package/vendor/miniz/miniz.h +0 -1422
- package/vendor/miniz/readme.md +0 -46
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_arm64/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_arm64/koffi.lib +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_ia32/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_ia32/koffi.lib +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_x64/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_x64/koffi.lib +0 -0
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
// example3.c - Demonstrates how to use miniz.c's deflate() and inflate() functions for simple file compression.
|
|
2
|
-
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
|
3
|
-
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
|
4
|
-
#include <stdio.h>
|
|
5
|
-
#include <limits.h>
|
|
6
|
-
#include "miniz.h"
|
|
7
|
-
|
|
8
|
-
typedef unsigned char uint8;
|
|
9
|
-
typedef unsigned short uint16;
|
|
10
|
-
typedef unsigned int uint;
|
|
11
|
-
|
|
12
|
-
#define my_max(a,b) (((a) > (b)) ? (a) : (b))
|
|
13
|
-
#define my_min(a,b) (((a) < (b)) ? (a) : (b))
|
|
14
|
-
|
|
15
|
-
#define BUF_SIZE (1024 * 1024)
|
|
16
|
-
static uint8 s_inbuf[BUF_SIZE];
|
|
17
|
-
static uint8 s_outbuf[BUF_SIZE];
|
|
18
|
-
|
|
19
|
-
int main(int argc, char *argv[])
|
|
20
|
-
{
|
|
21
|
-
const char *pMode;
|
|
22
|
-
FILE *pInfile, *pOutfile;
|
|
23
|
-
uint infile_size;
|
|
24
|
-
int level = Z_BEST_COMPRESSION;
|
|
25
|
-
z_stream stream;
|
|
26
|
-
int p = 1;
|
|
27
|
-
const char *pSrc_filename;
|
|
28
|
-
const char *pDst_filename;
|
|
29
|
-
long file_loc;
|
|
30
|
-
|
|
31
|
-
printf("miniz.c version: %s\n", MZ_VERSION);
|
|
32
|
-
|
|
33
|
-
if (argc < 4)
|
|
34
|
-
{
|
|
35
|
-
printf("Usage: example3 [options] [mode:c or d] infile outfile\n");
|
|
36
|
-
printf("\nModes:\n");
|
|
37
|
-
printf("c - Compresses file infile to a zlib stream in file outfile\n");
|
|
38
|
-
printf("d - Decompress zlib stream in file infile to file outfile\n");
|
|
39
|
-
printf("\nOptions:\n");
|
|
40
|
-
printf("-l[0-10] - Compression level, higher values are slower.\n");
|
|
41
|
-
return EXIT_FAILURE;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
while ((p < argc) && (argv[p][0] == '-'))
|
|
45
|
-
{
|
|
46
|
-
switch (argv[p][1])
|
|
47
|
-
{
|
|
48
|
-
case 'l':
|
|
49
|
-
{
|
|
50
|
-
level = atoi(&argv[1][2]);
|
|
51
|
-
if ((level < 0) || (level > 10))
|
|
52
|
-
{
|
|
53
|
-
printf("Invalid level!\n");
|
|
54
|
-
return EXIT_FAILURE;
|
|
55
|
-
}
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
default:
|
|
59
|
-
{
|
|
60
|
-
printf("Invalid option: %s\n", argv[p]);
|
|
61
|
-
return EXIT_FAILURE;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
p++;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if ((argc - p) < 3)
|
|
68
|
-
{
|
|
69
|
-
printf("Must specify mode, input filename, and output filename after options!\n");
|
|
70
|
-
return EXIT_FAILURE;
|
|
71
|
-
}
|
|
72
|
-
else if ((argc - p) > 3)
|
|
73
|
-
{
|
|
74
|
-
printf("Too many filenames!\n");
|
|
75
|
-
return EXIT_FAILURE;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
pMode = argv[p++];
|
|
79
|
-
if (!strchr("cCdD", pMode[0]))
|
|
80
|
-
{
|
|
81
|
-
printf("Invalid mode!\n");
|
|
82
|
-
return EXIT_FAILURE;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
pSrc_filename = argv[p++];
|
|
86
|
-
pDst_filename = argv[p++];
|
|
87
|
-
|
|
88
|
-
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
|
89
|
-
|
|
90
|
-
// Open input file.
|
|
91
|
-
pInfile = fopen(pSrc_filename, "rb");
|
|
92
|
-
if (!pInfile)
|
|
93
|
-
{
|
|
94
|
-
printf("Failed opening input file!\n");
|
|
95
|
-
return EXIT_FAILURE;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Determine input file's size.
|
|
99
|
-
fseek(pInfile, 0, SEEK_END);
|
|
100
|
-
file_loc = ftell(pInfile);
|
|
101
|
-
fseek(pInfile, 0, SEEK_SET);
|
|
102
|
-
|
|
103
|
-
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
|
|
104
|
-
{
|
|
105
|
-
// This is not a limitation of miniz or tinfl, but this example.
|
|
106
|
-
printf("File is too large to be processed by this example.\n");
|
|
107
|
-
return EXIT_FAILURE;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
infile_size = (uint)file_loc;
|
|
111
|
-
|
|
112
|
-
// Open output file.
|
|
113
|
-
pOutfile = fopen(pDst_filename, "wb");
|
|
114
|
-
if (!pOutfile)
|
|
115
|
-
{
|
|
116
|
-
printf("Failed opening output file!\n");
|
|
117
|
-
return EXIT_FAILURE;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
printf("Input file size: %u\n", infile_size);
|
|
121
|
-
|
|
122
|
-
// Init the z_stream
|
|
123
|
-
memset(&stream, 0, sizeof(stream));
|
|
124
|
-
stream.next_in = s_inbuf;
|
|
125
|
-
stream.avail_in = 0;
|
|
126
|
-
stream.next_out = s_outbuf;
|
|
127
|
-
stream.avail_out = BUF_SIZE;
|
|
128
|
-
|
|
129
|
-
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
|
130
|
-
{
|
|
131
|
-
// Compression.
|
|
132
|
-
uint infile_remaining = infile_size;
|
|
133
|
-
|
|
134
|
-
if (deflateInit(&stream, level) != Z_OK)
|
|
135
|
-
{
|
|
136
|
-
printf("deflateInit() failed!\n");
|
|
137
|
-
return EXIT_FAILURE;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
for ( ; ; )
|
|
141
|
-
{
|
|
142
|
-
int status;
|
|
143
|
-
if (!stream.avail_in)
|
|
144
|
-
{
|
|
145
|
-
// Input buffer is empty, so read more bytes from input file.
|
|
146
|
-
uint n = my_min(BUF_SIZE, infile_remaining);
|
|
147
|
-
|
|
148
|
-
if (fread(s_inbuf, 1, n, pInfile) != n)
|
|
149
|
-
{
|
|
150
|
-
printf("Failed reading from input file!\n");
|
|
151
|
-
return EXIT_FAILURE;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
stream.next_in = s_inbuf;
|
|
155
|
-
stream.avail_in = n;
|
|
156
|
-
|
|
157
|
-
infile_remaining -= n;
|
|
158
|
-
//printf("Input bytes remaining: %u\n", infile_remaining);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
status = deflate(&stream, infile_remaining ? Z_NO_FLUSH : Z_FINISH);
|
|
162
|
-
|
|
163
|
-
if ((status == Z_STREAM_END) || (!stream.avail_out))
|
|
164
|
-
{
|
|
165
|
-
// Output buffer is full, or compression is done, so write buffer to output file.
|
|
166
|
-
uint n = BUF_SIZE - stream.avail_out;
|
|
167
|
-
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
|
168
|
-
{
|
|
169
|
-
printf("Failed writing to output file!\n");
|
|
170
|
-
return EXIT_FAILURE;
|
|
171
|
-
}
|
|
172
|
-
stream.next_out = s_outbuf;
|
|
173
|
-
stream.avail_out = BUF_SIZE;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (status == Z_STREAM_END)
|
|
177
|
-
break;
|
|
178
|
-
else if (status != Z_OK)
|
|
179
|
-
{
|
|
180
|
-
printf("deflate() failed with status %i!\n", status);
|
|
181
|
-
return EXIT_FAILURE;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (deflateEnd(&stream) != Z_OK)
|
|
186
|
-
{
|
|
187
|
-
printf("deflateEnd() failed!\n");
|
|
188
|
-
return EXIT_FAILURE;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
else if ((pMode[0] == 'd') || (pMode[0] == 'D'))
|
|
192
|
-
{
|
|
193
|
-
// Decompression.
|
|
194
|
-
uint infile_remaining = infile_size;
|
|
195
|
-
|
|
196
|
-
if (inflateInit(&stream))
|
|
197
|
-
{
|
|
198
|
-
printf("inflateInit() failed!\n");
|
|
199
|
-
return EXIT_FAILURE;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
for ( ; ; )
|
|
203
|
-
{
|
|
204
|
-
int status;
|
|
205
|
-
if (!stream.avail_in)
|
|
206
|
-
{
|
|
207
|
-
// Input buffer is empty, so read more bytes from input file.
|
|
208
|
-
uint n = my_min(BUF_SIZE, infile_remaining);
|
|
209
|
-
|
|
210
|
-
if (fread(s_inbuf, 1, n, pInfile) != n)
|
|
211
|
-
{
|
|
212
|
-
printf("Failed reading from input file!\n");
|
|
213
|
-
return EXIT_FAILURE;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
stream.next_in = s_inbuf;
|
|
217
|
-
stream.avail_in = n;
|
|
218
|
-
|
|
219
|
-
infile_remaining -= n;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
status = inflate(&stream, Z_SYNC_FLUSH);
|
|
223
|
-
|
|
224
|
-
if ((status == Z_STREAM_END) || (!stream.avail_out))
|
|
225
|
-
{
|
|
226
|
-
// Output buffer is full, or decompression is done, so write buffer to output file.
|
|
227
|
-
uint n = BUF_SIZE - stream.avail_out;
|
|
228
|
-
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
|
229
|
-
{
|
|
230
|
-
printf("Failed writing to output file!\n");
|
|
231
|
-
return EXIT_FAILURE;
|
|
232
|
-
}
|
|
233
|
-
stream.next_out = s_outbuf;
|
|
234
|
-
stream.avail_out = BUF_SIZE;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (status == Z_STREAM_END)
|
|
238
|
-
break;
|
|
239
|
-
else if (status != Z_OK)
|
|
240
|
-
{
|
|
241
|
-
printf("inflate() failed with status %i!\n", status);
|
|
242
|
-
return EXIT_FAILURE;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (inflateEnd(&stream) != Z_OK)
|
|
247
|
-
{
|
|
248
|
-
printf("inflateEnd() failed!\n");
|
|
249
|
-
return EXIT_FAILURE;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
else
|
|
253
|
-
{
|
|
254
|
-
printf("Invalid mode!\n");
|
|
255
|
-
return EXIT_FAILURE;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
fclose(pInfile);
|
|
259
|
-
if (EOF == fclose(pOutfile))
|
|
260
|
-
{
|
|
261
|
-
printf("Failed writing to output file!\n");
|
|
262
|
-
return EXIT_FAILURE;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
printf("Total input bytes: %u\n", (mz_uint32)stream.total_in);
|
|
266
|
-
printf("Total output bytes: %u\n", (mz_uint32)stream.total_out);
|
|
267
|
-
printf("Success.\n");
|
|
268
|
-
return EXIT_SUCCESS;
|
|
269
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
// example4.c - Uses tinfl.c to decompress a zlib stream in memory to an output file
|
|
2
|
-
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
|
3
|
-
#include "miniz.h"
|
|
4
|
-
#include <stdio.h>
|
|
5
|
-
#include <limits.h>
|
|
6
|
-
|
|
7
|
-
typedef unsigned char uint8;
|
|
8
|
-
typedef unsigned short uint16;
|
|
9
|
-
typedef unsigned int uint;
|
|
10
|
-
|
|
11
|
-
#define my_max(a,b) (((a) > (b)) ? (a) : (b))
|
|
12
|
-
#define my_min(a,b) (((a) < (b)) ? (a) : (b))
|
|
13
|
-
|
|
14
|
-
static int tinfl_put_buf_func(const void* pBuf, int len, void *pUser)
|
|
15
|
-
{
|
|
16
|
-
return len == (int)fwrite(pBuf, 1, len, (FILE*)pUser);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
int main(int argc, char *argv[])
|
|
20
|
-
{
|
|
21
|
-
int status;
|
|
22
|
-
FILE *pInfile, *pOutfile;
|
|
23
|
-
uint infile_size, outfile_size;
|
|
24
|
-
size_t in_buf_size;
|
|
25
|
-
uint8 *pCmp_data;
|
|
26
|
-
long file_loc;
|
|
27
|
-
|
|
28
|
-
if (argc != 3)
|
|
29
|
-
{
|
|
30
|
-
printf("Usage: example4 infile outfile\n");
|
|
31
|
-
printf("Decompresses zlib stream in file infile to file outfile.\n");
|
|
32
|
-
printf("Input file must be able to fit entirely in memory.\n");
|
|
33
|
-
printf("example3 can be used to create compressed zlib streams.\n");
|
|
34
|
-
return EXIT_FAILURE;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Open input file.
|
|
38
|
-
pInfile = fopen(argv[1], "rb");
|
|
39
|
-
if (!pInfile)
|
|
40
|
-
{
|
|
41
|
-
printf("Failed opening input file!\n");
|
|
42
|
-
return EXIT_FAILURE;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Determine input file's size.
|
|
46
|
-
fseek(pInfile, 0, SEEK_END);
|
|
47
|
-
file_loc = ftell(pInfile);
|
|
48
|
-
fseek(pInfile, 0, SEEK_SET);
|
|
49
|
-
|
|
50
|
-
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
|
|
51
|
-
{
|
|
52
|
-
// This is not a limitation of miniz or tinfl, but this example.
|
|
53
|
-
printf("File is too large to be processed by this example.\n");
|
|
54
|
-
return EXIT_FAILURE;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
infile_size = (uint)file_loc;
|
|
58
|
-
|
|
59
|
-
pCmp_data = (uint8 *)malloc(infile_size);
|
|
60
|
-
if (!pCmp_data)
|
|
61
|
-
{
|
|
62
|
-
printf("Out of memory!\n");
|
|
63
|
-
return EXIT_FAILURE;
|
|
64
|
-
}
|
|
65
|
-
if (fread(pCmp_data, 1, infile_size, pInfile) != infile_size)
|
|
66
|
-
{
|
|
67
|
-
printf("Failed reading input file!\n");
|
|
68
|
-
return EXIT_FAILURE;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Open output file.
|
|
72
|
-
pOutfile = fopen(argv[2], "wb");
|
|
73
|
-
if (!pOutfile)
|
|
74
|
-
{
|
|
75
|
-
printf("Failed opening output file!\n");
|
|
76
|
-
return EXIT_FAILURE;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
printf("Input file size: %u\n", infile_size);
|
|
80
|
-
|
|
81
|
-
in_buf_size = infile_size;
|
|
82
|
-
status = tinfl_decompress_mem_to_callback(pCmp_data, &in_buf_size, tinfl_put_buf_func, pOutfile, TINFL_FLAG_PARSE_ZLIB_HEADER);
|
|
83
|
-
if (!status)
|
|
84
|
-
{
|
|
85
|
-
printf("tinfl_decompress_mem_to_callback() failed with status %i!\n", status);
|
|
86
|
-
return EXIT_FAILURE;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
outfile_size = ftell(pOutfile);
|
|
90
|
-
|
|
91
|
-
fclose(pInfile);
|
|
92
|
-
if (EOF == fclose(pOutfile))
|
|
93
|
-
{
|
|
94
|
-
printf("Failed writing to output file!\n");
|
|
95
|
-
return EXIT_FAILURE;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
printf("Total input bytes: %u\n", (uint)in_buf_size);
|
|
99
|
-
printf("Total output bytes: %u\n", outfile_size);
|
|
100
|
-
printf("Success.\n");
|
|
101
|
-
return EXIT_SUCCESS;
|
|
102
|
-
}
|
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
// example5.c - Demonstrates how to use miniz.c's low-level tdefl_compress() and tinfl_inflate() API's for simple file to file compression/decompression.
|
|
2
|
-
// The low-level API's are the fastest, make no use of dynamic memory allocation, and are the most flexible functions exposed by miniz.c.
|
|
3
|
-
// Public domain, April 11 2012, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
|
4
|
-
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
|
5
|
-
|
|
6
|
-
// Purposely disable a whole bunch of stuff this low-level example doesn't use.
|
|
7
|
-
#define MINIZ_NO_STDIO
|
|
8
|
-
#define MINIZ_NO_ARCHIVE_APIS
|
|
9
|
-
#define MINIZ_NO_TIME
|
|
10
|
-
#define MINIZ_NO_ZLIB_APIS
|
|
11
|
-
#define MINIZ_NO_MALLOC
|
|
12
|
-
#include "miniz.h"
|
|
13
|
-
|
|
14
|
-
// Now include stdio.h because this test uses fopen(), etc. (but we still don't want miniz.c's stdio stuff, for testing).
|
|
15
|
-
#include <stdio.h>
|
|
16
|
-
#include <limits.h>
|
|
17
|
-
|
|
18
|
-
typedef unsigned char uint8;
|
|
19
|
-
typedef unsigned short uint16;
|
|
20
|
-
typedef unsigned int uint;
|
|
21
|
-
|
|
22
|
-
#define my_max(a,b) (((a) > (b)) ? (a) : (b))
|
|
23
|
-
#define my_min(a,b) (((a) < (b)) ? (a) : (b))
|
|
24
|
-
|
|
25
|
-
// IN_BUF_SIZE is the size of the file read buffer.
|
|
26
|
-
// IN_BUF_SIZE must be >= 1
|
|
27
|
-
#define IN_BUF_SIZE (1024*512)
|
|
28
|
-
static uint8 s_inbuf[IN_BUF_SIZE];
|
|
29
|
-
|
|
30
|
-
// COMP_OUT_BUF_SIZE is the size of the output buffer used during compression.
|
|
31
|
-
// COMP_OUT_BUF_SIZE must be >= 1 and <= OUT_BUF_SIZE
|
|
32
|
-
#define COMP_OUT_BUF_SIZE (1024*512)
|
|
33
|
-
|
|
34
|
-
// OUT_BUF_SIZE is the size of the output buffer used during decompression.
|
|
35
|
-
// 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)
|
|
36
|
-
//#define OUT_BUF_SIZE (TINFL_LZ_DICT_SIZE)
|
|
37
|
-
#define OUT_BUF_SIZE (1024*512)
|
|
38
|
-
static uint8 s_outbuf[OUT_BUF_SIZE];
|
|
39
|
-
|
|
40
|
-
// tdefl_compressor contains all the state needed by the low-level compressor so it's a pretty big struct (~300k).
|
|
41
|
-
// This example makes it a global vs. putting it on the stack, of course in real-world usage you'll probably malloc() or new it.
|
|
42
|
-
tdefl_compressor g_deflator;
|
|
43
|
-
|
|
44
|
-
int main(int argc, char *argv[])
|
|
45
|
-
{
|
|
46
|
-
const char *pMode;
|
|
47
|
-
FILE *pInfile, *pOutfile;
|
|
48
|
-
uint infile_size;
|
|
49
|
-
int level = 9;
|
|
50
|
-
int p = 1;
|
|
51
|
-
const char *pSrc_filename;
|
|
52
|
-
const char *pDst_filename;
|
|
53
|
-
const void *next_in = s_inbuf;
|
|
54
|
-
size_t avail_in = 0;
|
|
55
|
-
void *next_out = s_outbuf;
|
|
56
|
-
size_t avail_out = OUT_BUF_SIZE;
|
|
57
|
-
size_t total_in = 0, total_out = 0;
|
|
58
|
-
long file_loc;
|
|
59
|
-
|
|
60
|
-
assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE);
|
|
61
|
-
|
|
62
|
-
printf("miniz.c example5 (demonstrates tinfl/tdefl)\n");
|
|
63
|
-
|
|
64
|
-
if (argc < 4)
|
|
65
|
-
{
|
|
66
|
-
printf("File to file compression/decompression using the low-level tinfl/tdefl API's.\n");
|
|
67
|
-
printf("Usage: example5 [options] [mode:c or d] infile outfile\n");
|
|
68
|
-
printf("\nModes:\n");
|
|
69
|
-
printf("c - Compresses file infile to a zlib stream in file outfile\n");
|
|
70
|
-
printf("d - Decompress zlib stream in file infile to file outfile\n");
|
|
71
|
-
printf("\nOptions:\n");
|
|
72
|
-
printf("-l[0-10] - Compression level, higher values are slower, 0 is none.\n");
|
|
73
|
-
return EXIT_FAILURE;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
while ((p < argc) && (argv[p][0] == '-'))
|
|
77
|
-
{
|
|
78
|
-
switch (argv[p][1])
|
|
79
|
-
{
|
|
80
|
-
case 'l':
|
|
81
|
-
{
|
|
82
|
-
level = atoi(&argv[1][2]);
|
|
83
|
-
if ((level < 0) || (level > 10))
|
|
84
|
-
{
|
|
85
|
-
printf("Invalid level!\n");
|
|
86
|
-
return EXIT_FAILURE;
|
|
87
|
-
}
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
default:
|
|
91
|
-
{
|
|
92
|
-
printf("Invalid option: %s\n", argv[p]);
|
|
93
|
-
return EXIT_FAILURE;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
p++;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if ((argc - p) < 3)
|
|
100
|
-
{
|
|
101
|
-
printf("Must specify mode, input filename, and output filename after options!\n");
|
|
102
|
-
return EXIT_FAILURE;
|
|
103
|
-
}
|
|
104
|
-
else if ((argc - p) > 3)
|
|
105
|
-
{
|
|
106
|
-
printf("Too many filenames!\n");
|
|
107
|
-
return EXIT_FAILURE;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
pMode = argv[p++];
|
|
111
|
-
if (!strchr("cCdD", pMode[0]))
|
|
112
|
-
{
|
|
113
|
-
printf("Invalid mode!\n");
|
|
114
|
-
return EXIT_FAILURE;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
pSrc_filename = argv[p++];
|
|
118
|
-
pDst_filename = argv[p++];
|
|
119
|
-
|
|
120
|
-
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
|
121
|
-
|
|
122
|
-
// Open input file.
|
|
123
|
-
pInfile = fopen(pSrc_filename, "rb");
|
|
124
|
-
if (!pInfile)
|
|
125
|
-
{
|
|
126
|
-
printf("Failed opening input file!\n");
|
|
127
|
-
return EXIT_FAILURE;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Determine input file's size.
|
|
131
|
-
fseek(pInfile, 0, SEEK_END);
|
|
132
|
-
file_loc = ftell(pInfile);
|
|
133
|
-
fseek(pInfile, 0, SEEK_SET);
|
|
134
|
-
|
|
135
|
-
if ((file_loc < 0) || ((mz_uint64)file_loc > INT_MAX))
|
|
136
|
-
{
|
|
137
|
-
// This is not a limitation of miniz or tinfl, but this example.
|
|
138
|
-
printf("File is too large to be processed by this example.\n");
|
|
139
|
-
return EXIT_FAILURE;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
infile_size = (uint)file_loc;
|
|
143
|
-
|
|
144
|
-
// Open output file.
|
|
145
|
-
pOutfile = fopen(pDst_filename, "wb");
|
|
146
|
-
if (!pOutfile)
|
|
147
|
-
{
|
|
148
|
-
printf("Failed opening output file!\n");
|
|
149
|
-
return EXIT_FAILURE;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
printf("Input file size: %u\n", infile_size);
|
|
153
|
-
|
|
154
|
-
if ((pMode[0] == 'c') || (pMode[0] == 'C'))
|
|
155
|
-
{
|
|
156
|
-
// The number of dictionary probes to use at each compression level (0-10). 0=implies fastest/minimal possible probing.
|
|
157
|
-
static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 };
|
|
158
|
-
|
|
159
|
-
tdefl_status status;
|
|
160
|
-
uint infile_remaining = infile_size;
|
|
161
|
-
|
|
162
|
-
// 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).
|
|
163
|
-
mz_uint comp_flags = TDEFL_WRITE_ZLIB_HEADER | s_tdefl_num_probes[MZ_MIN(10, level)] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0);
|
|
164
|
-
if (!level)
|
|
165
|
-
comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS;
|
|
166
|
-
|
|
167
|
-
// Initialize the low-level compressor.
|
|
168
|
-
status = tdefl_init(&g_deflator, NULL, NULL, comp_flags);
|
|
169
|
-
if (status != TDEFL_STATUS_OKAY)
|
|
170
|
-
{
|
|
171
|
-
printf("tdefl_init() failed!\n");
|
|
172
|
-
return EXIT_FAILURE;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
avail_out = COMP_OUT_BUF_SIZE;
|
|
176
|
-
|
|
177
|
-
// Compression.
|
|
178
|
-
for ( ; ; )
|
|
179
|
-
{
|
|
180
|
-
size_t in_bytes, out_bytes;
|
|
181
|
-
|
|
182
|
-
if (!avail_in)
|
|
183
|
-
{
|
|
184
|
-
// Input buffer is empty, so read more bytes from input file.
|
|
185
|
-
uint n = my_min(IN_BUF_SIZE, infile_remaining);
|
|
186
|
-
|
|
187
|
-
if (fread(s_inbuf, 1, n, pInfile) != n)
|
|
188
|
-
{
|
|
189
|
-
printf("Failed reading from input file!\n");
|
|
190
|
-
return EXIT_FAILURE;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
next_in = s_inbuf;
|
|
194
|
-
avail_in = n;
|
|
195
|
-
|
|
196
|
-
infile_remaining -= n;
|
|
197
|
-
//printf("Input bytes remaining: %u\n", infile_remaining);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
in_bytes = avail_in;
|
|
201
|
-
out_bytes = avail_out;
|
|
202
|
-
// Compress as much of the input as possible (or all of it) to the output buffer.
|
|
203
|
-
status = tdefl_compress(&g_deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
|
|
204
|
-
|
|
205
|
-
next_in = (const char *)next_in + in_bytes;
|
|
206
|
-
avail_in -= in_bytes;
|
|
207
|
-
total_in += in_bytes;
|
|
208
|
-
|
|
209
|
-
next_out = (char *)next_out + out_bytes;
|
|
210
|
-
avail_out -= out_bytes;
|
|
211
|
-
total_out += out_bytes;
|
|
212
|
-
|
|
213
|
-
if ((status != TDEFL_STATUS_OKAY) || (!avail_out))
|
|
214
|
-
{
|
|
215
|
-
// Output buffer is full, or compression is done or failed, so write buffer to output file.
|
|
216
|
-
uint n = COMP_OUT_BUF_SIZE - (uint)avail_out;
|
|
217
|
-
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
|
218
|
-
{
|
|
219
|
-
printf("Failed writing to output file!\n");
|
|
220
|
-
return EXIT_FAILURE;
|
|
221
|
-
}
|
|
222
|
-
next_out = s_outbuf;
|
|
223
|
-
avail_out = COMP_OUT_BUF_SIZE;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (status == TDEFL_STATUS_DONE)
|
|
227
|
-
{
|
|
228
|
-
// Compression completed successfully.
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
else if (status != TDEFL_STATUS_OKAY)
|
|
232
|
-
{
|
|
233
|
-
// Compression somehow failed.
|
|
234
|
-
printf("tdefl_compress() failed with status %i!\n", status);
|
|
235
|
-
return EXIT_FAILURE;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
else if ((pMode[0] == 'd') || (pMode[0] == 'D'))
|
|
240
|
-
{
|
|
241
|
-
// Decompression.
|
|
242
|
-
uint infile_remaining = infile_size;
|
|
243
|
-
|
|
244
|
-
tinfl_decompressor inflator;
|
|
245
|
-
tinfl_init(&inflator);
|
|
246
|
-
|
|
247
|
-
for ( ; ; )
|
|
248
|
-
{
|
|
249
|
-
size_t in_bytes, out_bytes;
|
|
250
|
-
tinfl_status status;
|
|
251
|
-
if (!avail_in)
|
|
252
|
-
{
|
|
253
|
-
// Input buffer is empty, so read more bytes from input file.
|
|
254
|
-
uint n = my_min(IN_BUF_SIZE, infile_remaining);
|
|
255
|
-
|
|
256
|
-
if (fread(s_inbuf, 1, n, pInfile) != n)
|
|
257
|
-
{
|
|
258
|
-
printf("Failed reading from input file!\n");
|
|
259
|
-
return EXIT_FAILURE;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
next_in = s_inbuf;
|
|
263
|
-
avail_in = n;
|
|
264
|
-
|
|
265
|
-
infile_remaining -= n;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
in_bytes = avail_in;
|
|
269
|
-
out_bytes = avail_out;
|
|
270
|
-
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);
|
|
271
|
-
|
|
272
|
-
avail_in -= in_bytes;
|
|
273
|
-
next_in = (const mz_uint8 *)next_in + in_bytes;
|
|
274
|
-
total_in += in_bytes;
|
|
275
|
-
|
|
276
|
-
avail_out -= out_bytes;
|
|
277
|
-
next_out = (mz_uint8 *)next_out + out_bytes;
|
|
278
|
-
total_out += out_bytes;
|
|
279
|
-
|
|
280
|
-
if ((status <= TINFL_STATUS_DONE) || (!avail_out))
|
|
281
|
-
{
|
|
282
|
-
// Output buffer is full, or decompression is done, so write buffer to output file.
|
|
283
|
-
uint n = OUT_BUF_SIZE - (uint)avail_out;
|
|
284
|
-
if (fwrite(s_outbuf, 1, n, pOutfile) != n)
|
|
285
|
-
{
|
|
286
|
-
printf("Failed writing to output file!\n");
|
|
287
|
-
return EXIT_FAILURE;
|
|
288
|
-
}
|
|
289
|
-
next_out = s_outbuf;
|
|
290
|
-
avail_out = OUT_BUF_SIZE;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// If status is <= TINFL_STATUS_DONE then either decompression is done or something went wrong.
|
|
294
|
-
if (status <= TINFL_STATUS_DONE)
|
|
295
|
-
{
|
|
296
|
-
if (status == TINFL_STATUS_DONE)
|
|
297
|
-
{
|
|
298
|
-
// Decompression completed successfully.
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
else
|
|
302
|
-
{
|
|
303
|
-
// Decompression failed.
|
|
304
|
-
printf("tinfl_decompress() failed with status %i!\n", status);
|
|
305
|
-
return EXIT_FAILURE;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
else
|
|
311
|
-
{
|
|
312
|
-
printf("Invalid mode!\n");
|
|
313
|
-
return EXIT_FAILURE;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
fclose(pInfile);
|
|
317
|
-
if (EOF == fclose(pOutfile))
|
|
318
|
-
{
|
|
319
|
-
printf("Failed writing to output file!\n");
|
|
320
|
-
return EXIT_FAILURE;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
printf("Total input bytes: %u\n", (mz_uint32)total_in);
|
|
324
|
-
printf("Total output bytes: %u\n", (mz_uint32)total_out);
|
|
325
|
-
printf("Success.\n");
|
|
326
|
-
return EXIT_SUCCESS;
|
|
327
|
-
}
|