Created
          January 21, 2014 07:07 
        
      - 
      
 - 
        
Save you21979/8535609 to your computer and use it in GitHub Desktop.  
    python2.6でgzipのbuffer扱えないのでしょうがないからこんな感じでつかうらしい
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from gzip import GzipFile | |
| from StringIO import StringIO | |
| class GZOStream: | |
| def __init__(self): | |
| self.sio = StringIO() | |
| self.gzf = GzipFile(fileobj=self.sio, mode='wb') | |
| def write(self,data): | |
| self.gzf.write(data) | |
| def finish(self): | |
| self.gzf.close() | |
| buf = self.sio.getvalue() | |
| self.sio.close() | |
| return buf | |
| class GZIStream: | |
| def __init__(self, buff): | |
| self.sio = StringIO(buff) | |
| self.gzf = GzipFile(fileobj=self.sio, mode='rb') | |
| def read(self): | |
| return self.gzf.read() | |
| def close(self): | |
| self.gzf.close() | |
| self.sio.close() | |
| go = GZOStream() | |
| go.write("aiiiiaaa") | |
| gi = GZIStream(go.finish()) | |
| print gi.read() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
python3ならこんな苦労はない