@decorator<EOL>def gzip(f, *args, **kwargs):
data = f(*args, **kwargs)<EOL>if isinstance(data, Response):<EOL><INDENT>content = data.data<EOL><DEDENT>else:<EOL><INDENT>content = data<EOL><DEDENT>gzip_buffer = BytesIO()<EOL>gzip_file = gzip2.GzipFile(<EOL>mode='<STR_LIT:wb>',<EOL>compresslevel=<NUM_LIT:4>,<EOL>fileobj=gzip_buffer<EOL>)<EOL>gzip_file.write(content)<EOL>gzip_file.close()<EOL>gzip_data = gzip_buffer.getvalue()<EOL>if isinstance(data, Response):<EOL><INDENT>data.data = gzip_data<EOL>data.headers['<STR_LIT>'] = '<STR_LIT>'<EOL>data.headers['<STR_LIT>'] = str(len(data.data))<EOL>return data<EOL><DEDENT>return gzip_data<EOL>
GZip Flask Response Decorator.