Пример #1
0
static void
squash_brotli_stream_init (SquashBrotliStream* s,
                           SquashCodec* codec,
                           SquashStreamType stream_type,
                           SquashOptions* options,
                           SquashDestroyNotify destroy_notify) {
  SquashStream* stream = (SquashStream*) s;
  squash_stream_init (stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  s->finished = false;
  if (stream_type == SQUASH_STREAM_COMPRESS) {
    brotli::BrotliParams params;
    params.quality = squash_options_get_int_at (stream->options, stream->codec, SQUASH_BROTLI_OPT_LEVEL);
    params.mode = (brotli::BrotliParams::Mode) squash_options_get_int_at (stream->options, stream->codec, SQUASH_BROTLI_OPT_MODE);
    s->compressor = new brotli::BrotliCompressor (params);
    s->remaining_block_in = s->compressor->input_block_size();
    s->remaining_out = 0;
    s->next_out = NULL;
    s->should_flush = false;
    s->should_seal = false;
  } else if (stream_type == SQUASH_STREAM_DECOMPRESS) {
    s->decompressor = BrotliCreateState(squash_brotli_malloc, squash_brotli_free, squash_codec_get_context (codec));
  } else {
    squash_assert_unreachable();
  }
}
Пример #2
0
static void
squash_lz4f_stream_init (SquashLZ4FStream* stream,
                         SquashCodec* codec,
                         SquashStreamType stream_type,
                         SquashOptions* options,
                         SquashDestroyNotify destroy_notify) {
  squash_stream_init ((SquashStream*) stream, codec, stream_type, (SquashOptions*) options, destroy_notify);
}
Пример #3
0
static void
squash_ms_stream_init (SquashMSCompStream* stream,
                       SquashCodec* codec,
                       SquashStreamType stream_type,
                       SquashOptions* options,
                       SquashDestroyNotify destroy_notify) {
    squash_stream_init ((SquashStream*) stream, codec, stream_type, options, destroy_notify);
}
Пример #4
0
static void
squash_bz2_stream_init (SquashBZ2Stream* stream,
                        SquashCodec* codec,
                        SquashStreamType stream_type,
                        SquashBZ2Options* options,
                        SquashDestroyNotify destroy_notify) {
  squash_stream_init ((SquashStream*) stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  bz_stream tmp = { 0, };
  stream->stream = tmp;
}
Пример #5
0
static void
squash_bz2_stream_init (SquashBZ2Stream* stream,
                        SquashCodec* codec,
                        SquashStreamType stream_type,
                        SquashOptions* options,
                        SquashDestroyNotify destroy_notify) {
  squash_stream_init ((SquashStream*) stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  bz_stream tmp   = { 0, };
  tmp.bzalloc     = squash_bz2_malloc;
  tmp.bzfree      = squash_bz2_free;
  tmp.opaque      = squash_codec_get_context (codec);
  stream->stream  = tmp;
}
Пример #6
0
static void
squash_csc_stream_init (SquashCscStream* s,
                        SquashCodec* codec,
                        SquashStreamType stream_type,
                        SquashCscOptions* options,
                        SquashDestroyNotify destroy_notify) {
  SquashStream* stream = (SquashStream*) s;

  squash_stream_init (stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  if (stream->stream_type == SQUASH_STREAM_COMPRESS) {
    s->ctx.comp = NULL;
  } else {
    s->ctx.decomp = NULL;
  }
}
Пример #7
0
static void
squash_brotli_stream_init (SquashBrotliStream* s,
                           SquashCodec* codec,
                           SquashStreamType stream_type,
                           SquashOptions* options,
                           SquashDestroyNotify destroy_notify) {
  SquashStream* stream = (SquashStream*) s;

  s->in.cb_ = squash_brotli_reader;
  s->in.data_ = (void*) stream;
  s->out.cb_ = squash_brotli_writer;
  s->out.data_ = (void*) stream;
  s->operation = SQUASH_OPERATION_PROCESS;

  squash_stream_init (stream, codec, stream_type, (SquashOptions*) options, destroy_notify);
}
Пример #8
0
static void
squash_ms_stream_init (SquashMSCompStream* stream,
                       SquashCodec* codec,
                       SquashStreamType stream_type,
                       SquashOptions* options,
                       SquashDestroyNotify destroy_notify) {
  squash_stream_init ((SquashStream*) stream, codec, stream_type, options, destroy_notify);

  MSCompStatus status;
  MSCompFormat format = squash_ms_format_from_codec (codec);
  if (stream->base_object.stream_type == SQUASH_STREAM_COMPRESS) {
    status = ms_deflate_init (format, &(stream->mscomp));
  } else {
    status = ms_inflate_init (format, &(stream->mscomp));
  }
  assert (status == MSCOMP_OK);
}
Пример #9
0
static void
squash_brotli_stream_init (SquashBrotliStream* s,
                           SquashCodec* codec,
                           SquashStreamType stream_type,
                           SquashOptions* options,
                           SquashDestroyNotify destroy_notify) {
  SquashStream* stream = (SquashStream*) s;
  squash_stream_init (stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  if (stream_type == SQUASH_STREAM_COMPRESS) {
    s->ctx.encoder = BrotliEncoderCreateInstance(squash_brotli_malloc, squash_brotli_free, NULL);

    BrotliEncoderSetParameter(s->ctx.encoder, BROTLI_PARAM_QUALITY, squash_options_get_int_at (options, codec, SQUASH_BROTLI_OPT_LEVEL));
    BrotliEncoderSetParameter(s->ctx.encoder, BROTLI_PARAM_LGWIN, squash_options_get_int_at (options, codec, SQUASH_BROTLI_OPT_WINDOW_SIZE));
    BrotliEncoderSetParameter(s->ctx.encoder, BROTLI_PARAM_LGBLOCK, squash_options_get_int_at (options, codec, SQUASH_BROTLI_OPT_BLOCK_SIZE));
    BrotliEncoderSetParameter(s->ctx.encoder, BROTLI_PARAM_MODE, squash_options_get_int_at (options, codec, SQUASH_BROTLI_OPT_MODE));
  } else if (stream_type == SQUASH_STREAM_DECOMPRESS) {
    s->ctx.decoder = BrotliCreateState(squash_brotli_malloc, squash_brotli_free, NULL);
  } else {
    squash_assert_unreachable();
  }
}
Пример #10
0
static void
squash_density_stream_init (SquashDensityStream* stream,
                            SquashCodec* codec,
                            SquashStreamType stream_type,
                            SquashOptions* options,
                            SquashDestroyNotify destroy_notify) {
  squash_stream_init ((SquashStream*) stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  stream->stream = density_stream_create (NULL, NULL);
  stream->next = SQUASH_DENSITY_ACTION_INIT;

  stream->buffer_size = 0;
  stream->buffer_pos = 0;
  stream->buffer_active = false;

  stream->input_buffer_size = 0;
  stream->input_buffer_active = false;

  stream->active_input_size = 0;

  stream->output_invalid = false;
}
Пример #11
0
static void
squash_lz4f_stream_init (SquashLZ4FStream* stream,
                         SquashCodec* codec,
                         SquashStreamType stream_type,
                         SquashOptions* options,
                         SquashDestroyNotify destroy_notify) {
  LZ4F_errorCode_t ec;
  squash_stream_init ((SquashStream*) stream, codec, stream_type, (SquashOptions*) options, destroy_notify);

  if (stream_type == SQUASH_STREAM_COMPRESS) {
    ec = LZ4F_createCompressionContext(&(stream->data.comp.ctx), LZ4F_VERSION);

    stream->data.comp.state = SQUASH_LZ4F_STATE_INIT;

    stream->data.comp.output_buffer = NULL;
    stream->data.comp.output_buffer_pos = 0;
    stream->data.comp.output_buffer_length = 0;

    stream->data.comp.input_buffer_length = 0;

    stream->data.comp.prefs = (LZ4F_preferences_t) {
      {
        squash_codec_get_option_int_index (codec, options, SQUASH_LZ4F_OPT_BLOCK_SIZE),
        blockLinked,
        squash_codec_get_option_bool_index (codec, options, SQUASH_LZ4F_OPT_CHECKSUM) ?
          contentChecksumEnabled :
          noContentChecksum,
      },
      squash_codec_get_option_int_index (codec, options, SQUASH_LZ4F_OPT_LEVEL)
    };
  } else {
    ec = LZ4F_createDecompressionContext(&(stream->data.decomp.ctx), LZ4F_VERSION);
  }

  assert (!LZ4F_isError (ec));
}