UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

42 lines (31 loc) 882 B
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); function _zlib() { const data = _interopRequireDefault(require("zlib")); _zlib = function () { return data; }; return data; } function _toBase() { const data = _interopRequireDefault(require("./string/to-base64")); _toBase = function () { return data; }; return data; } module.exports = function packCmd(obj, base64 = true, compress = true) { if (compress) { if (obj.payload) { obj.payload = _zlib().default.deflateSync(JSON.stringify(obj.payload)); } if (obj.headers && obj.headers.context) { obj.headers.context = _zlib().default.deflateSync(JSON.stringify(obj.headers.context)); } } if (base64) { const res = (0, _toBase().default)(JSON.stringify(obj)); return res; } return JSON.stringify(obj); };