INNER CODE UNIT · Python
add
pgbouncer/pgbouncer · win32/make-zip.py:79
def add(zf, prefix, path, name=None, text=False):
"""Store path in the archive as prefix/name, converting text to CRLF."""
info = zipfile.ZipInfo.from_file(path, f"{prefix}/{name or os.path.basename(path)}")
info.compress_type = zipfile.ZIP_DEFLATED
# Bit 0 of the internal attributes marks an entry as text.
info.internal_attr = 1 if text else 0
with open(path, "rb") as f:
data = f.read()
if text:
data = EOL_RE.sub(b"\r\n", data)
zf.writestr(info, data)
if __name__ == "__main__":
main()