我有一段代码可以成功创建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)
我想以字节形式检索分割文件。 压缩部分工作正常,但分割不起作用。