我正在寻找一种压缩基于 ascii 的字符串的方法,有什么帮助吗?
我也需要解压。我试过 zlib 但没有帮助。
我该怎么做才能将字符串压缩成更小的长度?
代码:
def compress(request):
if request.POST:
data = request.POST.get('input')
if is_ascii(data):
result = zlib.compress(data)
return render_to_response('index.html', {'result': result, 'input':data}, context_instance = RequestContext(request))
else:
result = "Error, the string is not ascii-based"
return render_to_response('index.html', {'result':result}, context_instance = RequestContext(request))
else:
return render_to_response('index.html', {}, context_instance = RequestContext(request))