How to use the pako.gzip function in pako

To help you get started, we’ve selected a few pako examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github superfly / fly / packages / core / src / cmd / deploy.ts View on Github external
finish() {
                  log.debug("Finished packing.")
                  const buf = readFileSync(pathResolve(cwd, ".fly/bundle.tar"))
                  console.log(`Bundle size: ${buf.byteLength / (1024 * 1024)}MB`)
                  const gz = pako.gzip(buf)
                  console.log(`Bundle compressed size: ${gz.byteLength / (1024 * 1024)}MB`)
                  const bundleHash = createHash("sha1") // we need to verify the upload is :+1:
                  bundleHash.update(buf)

                  API.post(`/api/v1/apps/${appName}/releases`, gz, {
                    params: {
                      sha1: bundleHash.digest("hex"),
                      env
                    },
                    headers: {
                      "Content-Type": "application/x-tar",
                      "Content-Length": gz.byteLength,
                      "Content-Encoding": "gzip"
                    },
                    maxContentLength: 100 * 1024 * 1024,
                    timeout: 120 * 1000
github Cirrus-Link / Sparkplug / client_libraries / javascript / sparkplug-client / index.js View on Github external
// See if any options have been set
        if (options !== undefined && options !== null) {
                logger.info("test: " + options.algorithm);
            // Check algorithm
            if (options['algorithm']) {
                logger.info("test");
                algorithm = options['algorithm'];
            }
        }

        if (algorithm === null || algorithm.toUpperCase() === "DEFLATE") {
            logger.debug("Compressing with DEFLATE!");
            resultPayload.body = pako.deflate(payload);
        } else if (algorithm.toUpperCase() === "GZIP") {
            logger.debug("Compressing with GZIP");
            resultPayload.body = pako.gzip(payload);
        } else {
            throw new Error("Unknown or unsupported algorithm " + algorithm);
        }

        // Create and add the algorithm metric if is has been specified in the options
        if (algorithm !== null) {
            resultPayload.metrics = [ {
                "name" : "algorithm", 
                "value" : algorithm.toUpperCase(), 
                "type" : "string"
            } ];
        }

        return resultPayload;
    },
github FabricLabs / fabric / src / rageshake / submit-rageshake.js View on Github external
body.append('user_agent', userAgent);

    if (client) {
        body.append('user_id', client.credentials.userId);
        body.append('device_id', client.deviceId);
    }

    if (opts.sendLogs) {
        progressCallback(_t("Collecting logs"));
        const logs = await rageshake.getLogsForReport();
        for (const entry of logs) {
            // encode as UTF-8
            const buf = new TextEncoder().encode(entry.lines);

            // compress
            const compressed = pako.gzip(buf);

            body.append('compressed-log', new Blob([compressed]), entry.id);
        }
    }

    progressCallback(_t("Uploading report"));
    await _submitReport(bugReportEndpoint, body, progressCallback);
}
github eclipse / tahu / client_libraries / javascript / sparkplug-client / index.js View on Github external
logger.debug("Compressing payload " + JSON.stringify(options));

        // See if any options have been set
        if (options !== undefined && options !== null) {
            // Check algorithm
            if (options['algorithm']) {
                algorithm = options['algorithm'];
            }
        }

        if (algorithm === null || algorithm.toUpperCase() === "DEFLATE") {
            logger.debug("Compressing with DEFLATE!");
            resultPayload.body = pako.deflate(payload);
        } else if (algorithm.toUpperCase() === "GZIP") {
            logger.debug("Compressing with GZIP");
            resultPayload.body = pako.gzip(payload);
        } else {
            throw new Error("Unknown or unsupported algorithm " + algorithm);
        }

        // Create and add the algorithm metric if is has been specified in the options
        if (algorithm !== null) {
            resultPayload.metrics = [ {
                "name" : "algorithm", 
                "value" : algorithm.toUpperCase(), 
                "type" : "string"
            } ];
        }

        return resultPayload;
    },
github Leko / type-puzzle / packages / playground / src / lib / share.ts View on Github external
async encode(config: Config): Promise {
    const configStr = JSON.stringify(config);
    const gziped: Uint8Array = gzip(configStr);
    const base64String = btoa(String.fromCharCode(...gziped));

    return encodeURIComponent(base64String);
  }
}
github dvingo / artdrop / app / state / utils.js View on Github external
var uploadImgToS3 = (file, filename, imgType) => {
  var body = file
  if (imgType === 'image/svg+xml') {
    body = pako.gzip(file)
  }
  return new Promise((resolve, reject) => {
    credsRef.once('value', snapshot => {
      var creds = snapshot.val()
      AWS.config.credentials = {
        accessKeyId: creds.s3AccessKey,
        secretAccessKey: creds.s3SecretKey}
      var params = {
        Bucket: s3BucketName,
        Key: filename,
        ACL: 'public-read',
        CacheControl: 'max-age: 45792000',
        ContentType: imgType,
        Body: body}

      if (imgType === 'image/svg+xml') {
github MixinNetwork / desktop-app / src / blaze / blaze.js View on Github external
_sendGzip(data, result) {
    this.transactions[data.id] = result
    this.ws.send(pako.gzip(JSON.stringify(data)))
  }
  closeBlaze() {
github thomaschampagne / elevate / plugin / core / scripts / utils / gzip.ts View on Github external
public static toBase64(object: T): string {
		return btoa(gzip(JSON.stringify(object), {to: "string"}));
	}
github voorhoede / plek / packages / cli / src / fly.js View on Github external
const upload = ({ appName, stage }) => {
  const bundle = fs.readFileSync(
    path.resolve(process.cwd(), '.fly/bundle.tar')
  );
  const gzippedBundle = pako.gzip(bundle);
  const bundleHash = createHash('sha1').update(bundle);

  return flyAxios.post(`/api/v1/apps/${appName}/releases`, gzippedBundle, {
    params: {
      sha1: bundleHash.digest('hex'),
      env: stage,
    },
    headers: {
      'Content-Type': 'application/x-tar',
      'Content-Length': gzippedBundle.byteLength,
      'Content-Encoding': 'gzip',
    },
    maxContentLength: 100 * 1024 * 1024,
    timeout: 120 * 1000,
  });
};