skip to Main Content

Im using API gateway from AWS.
Data comein is the binary format from somebody’s post request. And we know it is created by :https://learn.microsoft.com/en-us/dotnet/api/system.io.compression.gzipstream?view=netframework-4.6

body: `x1F�bx00x00x00x00x00x04x00��]o�0x14���oG��x0Fx02��t�&�x1B"x19�6��I��7'����x10�}vn` +`x1F�bx00x00x00x00x00x04x00��]o�0x14���oG��x0Fx02��t�&�x1B"x19�6��I��7'����x10�}vn` 
    ....,
  isBase64Encoded: false
...
'Content-Type': 'application/gzip',

My current attempt

const B = new Uint8Array(Buffer.from(body, 'binary'));
// or const B = Buffer.from(body, 'binary'); not work

zlib.unzip(B, (err, buffer) => {
  if (!err) {
    console.log(buffer.toString());
  } else {
    console.log(err);
  }
});

And getting some err:

Error: incorrect header check
    at Zlib.zlibOnError [as onerror] (node:zlib:189:17) {
  errno: -3,
  code: 'Z_DATA_ERROR'
}

Expected

Unzip this data and parse to json with zlib from nodejs.

2

Answers


  1. Chosen as BEST ANSWER

    Problem solved :

    Reference this article, in setting of API gateway, enable this enter image description here

    https://techblog.commercetools.com/gzip-on-aws-lambda-and-api-gateway-5170bb02b543


  2. Try zlib.gunzip instead. Your data is a gzip stream, not a zlib stream.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search