- Merge branch 'master' into sha-lom

- Extract out the tar handling from streamlayerformat into tarlayerformat
- Add a new tarfileappender class to make it easy to append data to gzipped tars
- Fix the gzipwrap to properly close
- Have the .git injection use the new appender
This commit is contained in:
Joseph Schorr 2014-10-15 15:51:34 -04:00
commit d43109d7cb
48 changed files with 1232 additions and 532 deletions

View file

@ -1,12 +1,19 @@
from gzip import GzipFile
# 256K buffer to Gzip
GZIP_BUFFER_SIZE = 1024 * 256
class GzipWrap(object):
def __init__(self, input, filename=None, compresslevel=1):
self.input = iter(input)
self.buffer = ''
self.zipper = GzipFile(filename, mode='wb', fileobj=self, compresslevel=compresslevel)
self.is_done = False
def read(self, size=-1):
if self.is_done:
return ''
# If the buffer already has enough bytes, then simply pop them off of
# the beginning and return them.
if len(self.buffer) >= size:
@ -21,7 +28,7 @@ class GzipWrap(object):
input_size = 0
input_buffer = ''
while input_size < 1024 * 256: # 256K buffer to Gzip
while input_size < GZIP_BUFFER_SIZE:
try:
s = self.input.next()
input_buffer += s
@ -34,6 +41,8 @@ class GzipWrap(object):
if is_done:
self.zipper.flush()
self.zipper.close()
self.is_done = True
if len(self.buffer) >= size or is_done:
ret = self.buffer[0:size]