I have a piece of a code which creates a zip file successfully, but I need to split this file if the size of it is more that 1MB.
I have this code but it doesn't work:
from split_file_reader.split_file_writer import SplitFileWriter
import zipfile
# make element tree
tree = etree.ElementTree(batch_element)
# make xml file and write it in stream
xml_object = BytesIO()
tree.write(xml_object, pretty_print=True, xml_declaration=False, encoding="utf-8")
xml_file = xml_object.getvalue()
final = BytesIO()
with SplitFileWriter(final, 1_000_000) as sfw:
with zipfile.ZipFile(sfw, "a") as zip_file:
zip_file.writestr('Batch.xml', xml_file)
I want to retrieve the split file as bytes. The zipping part is working, but the splitting doesn't.