node.jszlibinflate

How can I inflate and decode XML in Node.js?


When I try to inflate and decode with zlib in node I get the error "Error: incorrect header check"

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')

Using https://www.samltool.com/decode.php I can successfully inflate and decode it so it is not a problem with the input. Am I doing something wrong with zlib, or is there a way to do it without zlib?


Solution

  • You can use the inflateRawSync function to inflate the Xml, the header check will then be skipped.

    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);