1. See http://www.codeproject.com/KB/files/zip_utils.aspx
2. Include the header file # include "Zip. H", # include "Unzip. H", which is already detailed in the original article.
3. It is emphasized that the number of bytes must be increased by 1 when extracting data to the memory.
Hzip Hz = openzip (filename, 0); // read the zip package </P> <p> // set the decompressed directory <br/> setunzipbasedir (Hz, _ T (". // readzip // test "); </P> <p> If (HZ = NULL) <br/>{< br/> afxmessagebox ("failed to read"); <br/> return; <br/>}</P> <p> int I; </P> <p> zipentry ze; </P> <p> zresult result = findzipitem (Hz, _ T ("index.csv"), true, & I, & ze); </P> <p> If (result = zr_notfound) <br/>{< br/> closezip (HZ ); <br/> afxmessagebox ("failed to find the index.csv file"); <br/> return; <br/>}</P> <p> // decompress the package to the memory <br/> ibuf = new char [Ze. unc_size + 1]; <br/> memset (ibuf, 0, Ze. unc_size + 1); <br/> unzipitem (Hz, I, ibuf, Ze. unc_size); </P> <p> //-finished-<br/> closezip (HZ );
Ze. unc_size is the size of the file, so you must add one more byte to the end. Otherwise, garbled characters may occur in the last line when parsing the file. Should be ze. unc_size + 1