c++ - Using zlib with mingw -
i trying read test.zip file using zlib library , extract contents. requirement read each file , output content (unzipped) first memory , file.
i tried below code:
#include <iostream> #include <zlib.h> using namespace std; #define line 1024 int main() { const char *filename = "hello.zip"; gzfile infilez = gzopen(filename, "rb"); if (infilez == null) { printf("error: failed gzopen %s\n", filename); return -1; } unsigned char unzipbuffer[8192]; unsigned int unzippedbytes; std::vector<unsigned char> unzippeddata; while (true) { unzippedbytes = gzread(infilez, unzipbuffer, 8192); if (unzippedbytes > 0) { cout << unzippedbytes << endl; (int = 0; < unzippedbytes; i++) { cout << unzipbuffer[i]; } } else { break; } } gzclose(infilez); return 0; }
i got above example web. mentioned gzread
inflates contents , fills buffer (here unzipbuffer
). when tried print it, printing same contents of .zip file (example pk.....
non readable code).
i believe not correctly using apis of zlib. not find example related this. can me here?
the zlib library not directly process zip format. zlib provides raw deflate compression , decompression need process deflated zip entries, crc-32 calculation facility. need write own code or use library parse , process zip format.
gzip not zip. 2 different formats use, or may use, same raw compression format within.
Comments
Post a Comment