Newzip.write produces no file compression

This is supposed to create a zip file of a text file.

But the size of the zip file is no smaller?

-rw-rw-r-- 1 andy andy 557500 Oct 9 05:11 todays_files.txt
-rw-rw-r-- 1 andy andy 557630 Oct 9 05:09 newzip.zip

#! /usr/bin/python3.6
# Compressing a file Zip file is no smaller in size?
#  chmod +rx (make script executable from anywhere)
import math 

import zipfile

newzip=zipfile.ZipFile('/home/andy/Python/newzip.zip','w')
# File to compress
newzip.write('todays_files.txt')
newzip.close()

Is it actually text in the text file? Text compresses quite well. Some
data do not compress. What does gzip achieve with it? Eg:

 gzip -v < todays_files.txt > /dev/null

Argh. Belay all that. The default compression is ZIP_STORED, meaning
no compression. See (the docs)[zipfile — Work with ZIP archives — Python 3.10.7 documentation].

Cheers,
Cameron Simpson cs@cskk.id.au

2 Likes

Interesting.

Zip_Stored seems kinda silly.

If it is not compressed, what would be the point of creating a zip file?

There are use cases where its the collect of data in a single file that is important and not the compression.

That makes sense.

Also, some files do not meaningfully compress (eg video, which is
already low entropy). It is faster to not btoher to try. I guess these
inherently fall into Barry’s use case collection. I’ve certainly got an
explicit zip-but-do-not-compress use case where I’m working right now.

Cheers,
Cameron Simpson cs@cskk.id.au

Yes, you are right that some files will not compress.