如何将一个zip文件拆分为多个特定大小的zip文件,并将其解压缩为云存储中的单个文件?

2024-05-06 20:12:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用这个函数将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)

如何将一个zip文件(解压前)拆分为多个特定大小的zip文件,并将其解压缩为云存储中的单个文件


Tags: 文件pathselfclientgetbucketwithstorage
1条回答
网友
1楼 · 发布于 2024-05-06 20:12:52

您可以创建多部件压缩包,但既不能单独解压缩部件,也不能在创建存档后拆分部件(必须在创建存档期间指定部件)

在您的上下文中,我不理解相同zip的多个部分的值,因为您必须获得所有部分才能正确解压缩文件并验证CRC

如果你想要几个部分,你可以分别解压,你必须在压缩之前分割你的文件,分别压缩每个部分,然后你就可以用有效的CRC分别解压。但是,我没有抓住目标,因为您希望在最后合并所有部分

相关问题 更多 >