zlib Documentation

repository·develop·Indexed 27 days ago

https://github.com/madler/zlib

A general-purpose data compression library implementing deflate, zlib, and gzip formats. This documentation covers the core library and various contributions, including language bindings for Ada, Delphi, Pascal, and .NET (DotZLib), C++ stream interfaces (iostream3), the low-memory puff() implementation for deflate decompression, and hardware-accelerated CRC32 for IBM Z (crc32vx). It also provides build instructions for GNAT, Visual Studio via CMake, and NAnt.

Tokens
4.6K
Snippets
10
Records
38
Agent score
92%

What's inside zlib

  1. Overview of DotZLib .NET wrapper

    develop

    DotZLib is a .NET wrapper class library for ZLib1.dll. It provides functionality for:

    • Inflating and deflating memory buffers.
    • .NET streaming wrappers for the gz streams part of zlib.
    • Wrappers for the checksum components of zlib.

    For implementation examples, refer to DotZLib/UnitTests.cs.

  2. Build ZLib.Ada using Aonix ObjectAda for Win32 7.2.2

    develop

    To build ZLib.Ada on Aonix ObjectAda for Win32 7.2.2, follow these steps:

    1. Create a project containing all *.ads and *.adb files from the distribution.
    2. Build the libz.a library from the original ZLib C sources.
    3. Rename libz.a to z.lib.
    4. Add z.lib to your ObjectAda project.
    5. Add the libc.lib library from the ObjectAda distribution to the project.
    6. Build the executable using test.adb as the main procedure.
  3. Create a Visual Studio project using CMake

    develop

    Pre-made Visual Studio projects are no longer provided. Instead, use cmake-gui to generate a Visual Studio solution on demand.

    Follow these steps:

    1. Launch cmake-gui.
    2. Set source-dir to the zlib source directory.
    3. Set build-dir to your desired build directory.
    4. Click Configure. Select your Visual Studio version and platform details.
    5. Review the available options and descriptions that appear after the configuration run.
    6. Select the desired options.
    7. Click Configure again to ensure all dependencies are located. If any dependencies are missing (e.g., bzip2 for minizip), either install the dependency or deactivate the corresponding option. Repeat until no errors (red text) remain.
    8. Click Generate.
    9. Click Open Project to launch Visual Studio.

    Once Visual Studio is open, use Build > Build solution to compile the library.

    1. Start cmake-gui.
    2. Point source-dir to the source.
    3. Point build-dir to the dir where you want to build.
    4. Hit configure -- there you can select details.
    5. Select the options you want, which are shown with descriptions after the
       configure run is complete.
    6. Hit configure again to assure that everything that is needed is found.
    7. For those not found, deactivate the option or install the dependency, e.g.
       bzip2 for minizip, and go back to step 6 until there is no red.
    8. Hit generate.
    9. Hit open project.
  4. Use the Pascal (Delphi, Kylix) interface for zlib

    develop

    The zlibpas.pas unit provides a Pascal interface to the zlib data compression library for Delphi and Kylix environments.

    Key Integration Details:

    • Naming Conflict: Do not confuse zlibpas with Borland's built-in ZLib unit. Borland's unit is a suite of class wrappers that lacks essential features like checksums. Use zlibpas for full zlib functionality.
    • Type Mapping: C types are translated to Pascal types of similar sizes (e.g., Integer, LongInt) to avoid namespace pollution. Note that unsigned integers are not explicitly converted to Pascal unsigned integers.
    • Calling Convention: The interface uses cdecl. This means it is compatible with modern Delphi/Kylix but will not work with old Turbo Pascal.
    • Limitations: The gz* function interfaces are not translated to avoid C runtime library interfacing issues. Specifically, gzprintf cannot be used via this Pascal interface.
  5. Use the updated Delphi ZLib interface unit

    develop

    This directory provides an updated Delphi interface unit for ZLib, replacing the original Borland supplemental component based on zlib 1.0.4. This update is recommended to resolve bugs and security issues present in the older version.

    Key improvements in this version include:

    • Compatibility with zlib 1.2.1.
    • TZStreamRec field types updated to Longint for 64-bit readiness and consistency with zlib.h.
    • Updated zlib_version constant.
    • Support for the Z_RLE strategy symbolic constant.
    • Allocation and deallocation functions (TAlloc, TFree, zlibAllocMem, and zlibFreeMem) are now cdecl, allowing direct linking with original C zlib sources.
  6. Build ZLib.Ada using GNAT

    develop

    To build ZLib.Ada with GNAT, ensure the ZLib C library is already built on your system. Navigate to the ZLib.Ada source directory and use one of the following methods:

    Method 1: Direct command Use gnatmake with linker arguments pointing to the directory containing libz.a.

    Method 2: GNAT Project File For GNAT 3.15 or later, use the provided .gpr project file.

  7. Debug zlib applications on Windows

    develop

    To diagnose program misbehavior or application crashes using tools like WinDbg, you should include the Program Database (.pdb) files in your development environment:

    • For your own application: Ensure your build process generates or includes your application's .pdb files.
    • For zlib crashes: Install zlib1.pdb in the same directory as zlib1.dll to allow debuggers to inspect the library's internal state during a crash.
  8. Build ZLIB using CMake

    develop

    To build ZLIB, you need CMake version 3.12 or higher. In most cases, you can generate the build files using the following command:

    cmake -S . -B build -D CMAKE_BUILD_TYPE=Release

    You can customize the build by passing options via the command line using -D<option>=ON/OFF or via cmake-gui.

  9. Generate a Visual Studio project for zlib1.dll using cmake-gui

    develop

    Follow these steps to create a Visual Studio solution using cmake-gui:

    1. Start cmake-gui.
    2. Set source-dir to the project source directory.
    3. Set build-dir to your desired build directory.
    4. Click Configure. Select your generator and details.
    5. Review and select the desired options (descriptions are provided after the configuration run).
    6. Click Configure again to ensure all dependencies are located.
    7. If dependencies are missing (e.g., bzip2 for minizip), either deactivate the option or install the required dependency, then repeat step 6 until no errors remain.
    8. Click Generate.
    9. Click Open Project.
    10. In Visual Studio, select Build > Build solution.
  10. Build DotZLib using NAnt

    develop

    You can build the library using NAnt by running the nant command in the directory containing DotZLib.build.

    Use the following properties to control the build:

    • debug={true|false}: Toggles between debug and release builds (defaults to true).
    • nunit={true|false}: Includes or excludes unit tests (defaults to true).
    • clean: A target that removes previously built binaries.

    The output DotZLib.dll will be located in ./DotZLib/bin/release or ./DotZLib/bin/debug depending on your configuration.