【问题标题】:How to open gzip file on gae cloud?如何在gae云上打开gzip文件?
【发布时间】:2016-06-13 00:48:25
【问题描述】:

我正在使用 python 2.7 和 Google Compute Cloud。我想处理上传到 gcs 数据存储区的 gzip 文件。在 Python 上,这将是:

import gzip
with gzip.open('myfile.gz', 'r') as f:
    f.read()

由于 GCS 不允许这样做,我在 Google Cloud Storage Client Library Functions 上找到的唯一选项是:

import cloudstorage
cloudstorage.open('myfile.gz', 'r'):
    f.read()

不打开 gzip 文件。关于如何做到这一点的任何提示?

【问题讨论】:

    标签: python google-app-engine gzip google-cloud-storage google-compute-engine


    【解决方案1】:

    您可以使用 GCS 客户端库提供的文件对象,通过文件对象使用备用 gzip.GzipFile() 访问:

    import cloudstorage
    import gzip
    
    with cloudstorage.open('myfile.gz', 'r') as f:
        content = gzip.GzipFile(fileobj=f).read()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-23
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      相关资源
      最近更新 更多