Can you use zlib with K6 to to inflate and base64 decode a string

I need to inflate and base64 decode a value returned in a http response.
Is there anyway to do that in K6
Is it possible to use zlib similar to this?:

const zlib = require("zlib");
const inflated = zlib.inflateRawSync(Buffer.from(yourstring, 'base64')).toString('ascii');

Hi @MattK6,

k6 should automatically decompress bodies if the correct Content-encoding is supplied if that isn’t enough you will need to write an extension to do it for you.

There is b64decode to decode base64.

The code you have linked is some nodejs code and k6 is not based on nodejs or compatible with any of it’s internal libraries.

Hope this helps

Hi mstoykov,

It is not the whole body…it is a (SAML) token in the response. I have to extract the token. URL Decode it. Then inflate and base64 decode it.

I guess you can try one of those two libraries

  1. inflate
  2. zlib

But I have no idea how compatible with k6 they are :man_shrugging:

If you do try them, please write back and share your experience, and good luck :wink:

Apparently also pako has worked somewhat in the past with some issues, goja (the JS VM k6 uses) has come a long way since then so it’s possible even more stuff are working now :man_shrugging: