How to use the brotli.decompress function in brotli

To help you get started, we’ve selected a few brotli 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 DevExpress / testcafe-hammerhead / src / processing / encoding / index.ts View on Github external
export async function decodeContent (content: Buffer, encoding: string, charset: Charset) {
    if (encoding === GZIP_CONTENT_ENCODING) {
        // NOTE: https://github.com/request/request/pull/2492/files
        // Be more lenient with decoding compressed responses, since (very rarely)
        // servers send slightly invalid gzip responses that are still accepted
        // by common browsers.
        // Always using Z_SYNC_FLUSH is what cURL does.
        // GH-1915
        content = await gunzip(content, { flush: zlib.Z_SYNC_FLUSH, finishFlush: zlib.Z_SYNC_FLUSH });
    }

    else if (encoding === DEFLATE_CONTENT_ENCODING)
        content = await inflateWithFallback(content);

    else if (encoding === BROTLI_CONTENT_ENCODING)
        content = Buffer.from(require('brotli').decompress(content));

    charset.fromBOM(content);

    return charsetEncoder.decode(content, charset.get());
}
github bramstein / opentype / src / opentype.js View on Github external
transformVersion = 0;

        var transformLength = rb.read(Type.BASE128);
      }

      totalSize += origLength;

      index.push({
        flags: flag,
        tag: tag,
        origLength: origLength
      });
    }

    // TODO: Upgrade to Node v6.x so we can use Buffer.from.
    var data = new Buffer(brotli.decompress(buffer.slice(rb.byteOffset, rb.byteOffset + totalSize)));
    var offset = 0;

    index.forEach(function (table) {
      font.tables[table.tag] = data.slice(offset, offset + util.pad(table.origLength));
      offset += table.origLength;
    });
  } else if (signature === Format.TRUETYPE || signature === Format.OPENTYPE) {
    font.header = rb.read(sfnt.Header);
    var index = rb.readArray(sfnt.OffsetTable, font.header.numTables);

    index.forEach(function (table) {
      font.tables[table.tag] = buffer.slice(table.offset, table.offset + util.pad(table.length));
    });
  }

  for (var table in TABLES) {
github airtasker / proxay / src / persistence.ts View on Github external
export function serialiseBuffer(
  buffer: Buffer,
  headers: Headers
): PersistedBuffer {
  const header = headers["content-encoding"];
  const contentEncoding = typeof header === "string" ? header : undefined;
  const originalBuffer = buffer;
  let compression: CompressionAlgorithm = "none";
  if (contentEncoding === "br") {
    buffer = Buffer.from(brotli.decompress(buffer));
    compression = "br";
  }
  if (contentEncoding === "gzip") {
    buffer = gunzipSync(buffer);
    compression = "gzip";
  }
  const utf8Representation = buffer.toString("utf8");
  try {
    // Can it be safely stored and recreated in YAML?
    const recreatedBuffer = Buffer.from(
      yaml.safeLoad(yaml.safeDump(utf8Representation)),
      "utf8"
    );
    if (Buffer.compare(buffer, recreatedBuffer) === 0) {
      // Yes, we can store it in YAML.
      return {
github alibaba / anyproxy / lib / requestHandler.js View on Github external
});
            } else if (isServerDeflated && originContentLen) {
              refactContentEncoding();
              zlib.inflateRaw(serverResData, (err, buff) => {
                if (err) {
                  rejectParsing(err);
                } else {
                  fulfill(buff);
                }
              });
            } else if (isBrotlied && originContentLen) {
              refactContentEncoding();

              try {
                // an Unit8Array returned by decompression
                const result = brotliTorb.decompress(serverResData);
                fulfill(Buffer.from(result));
              } catch (e) {
                rejectParsing(e);
              }
            } else {
              fulfill(serverResData);
            }
          }
        }).then((serverResData) => {
          resolve({
github alibaba / anyproxy / lib / requestHandler / UserReqHandler.js View on Github external
});
            } else if (isServerDeflated && originContentLen) {
              refactContentEncoding();
              zlib.inflateRaw(serverResData, (err, buff) => { // TODO test case to cover
                if (err) {
                  rejectParsing(err);
                } else {
                  fulfill(buff);
                }
              });
            } else if (isBrotlied && originContentLen) {
              refactContentEncoding();

              try {
                // an Unit8Array returned by decompression
                const result = brotliTorb.decompress(serverResData);
                fulfill(Buffer.from(result));
              } catch (e) {
                rejectParsing(e);
              }
            } else {
              fulfill(serverResData);
            }
          }
        }).then((serverResData) => {
          resolve({
github ironSource / parquetjs / lib / compression.js View on Github external
function inflate_brotli(value) {
  return new Buffer(brotli.decompress(value));
}

brotli

A port of the Brotli compression algorithm as used in WOFF2

MIT
Latest version published 3 years ago

Package Health Score

67 / 100
Full package analysis