Here is the size of the file generated by zip
:
$ seq 10000 > 1.txt
$ zip 1 1.txt
adding: 1.txt (deflated 54%)
$ ls -og 1.zip
-rw-r--r-- 1 22762 Aug 29 10:04 1.zip
Here is an equivalent python script:
import zipfile
z = zipfile.ZipFile(sys.argv[1], 'w', zipfile.ZIP_DEFLATED)
fn = sys.argv[1]
z.writestr(zipfile.ZipInfo(fn), sys.stdin.read())
z.close()
The size of the zip file generated is the following:
$ seq 10000 | ./main.py 2.zip 2.txt
$ ls -go 2.zip
-rw-r--r-- 1 49002 Aug 29 10:15 2.zip
Does anybody know why the python version does not generate the zip file as small as the one generated by zip
?