我在 websocket 性能测试中使用了 K6。当来自服务器的内容被压缩时,我在控制台中打印了“�0E�e�!�56���j0&��v!�{�:�9�^�”。我使用 nodejs 代码来处理来自服务器的相同消息。我得到了正确的文字。
所以我的问题是如何在 K6 中解码压缩文本?
我的 K6 脚本是
socket.on('message', function (data) {
console.log(typeof (data));
console.log(data.length)
if (data.length < 200) {
// I got "�0E�e�!�56���j0&��v!�{�:�9�^�" in console
console.log(data);
}
// I tried to decode it got "incorrect header check"
let text = pako.inflate(data, { to: 'string' });
}
如果我使用以下 JS 脚本,我会得到正确的文本以将其扩展为纯文本。
ws.on('message', function (data) {
console.log('-------- begin -------');
// I got <Buffer 1f 8b 08 00 00 00 00 00 00 00 2d 8b 4b 0a 80 20 14 45 f7 72 c7 21 f9 1b e4 6e 34 1f 14 12 49 5e 47 d1 de 33 68 7a 3e 37 f6 8c 80 c4 b5 b7 4c 4c 68 3d in console
console.log(data);
console.log('-------- end -------');
let text = pako.inflate(data, {
to: 'string'
});
// msg is " msg: {"id":"btcusdt","subbed":"market.btcusdt.depth.step0","ts":1525243319443,"status":"ok"} "
console.log('msg: ' + text);
})