ZLib====--

Users Corner

--

This page contains contains suggestions and source code I've received from the users.
Not all of these are tested. Some worked for some of you but may not for others. Try at your own risk.

From Peter.Luxem@ping.be Sun Feb 18 17:48 WET 1996
I've added two functions for some progressbar, the follow after this message maybe you can do something with it. I didn't use your convention of source code, it works that was important for me.

/* get file length of uncompressed file */
long gz_length( file )
gzFile file;
{
    gz_stream *s = (gz_stream*)file;

    return _filelength( _fileno(s->file) );
}

/* get file length of compressed file */
long gz_length_comp( file )
gzFile file;
{
    gz_stream *s = (gz_stream*)file;

    long lPos=ftell(s->file);
    if ( !fseek( s->file, -4, SEEK_END ) )
    {
        char buffer[4];
        uLong x;
        fread( buffer, 1, 4, s->file);

        x = (uLong)buffer[0];

        x += ((uLong)buffer[1])<<8;
        x += ((uLong)buffer[2])<<16;
        x += ((uLong)buffer[3])<<24;

        fseek( s->file, lPos, SEEK_SET );

        return x;
    }
    else
    {
        return 0;
    }
}

From Luca Piergentili, pierge@rm.ats.it Tue, 03 Sep 1996 19:33:32
Extracted from main.cpp:

//
//      gzw v.1.0
//      
//      author: Luca Piergentili (pierge@rm.ats.it)
//      description: (un)compress Windows 16-bit command line utility
//      syntax: gzw [-sPassword] <-c|-d> <Filename>
//
//      This source code is placed into public domain as freeware. Feel free to add changes and
//      improvements.
//      If you modify this code, please send me an email so I can incorporate your improvements
//      and bugfixes.
//
//      Please don't change author name and date and respect the original copyright for the zLib
//      sources (copyright (C) 1995-1996 Jean-loup Gailly and Mark Adler) and for wSendmail.cpp
//      (May. 1 1996 - ver 1.1 by Jarle Aase).
//
//      I wrote this sample code to handle compressed data with zLib sources (copyright (C) 
//      1995-1996 Jean-loup Gailly and Mark Adler) into Windows 16-bit environment from command 
//      line, without window's graphical interface, because I don't like Pkzip's MS-DOS window 
//      over my Windows programs.
//      To carry out command line interface in Windows environment I have used as example the 
//      source code of wSendmail.cpp, written and placed into public domain by Jarle Aase.
//      Take a look at Aase's code to handle also .ini files.
//
//      Depending on GZW_HEADER_DEFINED, you can handle .gzw files instead original .gz.
//
//      If GZW_HEADER_DEFINED is *not* defined, in Win 16-bit environment:
//              to compress TEST.DAT:
//                      - rename TEST.DAT to TEST
//                      - go with: "gzw -c TEST"
//                      - you get TEST.gz and TEST.DAT will be removed
//              to uncompress TEST.gz
//                      - go with: "gzw -d TEST"
//                      - you get TEST (without original .DAT ext) and TEST.gz will be removed
//
//      If GZW_HEADER_DEFINED *is* defined, in Win 16-bit environment:
//              to compress TEST.DAT:
//                      - go with: "gzw -c TEST.DAT"
//                      - you get TEST.gzw
//              to uncompress TEST.gzw
//                      - go with: "gzw -d TEST.gzw"
//                      - you get TEST.DAT
//
//      The -s option allow very sample password checking. The psw is xor'ed with it self and
//      then saved in gzw header, for further checking. The xor process involve only command line 
//      password and not (un)compressed data. To do xor with data, insert memnxor() call on 
//      gz_(un)compress() loops.
//      Note: -s (password) parameter cannot handle spaces, even if the string is quoted "",
//      and maximum password length is GZW_HEADER_PSW_MAX.
//      The -s option is available only compiling with GZW_HEADER_DEFINED.
//
//      To define GZW_HEADER_DEFINED macro, add /DGZW_HEADER_DEFINED to your compile command
//      line, not in the source code.
//
//      The GZW10.ZIP must contain these files:
//
//      - readme.txt
//      - gzw.def (for VC++ 1.0)
//      - gzw.mak (for VC++ 1.0)
//      - main.cpp (this file)  
//      - gzwapi.h
//      - gzwapi.c
//      - gzwhdr.h
//      - modified version of zlib.h
//      - modified version of gzio.c
//
//      To compile this code you must have also a copy of zLib sources (zlib104.zip, 106Kb), 
//      available from the official page at:
//      http://quest.jpl.nasa.gov/zlib/
//      or from:
//      http://www.alessandria.alpcom.it/~iaco/zlib/
//
//      Luca Piergentili, 31/08/96
//      mailto: pierge@rm.ats.it
//