2

My requirement is to unzip a zip file I am receiving from the server on Linux platform. Now my C/C++ code should unzip the folder to receive the json files.

I did my research online and found I can use zlib library for this purpose, but zlib can not unzip a .zip file but it has in its contrib folder minizip which can be used for this purpose.

Referred: Simple way to unzip a .zip file using zlib

I downloaded zlib source file: zlib source code, version 1.2.8, zipfile format (678K, MD5 checksum 126f8676442ffbd97884eb4d6f32afb4) from http://www.zlib.net/

Now I go to zlib-1.2.8\contrib\minizip and try to compile miniunz.c

I try make all but getting below error:

[@DELL-BUILD03 minizip]$ make
cc -c -O -I../.. miniunz.c
cc -c -O -I../.. unzip.c
cc -c -O -I../.. ioapi.c
make: *** No rule to make target `../../libz.a', needed by `miniunz'.  Stop.

I tried manually placing a pre compiled libz.a in zlib-1.2.8 folder.

But still the same error. How do I proceed and unzip a sample json.zip folder?

Community
  • 1
  • 1
Gaurav K
  • 2,864
  • 9
  • 39
  • 68
  • 1
    If file exists and have adequate last modification date, it should work. I would recommend looking at https://code.google.com/p/miniz/ though, very nice single source file zip handler. – keltar Sep 09 '14 at 04:23
  • 1
    Build zlib two directories down using make, and it will leave a libz.a there. Then do the make in the minizip directory. – Mark Adler Sep 09 '14 at 04:33
  • @MarkAdler I did try placing pre compiled `libz.a` there but still same error. `zlib` make does not have any `target` or `build rule` – Gaurav K Sep 09 '14 at 04:44
  • @keltar Tried `miniz` as well .. Again I am trying with it.. Using precompiled `example4` for my `json.zip` ----- Got below error `[DELL-BUILD03 bin_linux]$ ./example4 json.zip a.txt Input file size: 266631 tinfl_decompress_mem_to_callback() failed with status 0! [DELL-BUILD03 bin_linux]$ ` – Gaurav K Sep 09 '14 at 04:45
  • @keltar Tried `miniz` .. It is able to decompress the file which it compressed itself.. The file received by server is giving above error.. The structure of received zip file is `json.zip-> it contains one file 320458_0902_00_05_502cf.json` – Gaurav K Sep 09 '14 at 05:02
  • @GauravK function you referred to expects zlib stream as input, not zip structure. To read zip structure with miniz you should use `mz_zip_reader_init_file`, `mz_zip_reader_get_num_fieles`, etc.. – keltar Sep 09 '14 at 05:41
  • @keltar That example I used successfully to `zip` and `unzip` a file say `a.json`. But for a `zipped file` (same structure which it successfully unzipped) which has been sent by a server, it is unable to unzip.So basically, it is able to `unzip` a file which has been `zipped` by itself – Gaurav K Sep 09 '14 at 07:10
  • @GauravK you obviously doing it wrong. But that's a separate question. "It doesn't work" couldn't be helped without good specifics. – keltar Sep 09 '14 at 08:05

1 Answers1

4

Resolved the error by running make first in zlib-1.2.3 and then make in minizip

Gaurav K
  • 2,864
  • 9
  • 39
  • 68