UNPKG

cargowise-eadapter

Version:
26 lines (25 loc) 793 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.compressMessage = void 0; const zlib = require("zlib"); /** * Before sending an message string through the eAdapter, it needs to be gzipped and base64 encoded. * * @param message the xml string you wish to compress. * @returns a promise resolving the compressed base64 string. */ async function compressMessage(message) { const input = Buffer.from(message, "utf8"); return new Promise((resolve, reject) => zlib.gzip(input, { level: 1, windowBits: 9, }, (err, result) => { if (err) { reject(err); return; } const output = result.toString("base64"); resolve(output); })); } exports.compressMessage = compressMessage;