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.2.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.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zipinfo-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f752f34516ec4196fe40dbcc06c402d991cd919c2d73cf333ff059e846760cb7
MD5 6a4868b1fbb7a460ecceb4db5844168c
BLAKE2b-256 b457c99785ff58a5a427bacea6ed4fc5b8a0178bac14ed8e28e3d010bc7c44eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for zipinfo-0.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: zipinfo-0.0.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 500882e5e84a13c46b7dcc9260dc6c809e089c488298126554ae80f95dab1185
MD5 5f7449769668d1c3e8ecec66993f2114
BLAKE2b-256 599f9aa47f9b32e8a2230e093f53143adb880e86ab549c2e6dcde3f91f86b85f

See more details on using hashes here.

Provenance

The following attestation bundles were made for zipinfo-0.0.2-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