How to use the pako.deflate 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 flowtsohg / mdx-m3-viewer / src / parsers / mpq / file.js View on Github external
encode() {
        if (this.buffer !== null && this.rawBuffer === null) {
            let sectorSize = this.archive.sectorSize,
                data = new Uint8Array(this.buffer),
                sectorCount = Math.ceil(data.byteLength / sectorSize),
                offsets = new Uint32Array(sectorCount + 1),
                offset = offsets.byteLength,
                chunks = [];

            // First offset is right after the offsets list.
            offsets[0] = offsets.byteLength;

            for (let i = 0; i < sectorCount; i++) {
                let sectorOffset = i * sectorSize,
                    uncompressed = data.subarray(sectorOffset, sectorOffset + sectorSize),
                    chunk = deflate(uncompressed),
                    compressedSectorSize = chunk.byteLength + 1;

                // If the sector is going to take more than the archive's sector size, don't compress it.
                if (compressedSectorSize > sectorSize) {
                    chunk = uncompressed;
                }

                offset += compressedSectorSize;

                offsets[i + 1] = offset;

                chunks[i] = chunk;
            }

            let compressedSize = offsets[offsets.length - 1],
                rawBuffer = new Uint8Array(new ArrayBuffer(compressedSize));
github OpenGeoscience / geojs / tutorials / common / tutorials.js View on Github external
$('.codeblock').each(function () {
        var block = $(this),
            defaultSrc = $('textarea', block).attr('defaultvalue'),
            key = 'src' + (block.attr('step') !== '1' ? block.attr('step') : '');

        var src = $('.CodeMirror', block).length ? $('.CodeMirror', block)[0].CodeMirror.getValue() : $('textarea', block).val().trim();
        if (src !== defaultSrc) {
          var comp = btoa(pako.deflate(src, {to: 'string', level: 9, raw: true}));
          /* instead of using regular base64, convert /, +, and = to ., -, and _
           * so that they don't need to be escaped on the url.  This reduces the
           * average length of the url by 6 percent. */
          comp = comp.replace(/\//g, '.').replace(/\+/g, '-').replace(/=/g, '_');
          newQuery[key] = comp;
        }
      });
      if (!inPop) {
github wanadev / holes-in / lib / extruder.js View on Github external
generateDebugLink(outerShape, holes, options){
        if(options.debug){
            try{
                const pako = require("pako");
                const data64 = pako.deflate(JSON.stringify({ holes, outerShape, doNotBuild: options.doNotBuild }));
                const urlParam = `data=${encodeURIComponent(data64)}`;
                console.info(`Holes in debug: https://wanadev.github.io/holes-in/debugPage.html?${urlParam}`);
            }catch(error) {
                console.warn("error on holes-in generate debug link. You may need to install pako", error)
            }
        }
    },
github samdenty / injectify / src / inject / Websockets.ts View on Github external
send(topic: string, data: any) {
    /**
     * Enhanced transport
     */
    const json = JSON.stringify(data)
    let transport = `${topic}${json ? ':' + json : ''}`
    if (
      global.config.compression &&
      !this.session.debug &&
      !/^core|auth$/.test(topic)
    ) {
      transport =
        '#' +
        pako.deflate(transport, {
          to: 'string'
        })
    }
    try {
      /**
       * Basic RAW transport
       */
      if (/^core|auth$/.test(topic)) {
        if (this.session.version === 0) {
          /**
           * Payload version 0
           */
          transport = JSON.stringify({
            d: data
          })
        } else {
github crimx / ext-saladict / src / _helpers / config-manager.ts View on Github external
function deflate (config: AppConfig): AppConfigCompressed {
  return {
    v: 1,
    d: pako.deflate(JSON.stringify(config), { to: 'string' })
  }
}
github isomorphic-git / isomorphic-git / for-future.js View on Github external
function wrapObject({ type, object /*: {type: string, object: Buffer} */ }) {
  let buffer$$1 = Buffer.concat([Buffer.from(type + ' '), Buffer.from(object.byteLength.toString()), Buffer.from([0]), Buffer.from(object)]);
  let oid = shasum(buffer$$1);
  return {
    oid,
    file: Buffer.from(pako.deflate(buffer$$1))
  };
}
github opf / openproject / frontend / src / app / modules / hal / services / hal-resource.service.ts View on Github external
protected toEprops(params:unknown):{ eprops:string } {
    const deflatedArray = Pako.deflate(JSON.stringify(params));
    const compressed = base64.bytesToBase64(deflatedArray)

    return { eprops: compressed };
  }
}
github K3D-tools / K3D-jupyter / js / src / core / lib / helpers / serialize.js View on Github external
function serializeArray(obj) {
    return {
        dtype: _.invert(typesToArray)[obj.data.constructor],
        compressed_buffer: pako.deflate(obj.data.buffer, {level: 9}),
        shape: obj.shape
    };
}
github Hopding / pdf-lib / src / core / pdf-structures / PDFContentStream.ts View on Github external
encode = () => {
    this.dictionary.set(PDFName.from('Filter'), PDFName.from('FlateDecode'));

    const buffer = new Uint8Array(this.operatorsBytesSize());
    this.copyOperatorBytesInto(buffer);
    this.encodedOperators = pako.deflate(buffer);

    this.dictionary.set(
      'Length',
      PDFNumber.fromNumber(this.encodedOperators.length),
    );

    return this;
  };
github rocket-pool / rocketpool / scripts / helpers / api / upgrade / upgrade-contract.js View on Github external
function compressAbi(abi) {
    return Buffer.from(pako.deflate(JSON.stringify(abi))).toString('base64');
}