Skip to content

Instantly share code, notes, and snippets.

@narenaryan
Created March 8, 2020 21:44
Show Gist options
  • Select an option

  • Save narenaryan/5b8a872669168496c93a81c09eda67a8 to your computer and use it in GitHub Desktop.

Select an option

Save narenaryan/5b8a872669168496c93a81c09eda67a8 to your computer and use it in GitHub Desktop.
from zipfile import ZipFile, ZipInfo
from io import BytesIO
def delete(path):
"""
Param: path -> file in archive
Returns a new zip file after deleting path
"""
new_zip = BytesIO()
with ZipFile('config.zip', 'r') as old_archive:
with ZipFile(new_zip, 'w') as new_archive:
for item in old_archive.filelist:
if item.filename != path:
# Copy everything other than path to be inserted
new_archive.writestr(item, old_archive.read(item.filename))
return new_zip
new_zip = delete('docker/docker-compose.yaml')
# Flush new zip to disk
with open('config.zip', 'wb') as f:
f.write(new_zip.getbuffer())
new_zip.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment