1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 06:53:00 +00:00

skip buffer usage

This commit is contained in:
Jörn-Michael Miehe 2021-09-03 06:28:34 +02:00
parent 349e7970d5
commit 1294cc3a38

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3
import argparse
import io
import logging
import os
import sys
@ -156,19 +155,15 @@ def main() -> None:
# decide what to do with the decks
if args.stdout:
# create file-like buffer
with io.BytesIO() as buffer:
# create zip file in buffer
with zipfile.ZipFile(buffer, "w") as zip_file:
# print out a zip file
with open(sys.stdout.fileno(), "wb", closefd=False, buffering=0) as raw_stdout:
with zipfile.ZipFile(raw_stdout, "w", compression=zipfile.ZIP_DEFLATED) as zip_file:
# put the decks into that zip file
for deck in decks:
zip_file.writestr(deck.file_name, deck.get_json(args.language))
# write buffer to stdout
buffer.seek(0)
with open(sys.stdout.fileno(), "wb", closefd=False, buffering=0) as stdout:
stdout.write(buffer.read())
else:
# save the decks to disk
for deck in decks:
deck.save(args.language)