Skip to content

Instantly share code, notes, and snippets.

@steshaw
Last active April 13, 2023 05:45
Show Gist options
  • Save steshaw/f090e76dab4c60bd7e91272ac20e0a68 to your computer and use it in GitHub Desktop.
Save steshaw/f090e76dab4c60bd7e91272ac20e0a68 to your computer and use it in GitHub Desktop.
import zipfile
import io
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, mode='w', compression=zipfile.ZIP_DEFLATED) as zipf:
zipf.writestr("file1.txt", "one")
zipf.writestr("file2.txt", "two")
zipf.writestr("file3.txt", "three")
zip_buffer.seek(0)
output_zip_file = "result.zip"
with open(output_zip_file, 'wb') as f:
f.write(zip_buffer.read())
print(f"Zip file '{output_zip_file}' created")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment