Have the layer PUT method calculate the uncompressed size in realtime, as trusting the JSON is fraught with complications
This commit is contained in:
parent
7fd3c7d31b
commit
474add0fb1
3 changed files with 48 additions and 5 deletions
25
util/gzipstream.py
Normal file
25
util/gzipstream.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""
|
||||
Defines utility methods for working with gzip streams.
|
||||
"""
|
||||
|
||||
import zlib
|
||||
|
||||
# Window size for decompressing GZIP streams.
|
||||
# This results in ZLIB automatically detecting the GZIP headers.
|
||||
# http://stackoverflow.com/questions/3122145/zlib-error-error-3-while-decompressing-incorrect-header-check/22310760#22310760
|
||||
ZLIB_GZIP_WINDOW = zlib.MAX_WBITS | 32
|
||||
|
||||
def calculate_size_handler():
|
||||
""" Returns an object and a SocketReader handler. The handler will gunzip the data it receives,
|
||||
adding the size found to the object.
|
||||
"""
|
||||
uncompressed_size_info = {
|
||||
'size': 0
|
||||
}
|
||||
|
||||
decompressor = zlib.decompressobj(ZLIB_GZIP_WINDOW)
|
||||
|
||||
def fn(buf):
|
||||
uncompressed_size_info['size'] += len(decompressor.decompress(buf))
|
||||
|
||||
return uncompressed_size_info, fn
|
Reference in a new issue