The code that does the compression in javascript using pako(https://github.com/nodeca/pako)Pako. It compresses string 't'
var compressedString = pako.gzip('t', {level: 4, to: 'string'}));
$.ajax('/decompress', {string: compressedString})
The code at /decompress that does the decompression
from cgi import parse_qs, escape
import json
import zlib
def application(environ, start_response):
status = '200 OK'
try:
request_body_size = int(environ.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
request_body = environ['wsgi.input'].read(request_body_size)
d = parse_qs(request_body)
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
inputString = d.get('string')[0]
# Use same wbits(=31) as used by pako
decompressed = zlib.decompress(inputString, 31);
return 'done'
Doing the decompression throws following error. The error occurs for zlib.decompress line.
error: Error -3 while decompressing data: incorrect header check
I also tried encoding the inputString(
inputString.encode('utf-8')
) but it also throws the error.