簡體   English   中英

如何使用雲function解壓雲存儲中的大文件?

[英]How do I use a cloud function to unzip a large file in cloud storage?

我有一個雲 function,當 zip 上傳到雲存儲並應該解壓縮它時會觸發它。 但是 function 用完 memory,大概是因為解壓縮的文件太大(~2.2 Gb)。 我想知道我有什么選擇來處理這個問題? 我讀到可以將 stream 大文件放入雲存儲,但我不知道如何從雲 function 或解壓縮時執行此操作。 任何幫助,將不勝感激。

這里是雲function到目前為止的代碼:

 storage_client = storage.Client()
 bucket = storage_client.get_bucket("bucket-name")

 destination_blob_filename = "large_file.zip"

 blob = bucket.blob(destination_blob_filename)
 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.blob(contentfilename)
                blob.upload_from_string(contentfile)

你的目標進程是有風險的:

  • 如果您沒有完全解壓縮 stream 文件,則無法驗證 zip 的校驗和
  • 如果您將 stream 數據導入 GCS,則無法保證文件完整性

因此,您有 2 次成功操作而無需校驗和驗證!

在擁有 Cloud Function 或 Cloud Run with more memory 之前,您可以使用Dataflow 模板解壓縮文件

暫無
暫無

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

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