Skip to main content

Fast GZIP-to-ZIP/ZIP64 conversion without recompression

Project description

gz2zip

gz2zip converts GZIP to ZIP/ZIP64 without recompression by reusing the original Deflate payload.

This is much faster than decompressing and re-zipping, and it supports both:

  1. seekable file conversion (gzip_to_zip)
  2. streaming conversion (stream_gzip_to_zip) for pipes and async workloads

Installation

pip install gz2zip

Install as an isolated CLI tool with pipx:

pipx install gz2zip

or with uv:

uv tool install gz2zip

Run without installing globally:

pipx run gz2zip --help
uvx gz2zip --help

Supported Python versions

Based on the official Python version support table, this package targets:

  • Python 3.10
  • Python 3.11
  • Python 3.12
  • Python 3.13
  • Python 3.14

CLI Usage

The package installs the gz2zip command:

gz2zip INPUT_GZ [-o OUTPUT_ZIP] [-n NAME_IN_ZIP] [-s UNCOMPRESSED_SIZE] [-t ISO_TIMESTAMP] [-q]

Common examples

Convert a file and auto-derive output name (input.gz -> input.zip):

gz2zip input.gz

Set output path and internal filename:

gz2zip input.gz -o output.zip -n data.csv

Pipe from stdin to stdout:

cat input.gz | gz2zip - -n data.csv > output.zip

Large-file case (>4 GiB original content): provide exact uncompressed size:

gz2zip huge.sql.gz -o huge.zip -n huge.sql -s 5368709120

Run as a module:

python -m gz2zip input.gz -o output.zip

CLI options

Option Description
input Input .gz file. Use - (or omit) to read from stdin.
-o, --output Output ZIP file. Use - for stdout.
-n, --name Filename to store inside ZIP.
-s, --size Known uncompressed size (recommended for >4 GiB input).
-t, --timestamp Override timestamp in ISO 8601, e.g. 2025-12-31T23:59:58.
-q, --quiet Suppress non-error logs.

API Usage

Synchronous (seekable files)

from gz2zip import gzip_to_zip

with open("input.gz", "rb") as f_in, open("output.zip", "wb") as f_out:
    gzip_to_zip(f_in, f_out, filename_in_zip="data.csv")

Asynchronous streaming

import asyncio
from gz2zip import stream_gzip_to_zip

async def gzip_chunks():
    with open("input.gz", "rb") as f:
        while chunk := f.read(64 * 1024):
            yield chunk

async def main():
    with open("output.zip", "wb") as out:
        async for chunk in stream_gzip_to_zip(gzip_chunks(), "data.csv"):
            out.write(chunk)

asyncio.run(main())

ZIP64 note

GZIP stores ISIZE modulo 2^32, so files larger than 4 GiB need an explicit known_uncompressed_size (-s in CLI) if exact size metadata is required.

Limitation: concatenated GZIP members

Concatenated GZIP streams are valid (for example: cat a.gz b.gz > joined.gz), but this project currently does not support that multi-member format correctly. Use single-member .gz input files.

Development

Run tests:

uv run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gz2zip-0.1.0.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gz2zip-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file gz2zip-0.1.0.tar.gz.

File metadata

  • Download URL: gz2zip-0.1.0.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gz2zip-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ca9cb9607f8ff120c16023536b4377440677bb8c8a91eff593d29d89f8f295f
MD5 005374d397c92fc58eeb2550242e5f0a
BLAKE2b-256 6b1ef841012e11f49ec521e1480e9cf3b8aad439345e8be5fb8521a154461700

See more details on using hashes here.

Provenance

The following attestation bundles were made for gz2zip-0.1.0.tar.gz:

Publisher: ci.yaml on 45deg/gz2zip

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gz2zip-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gz2zip-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gz2zip-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0264d793422cd3b5e339144f09dcacd3a407c775fb1288bbae01a8c461c67b17
MD5 57e28b297e532c2dcdd2b240108e1872
BLAKE2b-256 d9b65bea333a60f58faad5caf25b34f9c7f03284bfdde306fa777c9ac36add64

See more details on using hashes here.

Provenance

The following attestation bundles were made for gz2zip-0.1.0-py3-none-any.whl:

Publisher: ci.yaml on 45deg/gz2zip

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page