SVG: strip timestamp to make compressed gzip reproducible

we tell GzipFile to write the MTIME field to zero so that the compressed output is reproducible and doesn't change depending on when the data is compressed.
This commit is contained in:
Cosimo Lupo 2022-06-09 16:29:29 +01:00
parent 8673073a87
commit 119b7732cc
2 changed files with 4 additions and 2 deletions

View File

@ -110,7 +110,9 @@ class table_S_V_G_(DefaultTable.DefaultTable):
if (allCompressed or doc.compressed) and not docBytes.startswith(b"\x1f\x8b"):
import gzip
bytesIO = BytesIO()
with gzip.GzipFile(None, "w", fileobj=bytesIO) as gzipper:
# mtime=0 strips the useless timestamp and makes gzip output reproducible;
# equivalent to `gzip -n`
with gzip.GzipFile(None, "w", fileobj=bytesIO, mtime=0) as gzipper:
gzipper.write(docBytes)
gzipped = bytesIO.getvalue()
if len(gzipped) < len(docBytes):

View File

@ -16,7 +16,7 @@ def dump(table, ttFont=None):
def compress(data: bytes) -> bytes:
buf = io.BytesIO()
with gzip.GzipFile(None, "w", fileobj=buf) as gz:
with gzip.GzipFile(None, "w", fileobj=buf, mtime=0) as gz:
gz.write(data)
return buf.getvalue()