mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
util: put compression code next to each other
ctxmanager was injecting itself between the compression and decompression code. Let's restore some order.
This commit is contained in:
parent
2d4abff2d9
commit
f301293b9d
@ -2794,32 +2794,6 @@ def finddirs(path):
|
||||
yield path[:pos]
|
||||
pos = path.rfind('/', 0, pos)
|
||||
|
||||
# compression utility
|
||||
|
||||
class nocompress(object):
|
||||
def compress(self, x):
|
||||
return x
|
||||
def flush(self):
|
||||
return ""
|
||||
|
||||
compressors = {
|
||||
None: nocompress,
|
||||
# lambda to prevent early import
|
||||
'BZ': lambda: bz2.BZ2Compressor(),
|
||||
'GZ': lambda: zlib.compressobj(),
|
||||
}
|
||||
# also support the old form by courtesies
|
||||
compressors['UN'] = compressors[None]
|
||||
|
||||
def _makedecompressor(decompcls):
|
||||
def generator(f):
|
||||
d = decompcls()
|
||||
for chunk in filechunkiter(f):
|
||||
yield d.decompress(chunk)
|
||||
def func(fh):
|
||||
return chunkbuffer(generator(fh))
|
||||
return func
|
||||
|
||||
class ctxmanager(object):
|
||||
'''A context manager for use in 'with' blocks to allow multiple
|
||||
contexts to be entered at once. This is both safer and more
|
||||
@ -2880,6 +2854,32 @@ class ctxmanager(object):
|
||||
raise exc_val
|
||||
return received and suppressed
|
||||
|
||||
# compression utility
|
||||
|
||||
class nocompress(object):
|
||||
def compress(self, x):
|
||||
return x
|
||||
def flush(self):
|
||||
return ""
|
||||
|
||||
compressors = {
|
||||
None: nocompress,
|
||||
# lambda to prevent early import
|
||||
'BZ': lambda: bz2.BZ2Compressor(),
|
||||
'GZ': lambda: zlib.compressobj(),
|
||||
}
|
||||
# also support the old form by courtesies
|
||||
compressors['UN'] = compressors[None]
|
||||
|
||||
def _makedecompressor(decompcls):
|
||||
def generator(f):
|
||||
d = decompcls()
|
||||
for chunk in filechunkiter(f):
|
||||
yield d.decompress(chunk)
|
||||
def func(fh):
|
||||
return chunkbuffer(generator(fh))
|
||||
return func
|
||||
|
||||
def _bz2():
|
||||
d = bz2.BZ2Decompressor()
|
||||
# Bzip2 stream start with BZ, but we stripped it.
|
||||
|
Loading…
Reference in New Issue
Block a user