Library contents

Python ZipInfo.compress_type

Compare the member compression identifier with the standard stored-method constant.

A simple example

ZipInfo.compress_type

  1. Start with A member added with no compression
  2. Do this Read the method
  3. Result Stored
Stored means the archive member was recorded without applying a compression algorithm.

Syntax

Python syntax
info.compress_type == ZIP_STORED
Run these examples in Python

Save one example at a time as lesson.py. Use Python 3.9 or later.

python3 lesson.py

Identify how a receipt was stored

An archive inventory records how each receipt was stored in addition to its filename. Inspect the entry metadata to distinguish the storage method from the original receipt contents.

Resultstored
lesson.py
from io import BytesIO
from zipfile import ZipFile, ZIP_STORED

store = BytesIO()
with ZipFile(store, "w", compression=ZIP_STORED) as archive:
    archive.writestr("tea.txt", "paid")

store.seek(0)
with ZipFile(store) as archive:
    info = archive.getinfo("tea.txt")
    print("stored" if info.compress_type == ZIP_STORED else "compressed")
Output
stored

ZIP_STORED stores the original bytes without compression.

Advertisements

Inspect a choir archive

A teacher saves the bytes for the word alto in an uncompressed archive member. Inspect the compression method recorded for the member. Which method name should the catalog display?

Givenparts/alto.txt · 4 bytes
Worked resultstore

The archive contains one stored member. Its entry metadata and contents can be inspected independently.

Inspect a workshop archive

A tutor saves the bytes for glaze in a second uncompressed archive member. Inspect the compression method recorded for the member. Which method name should the catalog display?

Givenstudio/tag.txt · 5 bytes
Worked resultstore

The archive contains one stored member. Its entry metadata and contents can be inspected independently.

What to watch for

For an archive supplied by someone else, check expected member names and size limits before reading large payloads.

Documentation for ZipInfo.compress_type