How to open gzip file on gae cloud?

I am using python 2.7 and Google Compute Cloud. I want to process the gzip file loaded in the gcs datastore. In Python, it will be:

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

Since this is not allowed for GCS, the only option I found in the Google Cloud Storage Client Library Feature :

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

which does not open gzip files. Any tips on how I can do this?

0
source share
1 answer

You can use gzip.GzipFile () alternate access through the file object using the file object provided by the GCS client:

import cloudstorage
import gzip

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

Source: https://habr.com/ru/post/1695355/


All Articles