Skip to main content

A package to find metadata about zip files.

Project description

ZipInfo Utility

ZipInfo is a Python utility for analyzing and parsing ZIP file structures, specifically the End of Central Directory (EOCD) and Central Directory Record (CDR) sections. This tool helps to locate and extract information about files within ZIP archives by identifying critical offsets, directory structures, and file metadata.

Table of Contents


Installation

Since this utility does not require any external libraries beyond Python's standard library, you can simply include ZipInfo in your project.

Usage

The ZipInfo class provides methods for:

  • Calculating offsets in a ZIP file.
  • Identifying the location of the Central Directory in a ZIP file.
  • Parsing and extracting metadata for each file in the Central Directory.

Methods

ZipInfo.get_offset(offset: int) -> int

  • Description: Computes the offset within a file, normalized to megabytes.
  • Parameters:
    • offset (int): The offset in bytes.
  • Returns: An integer representing the normalized offset.

ZipInfo.find_central_directory(data: bytes) -> tuple

  • Description: Searches for the End of Central Directory (EOCD) in the provided data.
  • Parameters:
    • data (bytes): The byte sequence of the ZIP file.
  • Returns: A tuple containing:
    • central_dir_offset: Offset of the Central Directory in the ZIP file.
    • central_dir_size: Size of the Central Directory.
    • total_entries: Number of entries in the Central Directory.

ZipInfo.parse_eocd(eocd_data: bytes) -> tuple

  • Description: Parses the EOCD data to retrieve important directory metadata.
  • Parameters:
    • eocd_data (bytes): The EOCD record data.
  • Returns: A tuple with details including:
    • central_dir_offset: Offset of the Central Directory.
    • central_dir_size: Size of the Central Directory.
    • total_entries: Number of entries in the Central Directory.

ZipInfo.parse_central_directory(data: bytes, data_offset: int, total_records: int) -> list

  • Description: Parses the Central Directory and extracts metadata for each file entry.
  • Parameters:
    • data (bytes): The byte sequence of the ZIP file.
    • data_offset (int): Offset where the Central Directory begins.
    • total_records (int): Total number of file records in the Central Directory.
  • Returns: A list of dictionaries, each containing:
    • filename: Name of the file.
    • start_byte: Start byte offset of the file's local header.
    • end_byte: End byte offset of the file's data.

Logging

The ZipInfo class includes logging via Python’s logging library to provide insights into various stages of parsing. Enable DEBUG level logging to see detailed information, such as finding the EOCD and CDR signatures and handling unexpected records.

Example setup:

import logging

logging.basicConfig(level=logging.DEBUG)

Example

from zip import ZipInfo  # Import the ZipInfo class

# Load your ZIP file data as bytes
with open("example.zip", "rb") as f:
    data = f.read()

# Locate the Central Directory
central_dir_offset, central_dir_size, total_entries = ZipInfo.find_central_directory(data)

if central_dir_offset is not None:
    # Parse the Central Directory for file information
    file_info = ZipInfo.parse_central_directory(data, central_dir_offset, total_entries)
    print(file_info)  # List of dictionaries with file metadata
else:
    print("Central Directory not found.")

License

This project is licensed under the MIT License. See the LICENSE file for details.


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

zipinfo-0.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

zipinfo-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file zipinfo-0.0.1.tar.gz.

File metadata

  • Download URL: zipinfo-0.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for zipinfo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 361584b3776c26fc44675f482238b1fc8350504518d22d2c475c94b5befb9f4a
MD5 601bb1c9efb068ab8298fc2f8fe1f36a
BLAKE2b-256 791a7063580bba67bc9226a994b5d415b9b1eaa636ed106deca278a58a8dce84

See more details on using hashes here.

Provenance

The following attestation bundles were made for zipinfo-0.0.1.tar.gz:

Publisher: pypi-publish.yml on r0uted/zipinfo

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

File details

Details for the file zipinfo-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: zipinfo-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for zipinfo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f8a4e336f76149d30abc063af463311e0b686da4905ffdde207792a0dfe3f6b0
MD5 75369ef1ee6079e25d6085b86dc0762f
BLAKE2b-256 1a5c3cad80cd325988949a2ee963d595add7f9153d4eceadf37e3b77fe5030d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for zipinfo-0.0.1-py3-none-any.whl:

Publisher: pypi-publish.yml on r0uted/zipinfo

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