I tried to unzip a binary file to a membuf from a zip archive using Lucian Wischik's Zip Utils:
http://www.wischik.com/lu/programmer/zip_utils.html
http://www.codeproject.com/KB/files/zip_utils.aspx
FindZipItem(hz, filename.c_str(), true, &j, &ze);
char *content = new char[ze.unc_size];
UnzipItem(hz, j, content, ze.unc_size);
delete[] content;
But it didn't unzip the file correctly. It stopped at the first 0x00
of the file.
For example when I unzip an MP3 file inside a ZIP archive, it will only unzi开发者_开发知识库p the first 4 bytes: 0x49443303
(ID3\0) because the 5th to 8th byte is 0x00
.
I also tried to capture the ZR_RESULT
, and it always return ZR_OK
(which means completed without errors).
I think this guy also had the same problem, but no one replied to his question:
http://www.codeproject.com/KB/files/zip_utils.aspx?msg=2876222#xx2876222xx
Any kind of help would be appreciated :)
It may be unzipping just fine. Keep in mind that many string oriented display functions will stop outputting characters at the first '\0'
. Even your debugger will display a char*
as if it were a string in your watch window. It can only guess what the data is in a character array... How are you testing how many bytes were unzipping?
You may want to try something like this:
FindZipItem(hz, filename.c_str(), true, &j, &ze);
char *content = new char[ze.unc_size];
memset(content, 0, ze.unc_size); // added so we can say that if it has a bunch of 0 bytes, then the unzip stopped early.
UnzipItem(hz, j, content, ze.unc_size);
// will print in hex all of the bytes in the array
for(int i = 0; i < ze.unc_size; ++i) {
printf("%02x ", content[i]);
}
delete[] content;
I have two answers.
First, if you try to unzip an MP3 file. You are wrong. MP3 files are compressed, but not using the zip format.
Second, how do you know that the library is only unzipping the first 4 bytes. Do you try to printf()
the content? Or to strcpy()
it? In which case, the behavior is normal, as these functions are meant to treat text, which is defined as everything-until-the-first-char-0.
精彩评论