google-cloud-platform - 如何解压 Google 云存储中的 .zip 文件?

标签 google-cloud-platform google-cloud-storage gzip unzip

如何解压缩 Google Cloud Storage Bucket 中的 .zip 文件? (如果我们有其他工具,例如适用于 AWS 的“CloudBerry Explorer”,那就太好了。)

最佳答案

您可以使用Python,例如来自云函数:

    from google.cloud import storage
    from zipfile import ZipFile
    from zipfile import is_zipfile
    import io

    def zipextract(bucketname, zipfilename_with_path):

        storage_client = storage.Client()
        bucket = storage_client.get_bucket(bucketname)

        destination_blob_pathname = zipfilename_with_path
        
        blob = bucket.blob(destination_blob_pathname)
        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(zipfilename_with_path + "/" + contentfilename)
                    blob.upload_from_string(contentfile)

    zipextract("mybucket", "path/file.zip") # if the file is gs://mybucket/path/file.zip

关于google-cloud-platform - 如何解压 Google 云存储中的 .zip 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49541026/

相关文章:

google-cloud-storage - 允许对现有文件使用 gzip

android - 在 Android 上使用 JetS3t 时抛出 IncompatibleClassChangeError 异常

php - 使用 PHP 以 tar.gz 格式动态压缩目录

objective-c - 如何为 Swift 安装 Objective C GZIP 库

python-3.x - 在 Python 中修改 gzip xml 文件(Adobe Premiere Pro 项目文件)的更快方法?

python - 如何在 Google Cloud 上部署 Python 3 Flask 项目

google-cloud-platform - 如何让 podman/buildah 容器在 GCE 上的 CentOS 下运行?

google-app-engine - 在Google App Engine中从Google Cloud Storage提供大文件

javascript - Firestore 查询具有类似数组的文档 (Node.js/Admin SDK)

google-cloud-platform - 错误: 4 DEADLINE_EXCEEDED: Deadline Exceeded at Object.exports.createStatusError - GCP