mirror of
				https://github.com/eledio-devices/thirdparty-miniz.git
				synced 2025-10-31 08:42:39 +01:00 
			
		
		
		
	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:
		| @@ -26,11 +26,13 @@ int main(int argc, char *argv[]) | |||||||
|   uint total_succeeded = 0; |   uint total_succeeded = 0; | ||||||
|   argc, argv; |   argc, argv; | ||||||
|  |  | ||||||
|  |   printf("miniz.c version: %s\n", MZ_VERSION); | ||||||
|  |  | ||||||
|   do |   do | ||||||
|   { |   { | ||||||
|     // Allocate buffers to hold compressed and uncompressed data. |     // Allocate buffers to hold compressed and uncompressed data. | ||||||
|     pCmp = (mz_uint8 *)malloc(cmp_len); |     pCmp = (mz_uint8 *)malloc((size_t)cmp_len); | ||||||
|     pUncomp = (mz_uint8 *)malloc(src_len); |     pUncomp = (mz_uint8 *)malloc((size_t)src_len); | ||||||
|     if ((!pCmp) || (!pUncomp)) |     if ((!pCmp) || (!pUncomp)) | ||||||
|     { |     { | ||||||
|       printf("Out of memory!\n"); |       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); |       printf("Decompressed from %u to %u bytes\n", cmp_len, uncomp_len); | ||||||
|  |  | ||||||
|       // Ensure uncompress() returned the expected data. |       // 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"); |         printf("Decompression failed!\n"); | ||||||
|         free(pCmp); |         free(pCmp); | ||||||
|   | |||||||
| @@ -26,6 +26,8 @@ int main(int argc, char *argv[]) | |||||||
|   mz_zip_archive zip_archive;  |   mz_zip_archive zip_archive;  | ||||||
|   void *p; |   void *p; | ||||||
|  |  | ||||||
|  |   printf("miniz.c version: %s\n", MZ_VERSION); | ||||||
|  |  | ||||||
|   argc, argv; |   argc, argv; | ||||||
|  |  | ||||||
|   // Append a bunch of text files to test.zip |   // Append a bunch of text files to test.zip | ||||||
|   | |||||||
							
								
								
									
										67
									
								
								example3.c
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								example3.c
									
									
									
									
									
								
							| @@ -19,20 +19,73 @@ int main(int argc, char *argv[]) | |||||||
|   const char *pMode; |   const char *pMode; | ||||||
|   FILE *pInfile, *pOutfile; |   FILE *pInfile, *pOutfile; | ||||||
|   uint infile_size; |   uint infile_size; | ||||||
|  |   int level = Z_BEST_COMPRESSION; | ||||||
|   z_stream stream; |   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("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("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; |     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. |   // Open input file. | ||||||
|   pInfile = fopen(argv[2], "rb"); |   pInfile = fopen(pSrc_filename, "rb"); | ||||||
|   if (!pInfile) |   if (!pInfile) | ||||||
|   { |   { | ||||||
|     printf("Failed opening input file!\n"); |     printf("Failed opening input file!\n"); | ||||||
| @@ -45,7 +98,7 @@ int main(int argc, char *argv[]) | |||||||
|   fseek(pInfile, 0, SEEK_SET); |   fseek(pInfile, 0, SEEK_SET); | ||||||
|  |  | ||||||
|   // Open output file. |   // Open output file. | ||||||
|   pOutfile = fopen(argv[3], "wb"); |   pOutfile = fopen(pDst_filename, "wb"); | ||||||
|   if (!pOutfile) |   if (!pOutfile) | ||||||
|   { |   { | ||||||
|     printf("Failed opening output file!\n"); |     printf("Failed opening output file!\n"); | ||||||
| @@ -66,7 +119,7 @@ int main(int argc, char *argv[]) | |||||||
|     // Compression. |     // Compression. | ||||||
|     uint infile_remaining = infile_size; |     uint infile_remaining = infile_size; | ||||||
|  |  | ||||||
|     if (deflateInit(&stream, Z_BEST_COMPRESSION) != Z_OK) |     if (deflateInit(&stream, level) != Z_OK) | ||||||
|     { |     { | ||||||
|       printf("deflateInit() failed!\n"); |       printf("deflateInit() failed!\n"); | ||||||
|       return EXIT_FAILURE; |       return EXIT_FAILURE; | ||||||
| @@ -90,7 +143,7 @@ int main(int argc, char *argv[]) | |||||||
|         stream.avail_in = n; |         stream.avail_in = n; | ||||||
|          |          | ||||||
|         infile_remaining -= 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); |       status = deflate(&stream, infile_remaining ? Z_NO_FLUSH : Z_FINISH); | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								tinfl.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tinfl.c
									
									
									
									
									
								
							| @@ -1,5 +1,5 @@ | |||||||
| /* tinfl.c v1.09 - public domain inflate with zlib header parsing/adler32 checking (inflate-only subset of miniz.c) | /* 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 15, 2011 |    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 |    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. |    The entire decompressor coroutine is implemented in tinfl_decompress(). The other functions are optional high-level helpers. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user