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 files.
In [201]: import StringIO
In [202]: import boto
In [203]: conn = boto.connect_s3()
In [204]: my_bucket = conn.get_bucket('my_bucket')
In [205]: my_list = [ele for ele in my_bucket.list('my_file.zip')]
In [206]: f = StringIO.StringIO()
In [207]: my_list[0].get_file(f)
In [208]: f.seek(0)
If the file was not zipped I would just use:
my_content = my_list[0].get_contents_as_string()
but since it is zipped, I am getting garbage.
An answer to this question does what I want (I borrowed a bit of my attempt from it) using gzip
, but I can't find anything using for zip
. I tried using zipfileZipFile
, but read
, extract
and extractall
methods don't seem to do what I want.