JavaScript:从Websocket中,我收到消息,作为Zlib Deflate:如何阅读或“ Unflate”或“放气” (不夸大)

发布于 2025-02-08 08:33:18 字数 1566 浏览 6 评论 0原文

这个问题是关于从WebSocket转换GZIP放气消息,并将其转换为可以应用JSON.PARSE的数组或原始文本...

***也很清楚:在此问题中:我使用来自一个加密交易所....但是,问题是关于收到的消息而不是关于Crypto Exchange的

消息,他们说“请使用Zlib Deflate”

此处的JavaScript

digifinexopen = '{"id":12312,"method":"trades.subscribe","params":["btc_usdt"]}';
digifinex_market_ws = new WebSocket("wss://openapi.digifinex.com/ws/v1/"); 
digifinex_market_ws.binaryType = "arraybuffer";
digifinex_market_ws.onmessage = event => digifinex_trades(event.data);
digifinex_market_ws.onopen = event => digifinex_market_ws.send(digifinexopen);

function fu_bitmex_trades (jsonx) { console.log(jsonx); }

我在

object=>[[Int8Array]]: Int8Array(1129) 0 … 99]
0: 120
1: -38

< script; script; script; “ https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.4/pako.min.js” ... 如果我做pako.deflate(jsonx);

object=> Uint8Array(78) [120, 156, 1, 67, 0, 188, 255, 120, 218, 4, 192, 177, 13, 196, 32, 12, 133, 225, 93, 254, 154, 6, 174, 243, 54, 39, 66, 17, 201, 74, 36, 63, 187, 66, 236, 158, 111, 179, 34, 222, 192, 158, 114, 111, 196, 82, 121, 98, 27, 229, 63, 75, 24, 170, 57, 151, 196, 105, 220, 23, 214, 199, 175, 143, 243, 5, 0, 0, 255, 255, 32, 108, 18, 108, 62, 68, 31, 

如果我添加解码器= new TextDecoder(“ utf8”); and log(dododer.decode(jsonx));我得到我得到

string=> x�E��xڜ��n\7����'5���*
���$pƋ Ȼ�*�֋�g��#����|�����������������v\�//�_������������

, 我得到了我可以json.parse的原始数据????

This question is about converting a gzip deflate message from a websocket message and convert it to array OR raw text that I can apply JSON.parse on it...

*** to be also clear: In this question : i use a websocket from a crypto exchange.... but the question is about the received message NOT about crypto exchange

in the documentation they say "please use zlib deflate"

HERE THE JAVASCRIPT

digifinexopen = '{"id":12312,"method":"trades.subscribe","params":["btc_usdt"]}';
digifinex_market_ws = new WebSocket("wss://openapi.digifinex.com/ws/v1/"); 
digifinex_market_ws.binaryType = "arraybuffer";
digifinex_market_ws.onmessage = event => digifinex_trades(event.data);
digifinex_market_ws.onopen = event => digifinex_market_ws.send(digifinexopen);

function fu_bitmex_trades (jsonx) { console.log(jsonx); }

I have this in the log

object=>[[Int8Array]]: Int8Array(1129) 0 … 99]
0: 120
1: -38

I tried with <script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.4/pako.min.js" ...></script>
if I do pako.deflate(jsonx);
I get

object=> Uint8Array(78) [120, 156, 1, 67, 0, 188, 255, 120, 218, 4, 192, 177, 13, 196, 32, 12, 133, 225, 93, 254, 154, 6, 174, 243, 54, 39, 66, 17, 201, 74, 36, 63, 187, 66, 236, 158, 111, 179, 34, 222, 192, 158, 114, 111, 196, 82, 121, 98, 27, 229, 63, 75, 24, 170, 57, 151, 196, 105, 220, 23, 214, 199, 175, 143, 243, 5, 0, 0, 255, 255, 32, 108, 18, 108, 62, 68, 31, 

If I add decoder = new TextDecoder("utf8"); and log(decoder.decode(jsonx)); I get

string=> x�E��xڜ��n\7����'5���*
���$pƋ Ȼ�*�֋�g��#����|�����������������v\�//�_������������

but, HOW TO RETREIVE the array or raw data that I could json.parse ????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘和柠 2025-02-15 08:33:18

如果我两次解压缩您的数据,我会得到:

{"error":null,"result":{"status":"success"},"id":12312}

看起来您被压缩而不是解压缩。使用pako.inflate()

If I decompress your data twice, I get:

{"error":null,"result":{"status":"success"},"id":12312}

It looks like you compressed instead of decompressed. Use pako.inflate().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文