mirror of
https://github.com/eledio-devices/thirdparty-miniz.git
synced 2025-11-01 16:14:13 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04debb7192 |
10
example1.c
10
example1.c
@@ -1,5 +1,5 @@
|
||||
// example1.c - Demonstrates miniz.c's compress() and uncompress() functions (same as zlib's).
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com
|
||||
#include "miniz.c"
|
||||
|
||||
typedef unsigned char uint8;
|
||||
@@ -26,13 +26,11 @@ int main(int argc, char *argv[])
|
||||
uint total_succeeded = 0;
|
||||
argc, argv;
|
||||
|
||||
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);
|
||||
pCmp = (mz_uint8 *)malloc(cmp_len);
|
||||
pUncomp = (mz_uint8 *)malloc(src_len);
|
||||
if ((!pCmp) || (!pUncomp))
|
||||
{
|
||||
printf("Out of memory!\n");
|
||||
@@ -83,7 +81,7 @@ int main(int argc, char *argv[])
|
||||
printf("Decompressed from %u to %u bytes\n", cmp_len, uncomp_len);
|
||||
|
||||
// Ensure uncompress() returned the expected data.
|
||||
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, (size_t)src_len)))
|
||||
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, src_len)))
|
||||
{
|
||||
printf("Decompression failed!\n");
|
||||
free(pCmp);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -94,7 +94,7 @@
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -167,7 +167,7 @@
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
@@ -244,7 +244,7 @@
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// example2.c - Simple demonstration of miniz.c's ZIP archive API's.
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com
|
||||
#include "miniz.c"
|
||||
|
||||
typedef unsigned char uint8;
|
||||
@@ -26,8 +26,6 @@ int main(int argc, char *argv[])
|
||||
mz_zip_archive zip_archive;
|
||||
void *p;
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
argc, argv;
|
||||
|
||||
// Append a bunch of text files to test.zip
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -94,7 +94,7 @@
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -167,7 +167,7 @@
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
@@ -244,7 +244,7 @@
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
|
||||
69
example3.c
69
example3.c
@@ -1,5 +1,5 @@
|
||||
// example3.c - Demonstrates how to use miniz.c's deflate() and inflate() functions for simple file compression.
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com
|
||||
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
||||
#include "miniz.c"
|
||||
|
||||
@@ -19,73 +19,20 @@ int main(int argc, char *argv[])
|
||||
const char *pMode;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size;
|
||||
int level = Z_BEST_COMPRESSION;
|
||||
z_stream stream;
|
||||
int n = 1;
|
||||
const char *pSrc_filename;
|
||||
const char *pDst_filename;
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
if (argc < 4)
|
||||
if (argc != 4)
|
||||
{
|
||||
printf("Usage: example3 [options] [mode:c or d] infile outfile\n");
|
||||
printf("\nModes:\n");
|
||||
printf("Usage: example3 [c/d] infile outfile\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 ((n < argc) && (argv[n][0] == '-'))
|
||||
{
|
||||
switch (argv[n][1])
|
||||
{
|
||||
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[n]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
if ((argc - n) < 3)
|
||||
{
|
||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if ((argc - n) > 3)
|
||||
{
|
||||
printf("Too many filenames!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pMode = argv[n++];
|
||||
if (!strchr("cCdD", pMode[0]))
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pSrc_filename = argv[n++];
|
||||
pDst_filename = argv[n++];
|
||||
|
||||
printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);
|
||||
pMode = argv[1];
|
||||
|
||||
// Open input file.
|
||||
pInfile = fopen(pSrc_filename, "rb");
|
||||
pInfile = fopen(argv[2], "rb");
|
||||
if (!pInfile)
|
||||
{
|
||||
printf("Failed opening input file!\n");
|
||||
@@ -98,7 +45,7 @@ int main(int argc, char *argv[])
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
// Open output file.
|
||||
pOutfile = fopen(pDst_filename, "wb");
|
||||
pOutfile = fopen(argv[3], "wb");
|
||||
if (!pOutfile)
|
||||
{
|
||||
printf("Failed opening output file!\n");
|
||||
@@ -119,7 +66,7 @@ int main(int argc, char *argv[])
|
||||
// Compression.
|
||||
uint infile_remaining = infile_size;
|
||||
|
||||
if (deflateInit(&stream, level) != Z_OK)
|
||||
if (deflateInit(&stream, Z_BEST_COMPRESSION) != Z_OK)
|
||||
{
|
||||
printf("deflateInit() failed!\n");
|
||||
return EXIT_FAILURE;
|
||||
@@ -143,7 +90,7 @@ int main(int argc, char *argv[])
|
||||
stream.avail_in = n;
|
||||
|
||||
infile_remaining -= n;
|
||||
//printf("Input bytes remaining: %u\n", infile_remaining);
|
||||
printf("Input bytes remaining: %u\n", infile_remaining);
|
||||
}
|
||||
|
||||
status = deflate(&stream, infile_remaining ? Z_NO_FLUSH : Z_FINISH);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -94,7 +94,7 @@
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -167,7 +167,7 @@
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
@@ -244,7 +244,7 @@
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// 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.
|
||||
// Public domain, May 15 2011, Rich Geldreich, richgel99@gmail.com
|
||||
#include "tinfl.c"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -94,7 +94,7 @@
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
@@ -167,7 +167,7 @@
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
@@ -244,7 +244,7 @@
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
|
||||
295
example5.c
295
example5.c
@@ -1,295 +0,0 @@
|
||||
// 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.
|
||||
// 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.
|
||||
// Public domain, April 11 2012, Rich Geldreich, richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
// For simplicity, this example is limited to files smaller than 4GB, but this is not a limitation of miniz.c.
|
||||
#include "miniz.c"
|
||||
|
||||
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))
|
||||
|
||||
// IN_BUF_SIZE is the size of the file read buffer.
|
||||
// IN_BUF_SIZE must be >= 1
|
||||
#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)
|
||||
|
||||
// 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)
|
||||
static uint8 s_outbuf[OUT_BUF_SIZE];
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *pMode;
|
||||
FILE *pInfile, *pOutfile;
|
||||
uint infile_size;
|
||||
int level = Z_BEST_COMPRESSION;
|
||||
int n = 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;
|
||||
|
||||
assert(COMP_OUT_BUF_SIZE <= OUT_BUF_SIZE);
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
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 ((n < argc) && (argv[n][0] == '-'))
|
||||
{
|
||||
switch (argv[n][1])
|
||||
{
|
||||
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[n]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
if ((argc - n) < 3)
|
||||
{
|
||||
printf("Must specify mode, input filename, and output filename after options!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
else if ((argc - n) > 3)
|
||||
{
|
||||
printf("Too many filenames!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pMode = argv[n++];
|
||||
if (!strchr("cCdD", pMode[0]))
|
||||
{
|
||||
printf("Invalid mode!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pSrc_filename = argv[n++];
|
||||
pDst_filename = argv[n++];
|
||||
|
||||
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);
|
||||
infile_size = ftell(pInfile);
|
||||
fseek(pInfile, 0, SEEK_SET);
|
||||
|
||||
// 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'))
|
||||
{
|
||||
uint infile_remaining = infile_size;
|
||||
uint comp_flags = tdefl_create_comp_flags_from_zip_params(level, MZ_DEFAULT_WINDOW_BITS, MZ_DEFAULT_STRATEGY) | TDEFL_WRITE_ZLIB_HEADER;
|
||||
|
||||
// Initialize the low-level compressor.
|
||||
tdefl_compressor deflator;
|
||||
tdefl_status status = tdefl_init(&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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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(&deflator, next_in, &in_bytes, next_out, &out_bytes, infile_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH);
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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", total_in);
|
||||
printf("Total output bytes: %u\n", total_out);
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
346
example5.vcproj
346
example5.vcproj
@@ -1,346 +0,0 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="9.00"
|
||||
Name="example5"
|
||||
ProjectGUID="{AE293522-92D8-4B60-95C7-B4AEE10A303F}"
|
||||
RootNamespace="example5"
|
||||
Keyword="Win32Proj"
|
||||
TargetFrameworkVersion="196613"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
<Platform
|
||||
Name="x64"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)\$(ProjectName)D.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Debug|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_x64D.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="17"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|x64"
|
||||
OutputDirectory="$(SolutionDir)bin"
|
||||
IntermediateDirectory="$(ProjectName)\$(ConfigurationName)_$(PlatformName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
TargetEnvironment="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="3"
|
||||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS"
|
||||
RuntimeLibrary="0"
|
||||
EnableFunctionLevelLinking="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="4"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
OutputFile="$(OutDir)\$(ProjectName)_x64.exe"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="17"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FD737F1-C7A5-4376-A066-2A32D752A31F}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\example5.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{17DA6AB6-F800-4c08-8B7A-83BB121AAC02}"
|
||||
>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
10
examples.sln
10
examples.sln
@@ -9,8 +9,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example3", "example3.vcproj
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example4", "example4.vcproj", "{AE293522-92D8-4B60-95C7-C3AEE10A303F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example5", "example5.vcproj", "{AE293522-92D8-4B60-95C7-B4AEE10A303F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
@@ -51,14 +49,6 @@ Global
|
||||
{AE293522-92D8-4B60-95C7-C3AEE10A303F}.Release|Win32.Build.0 = Release|Win32
|
||||
{AE293522-92D8-4B60-95C7-C3AEE10A303F}.Release|x64.ActiveCfg = Release|x64
|
||||
{AE293522-92D8-4B60-95C7-C3AEE10A303F}.Release|x64.Build.0 = Release|x64
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Debug|x64.Build.0 = Debug|x64
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|Win32.Build.0 = Release|Win32
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|x64.ActiveCfg = Release|x64
|
||||
{AE293522-92D8-4B60-95C7-B4AEE10A303F}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
38
tinfl.c
38
tinfl.c
@@ -1,6 +1,5 @@
|
||||
/* tinfl.c v1.11 - public domain inflate with zlib header parsing/adler32 checking (inflate-only subset of miniz.c)
|
||||
See "unlicense" statement at the end of this file.
|
||||
Rich Geldreich <richgel99@gmail.com>, last updated May 20, 2011
|
||||
/* tinfl.c v1.09 - public domain inflate with zlib header parsing/adler32 checking (inflate-only subset of miniz.c)
|
||||
Rich Geldreich <richgel99@gmail.com>, last updated May 15, 2011
|
||||
Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt
|
||||
|
||||
The entire decompressor coroutine is implemented in tinfl_decompress(). The other functions are optional high-level helpers.
|
||||
@@ -32,11 +31,7 @@ typedef unsigned long long mz_uint64;
|
||||
// Works around MSVC's spammy "warning C4127: conditional expression is constant" message.
|
||||
#define MZ_MACRO_END while (0, 0)
|
||||
|
||||
// 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.
|
||||
// Decompression flags.
|
||||
enum
|
||||
{
|
||||
TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
|
||||
@@ -559,30 +554,3 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size,
|
||||
}
|
||||
|
||||
#endif // #ifndef TINFL_HEADER_FILE_ONLY
|
||||
|
||||
/*
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user