How to use the pako/lib/deflate.js.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 fontello / ttf2woff / index.js View on Github external
var len, woffDataChains = [];

  for (i = 0; i < entries.length; ++i) {
    tableEntry = entries[i];

    var sfntData = new ByteBuffer(buf.buffer, tableEntry.Offset, tableEntry.Length);

    if (tableEntry.Tag.toString() === 'head') {
      version.maj = sfntData.getUint16(SFNT_ENTRY_OFFSET.VERSION_MAJ);
      version.min = sfntData.getUint16(SFNT_ENTRY_OFFSET.VERSION_MIN);
      flavor = sfntData.getUint32(SFNT_ENTRY_OFFSET.FLAVOR);
      sfntData.setUint32 (SFNT_ENTRY_OFFSET.CHECKSUM_ADJUSTMENT, checksumAdjustment);
    }

    var res = deflate(sfntData.toArray());

    var compLength;

    // We should use compression only if it really save space (standard requirement).
    // Also, data should be aligned to long (with zeros?).
    compLength = Math.min(res.length, sfntData.length);
    len = longAlign(compLength);

    var woffData = new ByteBuffer(len);

    woffData.fill(0);

    if (res.length >= sfntData.length) {
      woffData.writeBytes(sfntData.toArray());
    } else {
      woffData.writeBytes(res);
github fontello / ttf2woff / index.js View on Github external
function woffAppendMetadata(src, metadata) {

  var zdata =  deflate(metadata);

  src.setUint32(WOFF_OFFSET.SIZE, src.length + zdata.length);
  src.setUint32(WOFF_OFFSET.META_OFFSET, src.length);
  src.setUint32(WOFF_OFFSET.META_LENGTH, zdata.length);
  src.setUint32(WOFF_OFFSET.META_ORIG_LENGTH, metadata.length);

  //concatenate src and zdata
  var buf = new ByteBuffer(src.length + zdata.length);

  buf.writeBytes(src.toArray());
  buf.writeBytes(zdata);

  return buf;
}