簡體   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?

我使用這個 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)

如何將 zip 文件(解壓前)拆分為多個特定大小的 zip 文件並將其作為單個文件提取到雲存儲中?

您可以創建多部分 zip,但您既不能單獨解壓縮該部分,也不能在創建存檔后拆分它(您必須在存檔創建期間指定該部分)。

在您的上下文中,我不理解具有相同 zip 的多個部分的值,因為您必須獲得所有部分才能正確解壓縮文件並驗證 CRC。

如果您想要幾個可以單獨解壓縮的部分,則必須在壓縮之前拆分文件,分別壓縮每個部分,然后您將能夠使用有效的 CRC 單獨解壓縮。 但同樣,我沒有抓住目標,因為你想在最后合並所有部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM