Python: Creating a streaming gzip'd file-like? -


I try to figure out the best way to insert a stream with Python's zlib I am here.

I have file-like input stream ( input , below) and output function which accepts file-like ( output_function , below) Is:

and I with gzip-compress input

and open as input ("file") :

  Before sending: output_function (gzip_stream (input))  with input ("file") as input ()  > 

It seems that the module assumes that either input or output is a gzip'd file- Not-be disc ... So am I module I want.

However, it does not provide a simple way to basically create a stream file like ... and it supports stream-compression manually in the way of adding data to a compression buffer Now it is flushing that buffer.

Of course, I could write a cover around zlib.Compress.compress and zlib.Compress.flush ( narrow it zlib.compressobj () ), but I must be worried about having a buffer size incorrect, or something similar.

So, what's the easiest way to create streaming, jesus-compressing files-with Python?

Edit : In order to make it clear, both input stream and compressed output stream are too big to fit in both memory, so output_function (StringIO (zlib.compress (Input.

This is quite a cool (self-reference, etc.); just put a few minutes to write it, Nothing is actually elegant), but if you are still interested in using gzip instead of zlib what do you want Yes.

Actually, GzipWrap is a (very limited) file-like object that is given a given iterative (e.g., a file-like object, a list of strings, a generator ...)

Of course, it produces binary, so there was no point in applying "readline".

You should cover it or use it To be able to extend the gizip import GzipFile class from GzipWrap (object)

  only one As Bjekt: # input is a file object which input Diaf __init __ (self, input file name = no) feeds himself. Input = input self.buffer = '' self.zipper = GzipFile (file name, mode = 'wb', fileobj = self) def (self, size = -1): if (size = lt; 0) or lane Auto buffer) & lt; Size: for self.input in: self.zipper.write (s) Size & gt; 0 more lane (auto buffer) & gt; = Size: self.zipper.flush () Break: self.zipper.close () If size & lt; 0: ret = self.buffer self.buffer = '' else: ret, self.buffer = self.buffer [: shape], self.buffer [size:] ret ret ret flush (self): pass def write (self, Data): self.buffer + = data off of DRF (self): self.input.close ()  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -