Library contents

Python ZipInfo.file_size

Read the uncompressed byte length recorded for an archive member.

A simple example

ZipInfo.file_size

  1. Start with Member containing ASCII AB
  2. Do this Read its uncompressed size
  3. Result 2 bytes
This size describes the original data, including both letters.

Syntax

Python syntax
info.file_size
Run these examples in Python

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

python3 lesson.py

Check the original receipt size

An office is preparing receipts for transfer and needs to budget storage. Identify which size the program measures, especially when a receipt is also stored inside a compressed archive.

Result4
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(info.file_size)
Output
4

The four ASCII characters in paid occupy four bytes.

Advertisements

Inspect a choir archive

A teacher saves the bytes for the word alto in an uncompressed archive member. Read the stored byte count for the member. The archive uses the store method, which leaves the member data uncompressed.

Givenparts/alto.txt · 4 bytes
Worked result4

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. Read the stored byte count for the member. The archive uses the store method, which leaves the member data uncompressed.

Givenstudio/tag.txt · 5 bytes
Worked result5

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.file_size