简体   繁体   English

如何将 zip 文件拆分为多个特定大小的 zip 文件并将其提取为云存储中的单个文件?

[英]How can I split a zip file into multiple zip files of specific size and extract it as a single file in cloud storage?

I use this function to extract zip file into cloud storage bucket.我使用这个 function 将 zip 文件提取到云存储桶中。

def zipextract(self, zipfilename_with_path, subfile):
    """Unzip file into Cloud Storage."""
    bucket = self.storage_client.get_bucket(self.bucketname)
    bucket_dest = self.storage_client.get_bucket(self.project_id)

    blob = bucket.blob(zipfilename_with_path)
    if blob.exists():
        zipbytes = io.BytesIO(blob.download_as_string())

        if is_zipfile(zipbytes):
            with ZipFile(zipbytes, 'r') as myzip:
                for contentfilename in myzip.namelist():
                    contentfile = myzip.read(contentfilename)
                    blob = bucket_dest.blob(
                        subfile + "/" + contentfilename)
                    blob.upload_from_string(contentfile)

How can I split a zip file (before the decompression) into multiple zip files of specific size and extract it as a single file in cloud storage?如何将 zip 文件(解压前)拆分为多个特定大小的 zip 文件并将其作为单个文件提取到云存储中?

You can create a multi-part zip, but you can't neither uncompress the part separately nor split it after archive creation (you have to specify the part during the archive creation).您可以创建多部分 zip,但您既不能单独解压缩该部分,也不能在创建存档后拆分它(您必须在存档创建期间指定该部分)。

In your context, I don't understand the values to have multi-part of the same zip, because you have to get all the part to be able to uncompress correctly the file and validate the CRC.在您的上下文中,我不理解具有相同 zip 的多个部分的值,因为您必须获得所有部分才能正确解压缩文件并验证 CRC。

If you want several part, that you can uncompress separately, you have to split your file before the compression, compress each part separately, and then you will be able to uncompress separately with a valid CRC.如果您想要几个可以单独解压缩的部分,则必须在压缩之前拆分文件,分别压缩每个部分,然后您将能够使用有效的 CRC 单独解压缩。 But again, I don't catch the objective because you want to merge all the part at the end.但同样,我没有抓住目标,因为你想在最后合并所有部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM