简体   繁体   中英

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.

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?

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).

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.

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. But again, I don't catch the objective because you want to merge all the part at the end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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