jquery解压压缩流zlib
我正在使用 Flask 应用程序将一些 html 标记数据流式传输到客户端浏览器。我想压缩并发送数据流。我可以在服务器端使用压缩(zlib 压缩),但不幸的是,我没有找到在客户端解压缩它的方法(使用 jquery)。由于这个问题,我在浏览器中看到垃圾显示,如下所示。
eJw=��[�۶���+���At�����(�m6�EѶl]hR�^~��l�Z^K3)�"��OÙ�ef(�s˲R�\�~8�--�?�i��ݪB���us��3%�lj]��ӿ�n���/?}nׂ�_>������[���W�?u�?�P��g�fJ|�Y%N�>���Ӊ�� �Y����y�m?���>?^�M�TZ�����o�Y^�/��=��) y���u
X!�e
下面的原始数据(如:html_result_file 所示)应如下所示:
<table id="table_id" class="striped hoverable responsive-table centered">
<thead><tr><th>Cluster</th><th>vserver</th><th>share-name</th></tr></thead>
<tr><td>ct-cis-cldd-x01</td><td>av-cisdd01-ct01</td><td>admin$</td></tr>
<tr><td>ct-cis-cldd-x01</td><td>av-cisdd01-ct01</td><td>c$</td></tr>`enter code here`
<tr><td>ct-cis-cldd-x01</td><td>av-cisdd01-ct01</td><td>ipc$</td></tr>
</table>
我的 Flask 应用程序代码如下:
import zlib
compressor = zlib.compressobj()
def generate():
with open (html_result_file,'r') as fr:
for line in fr:
yield compressor.compress(line.encode())
yield compressor.flush()
response = Response(generate(), mimetype='application/zlib')
return response
我接收此响应的 jquery 代码如下...
<div class="row">
<div class="col s12" id="tabdata">
</div>
</div>
<script>
$.ajax({
type: $('#testform').attr('method'),
url: $('#testform').attr('action'),
data: $('#testform').serialize(),
success: function (response) {
console.log(response)
$('#tabdata').html(response)
</script>
这里,console.log 语句显示从应用。
如果有人能建议一种方法来正确解压缩此响应以在浏览器上显示,那就太好了。
我的主要目标是在发送流时在这里实现压缩,我很高兴以任何其他方式实现它。
I am using a flask application to stream some html markup data to client browser. I want to compress and send the data stream. I could use the compression at the server end (zlib compression) but unfortunately, I am not finding a way to decompress it at the client end (using jquery). Because of this issue, I am getting garbage display in the browser as below.
eJw=��[�۶���+���At�����(�m6�EѶl]hR�^~��l�Z^K3)�"��OÙ�ef(�s˲R�\�~8�--�?�i��ݪB���us��3%�lj]��ӿ�n���/?}nׂ�_>������[���W�?u�?�P��g�fJ|�Y%N�>���Ӊ�� �Y����y�m?���>?^�M�TZ�����o�Y^�/��=��) y���u
X!�e
The original data (as depicted in : html_result_file) below should be as follows :
<table id="table_id" class="striped hoverable responsive-table centered">
<thead><tr><th>Cluster</th><th>vserver</th><th>share-name</th></tr></thead>
<tr><td>ct-cis-cldd-x01</td><td>av-cisdd01-ct01</td><td>adminlt;/td></tr>
<tr><td>ct-cis-cldd-x01</td><td>av-cisdd01-ct01</td><td>clt;/td></tr>`enter code here`
<tr><td>ct-cis-cldd-x01</td><td>av-cisdd01-ct01</td><td>ipclt;/td></tr>
</table>
My flask application code is as below :
import zlib
compressor = zlib.compressobj()
def generate():
with open (html_result_file,'r') as fr:
for line in fr:
yield compressor.compress(line.encode())
yield compressor.flush()
response = Response(generate(), mimetype='application/zlib')
return response
My jquery code receiving this response is as below...
<div class="row">
<div class="col s12" id="tabdata">
</div>
</div>
<script>
$.ajax({
type: $('#testform').attr('method'),
url: $('#testform').attr('action'),
data: $('#testform').serialize(),
success: function (response) {
console.log(response)
$('#tabdata').html(response)
</script>
Here, the console.log statement displays the garbage values received from the application.
It would be great if some one could suggest a way to decompress this response correctly for displaying on the browser.
My main aim is to achieve compression here while sending the stream and I am happy to achieve it any alternate ways..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论