Unzip my_file.zip pulled from s3 using boto

前端 未结 1 1322
感情败类
感情败类 2021-01-24 05:49

I am trying to use boto to open a .zip file I have in s3. I am trying to work with the data directly, I want to avoid creating temporary f

相关标签:
1条回答
  • 2021-01-24 06:43

    You should look into the python module gzip :

    https://docs.python.org/2/library/gzip.html

    you should be able to stringIO with gzip. .

    from boto.s3.connection import S3Connection
    import gzip
    from StringIO import StringIO
    
    S3Conn = S3Connection() # assuming your .boto has been setup
    Bucket = S3Conn.get_bucket('my_bucket')
    my_list = [gzip.GzipFile(fileobj=(StringIO(ele.get_contents_as_string()))) for ele in Bucket.list()]
    #for readability I pulled this out
    for item in my_list:
        item.read()
    

    for readability the list comprehension should probably be broken up - but I followed your original posting to compare.

    Good luck!

    0 讨论(0)
提交回复
热议问题