Tuesday, 15 May 2012

python - Unzip my_file.zip pulled from s3 using boto -


I use a .zip file to open boto I'm trying to do s3 I'm trying to work directly with the data, I want to avoid making temporary files. [203]: In imported beato [203]: conn = boto.connect_s3 () in [204]: my_bucket = conn.get_bucket ('my_bucket') in [205]: my_list = [my_bucket.list ('my_file.zip' For ele) in [206]: f = StringIO.StringIO () in [207]: my_list [0] .get_file (f) if [208]: f.seek (0)

If the file was not zipped then I would use it:

  my_content = my_list [0]  

But because it is zipped, That's why I'm getting garbage.

Gzip by using whatever I want (I try it a bit), but nothing for me zip I've tried to use the zipfileZipFile , but read , extract and extractall methods what I want to do I do not think I should see Python module in gizip:

You should be able with gciip in stringIO .boto.s3.connection StringIO S3Conn = S3Connection () # From your S3Connection Import gzip StringIO import, assuming your .boto has been set up Bucket = S3Conn.get_bucket ('my_bucket') my_list = [Gzip.GzipFile (fileobj = (StringIO (ele.get_contents_as_string) ())) Bucket.list in ele) ()] # For reading ability, I pulled it in my_list for the item: item.read ()

Understand the list for readability It should probably be broken - but to follow the comparison I followed your original posting.

Good luck!


No comments:

Post a Comment