当我尝试在节点中使用zlib进行充气和解码时,出现错误“错误:错误的标头检查”
const example = 'pZNBj9owEIX/Sm4+JcYQFrAIUgSqhLRtEWx72MvK6wys1cROPeNu+u/rBGg57O6lp0jj5/nevHGWqJq6lWWgF7uHnwGQkhIRPBln185iaMAfwP8yGr7t7wv2QtSi5BxBBw+ZVh4q12XaNTLPJ9z509PJu9ByMZmMeYidkPcMji3X534sKYm8eQ4EZ4KxpwtiayvoCjZlySY6MVb1Nv5BTRtxlrJGEYYfYpwF5OtY2rjucPjKEV2msO1Yst0U7Kla5CKfwiSdPefjNJ+rebq4Ox7TyUwvcq0Wo3keQVvEELlIylLBxiMxS0fTVIgHcSenuRyJR5Z8j1MMRsbZiCVdU1uU/VAFC95Kp9CgtKoBlKTlofx8L6NQqmuOt1faj++03pHTrmarZa+Wgzu/+p/UGyBVKVJLfttxeV78l+hgu9m52ujfSVnX7nXtQREUjHyIm/rkfAz7fc8iE0PFVOlxkMpgsQVtjgYqxq+Yy9OCanhocesEHSVr18SFGuyThU5puk59q1rXMcc9HFcfRq2l7nWxvIufV+erXUwSdEQ+eBUtOU+XAN5sfj57x+jf09vfZPUH'
const inflated = zlib.inflateSync(Buffer.from(example, 'base64')).toString('ascii')
使用https://www.samltool.com/decode.php,我可以成功地对其进行膨胀和解码,因此输入不是问题。我在zlib上做错了什么,还是没有zlib可以解决此问题?
最佳答案
您可以使用inflateRawSync函数为Xml充气,然后跳过标题检查。
const zlib = require("zlib");
const example = 'pZNBj9owEIX/Sm4+JcYQFrAIUgSqhLRtEWx72MvK6wys1cROPeNu+u/rBGg57O6lp0jj5/nevHGWqJq6lWWgF7uHnwGQkhIRPBln185iaMAfwP8yGr7t7wv2QtSi5BxBBw+ZVh4q12XaNTLPJ9z509PJu9ByMZmMeYidkPcMji3X534sKYm8eQ4EZ4KxpwtiayvoCjZlySY6MVb1Nv5BTRtxlrJGEYYfYpwF5OtY2rjucPjKEV2msO1Yst0U7Kla5CKfwiSdPefjNJ+rebq4Ox7TyUwvcq0Wo3keQVvEELlIylLBxiMxS0fTVIgHcSenuRyJR5Z8j1MMRsbZiCVdU1uU/VAFC95Kp9CgtKoBlKTlofx8L6NQqmuOt1faj++03pHTrmarZa+Wgzu/+p/UGyBVKVJLfttxeV78l+hgu9m52ujfSVnX7nXtQREUjHyIm/rkfAz7fc8iE0PFVOlxkMpgsQVtjgYqxq+Yy9OCanhocesEHSVr18SFGuyThU5puk59q1rXMcc9HFcfRq2l7nWxvIufV+erXUwSdEQ+eBUtOU+XAN5sfj57x+jf09vfZPUH'
const inflated = zlib.inflateRawSync(Buffer.from(example, 'base64')).toString('ascii');
console.log("Inflated:", inflated);
关于node.js - 如何在Node.js中膨胀和解码XML?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60500151/