Created
          August 24, 2021 14:23 
        
      - 
      
- 
        Save wernsey/4cd9c8ebaa7223f93f32b8c138dd9ccc to your computer and use it in GitHub Desktop. 
    Test program for miniz (https://github.com/richgel999/miniz)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Test program for miniz (https://github.com/richgel999/miniz) | |
| #include <stdio.h> | |
| #include "../miniz.h" | |
| int main(int argc, char *argv[]) { | |
| mz_zip_archive zip; | |
| int i; | |
| if(argc < 2) { | |
| fprintf(stderr, "error: no input file\n"); | |
| return 1; | |
| } | |
| mz_zip_zero_struct(&zip); | |
| if(!mz_zip_reader_init_file(&zip, argv[1], 0)) { | |
| fprintf(stderr, "error: mz_zip_reader_init_file: %s\n", mz_zip_get_error_string(mz_zip_get_last_error(&zip))); | |
| return 1; | |
| } | |
| for(i = 0; i < mz_zip_reader_get_num_files(&zip); i++) { | |
| mz_zip_archive_file_stat stat; | |
| char name[256]; | |
| mz_zip_reader_get_filename(&zip, i, name, sizeof name); | |
| if(mz_zip_reader_is_file_a_directory(&zip, i)) { | |
| printf("Directory: %s\n", name); | |
| continue; | |
| } else if(!mz_zip_reader_is_file_supported(&zip, i)) { | |
| fprintf(stderr, "Unsupported file: %s\n", name); | |
| continue; | |
| } | |
| printf("%-2d: File: %s\n", i, name); | |
| if(!mz_zip_reader_file_stat(&zip, i, &stat)) { | |
| fprintf(stderr, "error: mz_zip_reader_file_stat: %s\n", mz_zip_get_error_string(mz_zip_get_last_error(&zip))); | |
| return 1; | |
| } | |
| printf(" - compressed size ......: %llu\n", stat.m_comp_size); | |
| printf(" - uncompressed size ....: %llu\n", stat.m_uncomp_size); | |
| printf(" - comment ..............: %s\n", stat.m_comment); | |
| size_t size; | |
| void *p = mz_zip_reader_extract_to_heap(&zip, i, &size, 0); | |
| if(!p) { | |
| fprintf(stderr, "error: mz_zip_reader_file_stat: %s\n", mz_zip_get_error_string(mz_zip_get_last_error(&zip))); | |
| return 1; | |
| } | |
| printf(" %u bytes extracted\n", size); | |
| mz_free(p); | |
| } | |
| //const char *search = "README.MD"; | |
| const char *search = "example6.c"; | |
| i = mz_zip_reader_locate_file(&zip, search, NULL, MZ_ZIP_FLAG_IGNORE_PATH); | |
| if(i >= 0) { | |
| printf("%s @ %d\n", search, i); | |
| } else { | |
| printf("Couldn't locate %s\n", search); | |
| } | |
| printf("done.\n"); | |
| mz_zip_reader_end(&zip); | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment