【发布时间】:2016-09-07 02:05:57
【问题描述】:
当我从 Storage Platform Web UI 下载存储在 Google Cloud Storage 存储桶中的 GZIP 文件时,一切正常,我可以毫无问题地解压缩文件。
但是,当我使用 googleapiclient 和 Python 下载文件时,我无法解压缩它。 7-Zip 表示文件已损坏。 我的代码:
import io
from apiclient.http import MediaIoBaseDownload
from googleapiclient import http
bucket='bqtoredshiftdaily'
out_file=os.path.join(current_dir,process_name,"Upload",gcsfile.replace("/", "_"))
with open(out_file, 'w') as f:
req = gcs_service.objects().get_media(bucket=bucket, object=gcsfile)
downloader = http.MediaIoBaseDownload(f, req)
done = False
while done is False:
status, done = downloader.next_chunk()
print("Download {}%.".format(int(status.progress() * 100)))
下载成功,但正如我所说,我无法解压缩下载的 GZIP 文件。 知道为什么吗?
【问题讨论】:
标签: python gzip google-cloud-storage