How to use the pako/lib/zlib/deflate.deflateInit2 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 emailjs / emailjs-imap-client / src / compression.js View on Github external
function deflater (emit) {
  const stream = new ZStream()
  let status = deflateInit2(stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, WINDOW_BITS, 8, Z_DEFAULT_STRATEGY)
  if (status !== Z_OK) {
    throw new Error('Problem initializing deflate stream: ' + messages[status])
  }

  return function (data) {
    if (data === undefined) return emit()

    // Attach the input data
    stream.input = data
    stream.next_in = 0
    stream.avail_in = stream.input.length

    let status
    let output
    let start
    let ret = true
github Peergos / Peergos / ui / doppio / natives / java_util.js View on Github external
java_util_zip_Deflater['init(IIZ)J'] = function (thread, level, strategy, nowrap) {
        var DEF_MEM_LEVEL = 8;
        var Z_DEFLATED = 8;
        var strm = new ZStreamCons();
        var ret = deflate.deflateInit2(strm, level, Z_DEFLATED, nowrap ? -MAX_WBITS : MAX_WBITS, DEF_MEM_LEVEL, strategy);
        if (ret != 0) {
            var msg = strm.msg ? strm.msg : ret == -2 ? 'inflateInit2 returned Z_STREAM_ERROR' : 'unknown error initializing zlib library';
            thread.throwNewException('Ljava/lang/InternalError;', msg);
        } else {
            var num = OpenZStream(strm);
            return Long.fromNumber(num);
        }
    };
    java_util_zip_Deflater['setDictionary(J[BII)V'] = function (thread, arg0, arg1, arg2, arg3) {
github Peergos / Peergos / ui / doppio / natives / java_util.js View on Github external
var thisBuf = javaThis['java/util/zip/Deflater/buf'];
        var thisOff = javaThis['java/util/zip/Deflater/off'];
        var thisLen = javaThis['java/util/zip/Deflater/len'];
        var inBuf = thisBuf.array;
        var outBuf = b.array;
        strm.input = i82u8(inBuf, 0, inBuf.length);
        strm.next_in = thisOff;
        strm.avail_in = thisLen;
        strm.output = i82u8(outBuf, 0, outBuf.length);
        strm.next_out = off;
        strm.avail_out = len;
        if (javaThis['java/util/zip/Deflater/setParams']) {
            var level = javaThis['java/util/zip/Deflater/level'];
            var strategy = javaThis['java/util/zip/Deflater/level'];
            var newStream = new ZStreamCons();
            var res = deflate.deflateInit2(newStream, level, strm.state.method, strm.state.windowBits, strm.state.memLevel, strategy);
            ZStreams[addr.toNumber()] = newStream;
            switch (res) {
            case 0:
                javaThis['java/util/zip/Deflater/setParams'] = 0;
                thisOff += thisLen - strm.avail_in;
                javaThis['java/util/zip/Deflater/off'] = thisOff;
                javaThis['java/util/zip/Deflater/len'] = strm.avail_in;
                return len - strm.avail_out;
            case -5:
                javaThis['java/util/zip/Deflater/setParams'] = 0;
                return 0;
            default:
                thread.throwNewException('Ljava/lang/InternalError;', strm.msg);
            }
        } else {
            var finish = javaThis['java/util/zip/Deflater/finish'];