miniz.c updated to v1.10 - substantial compressor optimizations, fixed minor issue with unsigned long type, added level commmand line option parsing to example3

This commit is contained in:
richgel99@gmail.com
2011-05-28 13:52:24 +00:00
parent fda66cc357
commit 9560a0a51d
5 changed files with 685 additions and 216 deletions

View File

@@ -26,11 +26,13 @@ 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(cmp_len);
pUncomp = (mz_uint8 *)malloc(src_len);
pCmp = (mz_uint8 *)malloc((size_t)cmp_len);
pUncomp = (mz_uint8 *)malloc((size_t)src_len);
if ((!pCmp) || (!pUncomp))
{
printf("Out of memory!\n");
@@ -81,7 +83,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, src_len)))
if ((uncomp_len != src_len) || (memcmp(pUncomp, s_pStr, (size_t)src_len)))
{
printf("Decompression failed!\n");
free(pCmp);

View File

@@ -8,13 +8,13 @@ typedef unsigned int uint;
// The string to compress.
static const char *s_pStr =
"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";
@@ -26,6 +26,8 @@ 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

View File

@@ -19,20 +19,73 @@ 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;
if (argc != 4)
printf("miniz.c version: %s\n", MZ_VERSION);
if (argc < 4)
{
printf("Usage: example3 [c/d] infile outfile\n");
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;
}
pMode = argv[1];
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(argv[2], "rb");
pInfile = fopen(pSrc_filename, "rb");
if (!pInfile)
{
printf("Failed opening input file!\n");
@@ -45,7 +98,7 @@ int main(int argc, char *argv[])
fseek(pInfile, 0, SEEK_SET);
// Open output file.
pOutfile = fopen(argv[3], "wb");
pOutfile = fopen(pDst_filename, "wb");
if (!pOutfile)
{
printf("Failed opening output file!\n");
@@ -66,7 +119,7 @@ int main(int argc, char *argv[])
// Compression.
uint infile_remaining = infile_size;
if (deflateInit(&stream, Z_BEST_COMPRESSION) != Z_OK)
if (deflateInit(&stream, level) != Z_OK)
{
printf("deflateInit() failed!\n");
return EXIT_FAILURE;
@@ -90,7 +143,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);

804
miniz.c

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/* 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
/* tinfl.c v1.10 - public domain inflate with zlib header parsing/adler32 checking (inflate-only subset of miniz.c)
Rich Geldreich <richgel99@gmail.com>, last updated May 20, 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.