My intention is to create a ZIP file on disk and stream in-memory files into the archive, possibly several GB large.
With the following minimum working example
void* zipWriter = nullptr;
void* zipStream = nullptr;
mz_stream_os_create(&zipStream);
mz_stream_os_open(zipStream, "archive.zip", MZ_OPEN_MODE_CREATE | MZ_OPEN_MODE_WRITE);
mz_zip_writer_create(&zipWriter);
mz_zip_writer_open(zipWriter, zipStream);
mz_zip_file info = {};
info.filename = "testfilename";
info.filename_size = 13;
info.compression_method = MZ_COMPRESS_METHOD_STORE;
mz_zip_writer_add_buffer(zipWriter, "filecontent", 12, &info);
mz_zip_writer_close(zipWriter);
mz_stream_os_close(zipStream);
I am getting the following verbose debug output:
Zip - Open
Zip - Entry - Write open - testfilename (level 9 raw 0)
Zip - Entry - Write - 12 (max 12)
Zip - Entry - Read Close
Zip - Entry - Crc failed (actual 0x52d869b7 expected 0x00000000)
I also tests precalculating the CRC and storing it in info.crc which didn't work as well.
The "Read Close" in the log made me a bit suspicious.
When changing the following function in mz_zip_rw.c from
int32_t mz_zip_writer_open(void *handle, void *stream)
{
return mz_zip_writer_open_int(handle, stream, 0);
}
to
int32_t mz_zip_writer_open(void *handle, void *stream)
{
return mz_zip_writer_open_int(handle, stream, MZ_OPEN_MODE_WRITE);
}
then I get the following output:
Zip - Open
Zip - Entry - Write open - testfilename (level 9 raw 0)
Zip - Entry - Write - 12 (max 12)
Zip - Entry - Write Close (crc 0x52d869b7 cs -1 ucs -1 )
Zip - Entry - Write cd (ucs 12 cs 12 crc 0x52d869b7)
Zip - Close
Zip - Write cd (disk 0 entries 1 offset 82 size 58)
and the archive is created successfully.
Do I use the wrong version/way/flavour of the API? Why is the mz_zip_writer_open() function opening the archive in mode == 0? Is this simply a bug?
Do you have a recommendation which API calls I could replace to make it work?
My intention is to create a ZIP file on disk and stream in-memory files into the archive, possibly several GB large.
With the following minimum working example
I am getting the following verbose debug output:
I also tests precalculating the CRC and storing it in
info.crcwhich didn't work as well.The "Read Close" in the log made me a bit suspicious.
When changing the following function in mz_zip_rw.c from
to
then I get the following output:
and the archive is created successfully.
Do I use the wrong version/way/flavour of the API? Why is the mz_zip_writer_open() function opening the archive in
mode == 0? Is this simply a bug?Do you have a recommendation which API calls I could replace to make it work?