Last active
April 13, 2023 05:45
-
-
Save steshaw/f090e76dab4c60bd7e91272ac20e0a68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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