News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Github-kuba miniz for Pelles C

Started by John Z, November 25, 2025, 12:01:37 PM

Previous topic - Next topic

TimoVJL

May the source be with you

John Z

Thanks Timo,

I appreciate, very much, all of your help!

John Z

Vortex

Source code reviewed to remove some unnecessary struct statements :

#include <stdlib.h>
#pragma comment(lib, "zip.lib")
#define ZIP_DEFAULT_COMPRESSION_LEVEL 6
typedef struct zip_t zip_t;
extern zip_t __stdcall *zip_open(const char *zipname, int level, char mode);
extern int __stdcall zip_entry_open(zip_t *zip, const char *entryname);
extern int __stdcall zip_entry_fwrite(zip_t *zip, const char *filename);
extern int __stdcall zip_entry_close(zip_t *zip);
extern int __stdcall zip_close(zip_t *zip);

int __cdecl main(void)
{
    zip_t *zip = zip_open("test.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
    {
        zip_entry_open(zip, "sample.docx");
        {
            zip_entry_fwrite(zip, "sample.docx");
        }
        zip_entry_close(zip);
    }
    zip_close(zip);
    return 0;
}
Code it... That's all...

TimoVJL

Why not do bit more
int __cdecl main(void)
{
    zip_t *zip = zip_open("test.zip", ZIP_DEFAULT_COMPRESSION_LEVEL, 'w');
    if (zip) {
        zip_entry_open(zip, "sample.docx");
        zip_entry_fwrite(zip, "sample.docx");
        zip_entry_close(zip);
        zip_close(zip);
    }
    return 0;
}
May the source be with you

Vortex

QuoteOptional features
The library supports three compile-time flags to strip unused functionality and reduce binary size. All features are enabled by default -- if you just drop the source files into your project and compile, everything works as before.

https://github.com/kuba--/zip
Code it... That's all...

TimoVJL

#20
A miniz main problem is, that it is one file and not easy to split modules for static library.

msvc have a -Gy option for that.


This tool can help with modified source code:
split source file using tags
Just have an another tool to add tags a new version of code.
May the source be with you

Vortex

Adding this line to the top of zip.c and rebuilding the static library :

#define ZIP_ENABLE_INFLATE 0
The size of my test executable dropped from 138K to 134K.
Code it... That's all...

TimoVJL

#22
Test projects without library for testing defines.
First project with static crt and second with pocrt.dll, so actual code size seen.
May the source be with you

John Z

#23
Well newer versions of miniz definitely work, but seems some incompatibility with some programs.

This newest version does not cleanly work with LibreOffice 25.8, or Excel 2010 (both will 'repair' the file and then are OK) but DOES work with LibreOffice 7, without repair (as Timo pointed out above, and I've verified as well). Yet a quite a bit older version of miniz works for both newer LibreOffice, older LibreOffice, and Excel several generations, no repair, no errors.

Newer miniz zipped file open ok with miniz definitely, and with Windows Zip and 7z as far as I can tell.

It is a conundrum! 

The one thing I see in a Hex display/comparison is that the newer version of miniz appears to be appending to the filenames 01000000 maybe some sort of padding?  When using Windows built in ZIP or using 7z, or using the older version of miniz these bytes are not there.  The resulting spreadsheet from these three methods all open OK no repair needed.

So this is just a caution in using miniz created zip files in other applications, some may not be compatible. Sadly I'll just have to stick with the older miniz version for now.

John Z

Pelle

Have you ever looked at this?
https://zlib.net/

My main interest is in the compression/decompression part, which has worked well for me since the 1990s, but I think there is some attempt somewhere in this package to handle ZIP files...

I'm not sure this will solve anything, but if you are stuck ...
/Pelle

John Z

Thanks, I'll give it a look.

John Z

Vortex

Using zlib does not look easy. Anyone who tried the latest version?
Code it... That's all...

John Z

Looks like there is a possible path using ZLib which might make it easier.
ZLib has a miniz like version minizip

So I might be able to implement, or at least try -

Two links:
Base -
https://www.winimage.com/zLibDll/minizip.html

This seems A good helper set of functions, similar to miniz -
https://nachtimwald.com/2019/09/08/making-minizip-easier-to-use

John Z

Vortex

Extracting the contents of a zip file with COM \ Component Object Modeling is possible. Later, I can post an example.
Code it... That's all...

John Z

Yes, I read COM could do zipping and unzipping but not quite simple. 

My particular requirement at this time is to be able to create and add files to a zip file, but I'm sure your example will be useful to other interested people.  Good code examples help everyone 👍

John Z