我有一段代码可以成功创建一个 zip 文件,但是如果它的大小超过 1MB,我需要拆分这个文件。
我有这段代码,但它不起作用:
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)
我想以字节形式检索拆分文件。压缩部分正在工作,但拆分没有。