示例#1
0
static SquashStatus
squash_csc_process_stream (SquashStream* stream, SquashOperation operation) {
  SquashCscStream* s = (SquashCscStream*) stream;

  s->operation = operation;

  CSCProps props;
  unsigned char props_buf[CSC_PROP_SIZE];

  struct SquashCscInStream istream = { squash_csc_reader, s };
  struct SquashCscOutStream ostream = { squash_csc_writer, s };

  if (stream->stream_type == SQUASH_STREAM_COMPRESS) {
    if (stream->options != NULL) {
      SquashCscOptions* opts = (SquashCscOptions*) stream->options;
      CSCEncProps_Init (&props, opts->dict_size, opts->level);
      props.DLTFilter = opts->enable_delta;
      props.EXEFilter = opts->enable_exe;
      props.TXTFilter = opts->enable_txt;
    } else {
      CSCEncProps_Init (&props, SQUASH_CSC_DEFAULT_DICT_SIZE, SQUASH_CSC_DEFAULT_LEVEL);
    }

    CSCEnc_WriteProperties (&props, props_buf, 0);
    size_t bytes_written = squash_csc_writer(&ostream, props_buf, CSC_PROP_SIZE);
    if (bytes_written != CSC_PROP_SIZE)
      return squash_error (SQUASH_FAILED);

    s->ctx.comp = CSCEnc_Create (&props, (ISeqOutStream*) &ostream);
    CSCEnc_Encode (s->ctx.comp, (ISeqInStream*) &istream, NULL);
    CSCEnc_Encode_Flush (s->ctx.comp);
  } else {
    size_t prop_l = CSC_PROP_SIZE;
    squash_csc_reader (&istream, props_buf, &prop_l);
    if (prop_l != CSC_PROP_SIZE)
      return squash_error (SQUASH_FAILED);

    CSCDec_ReadProperties (&props, props_buf);

    s->ctx.decomp = CSCDec_Create (&props, (ISeqInStream*) &istream);
    CSCDec_Decode (s->ctx.decomp, (ISeqOutStream*) &ostream, NULL);
  }

  return SQUASH_OK;
}
示例#2
0
int64_t lzbench_csc_decompress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t, size_t, char*)
{
	MemSeqStream isss, osss;
	CSCProps p;

	CSCDec_ReadProperties(&p, (uint8_t*)inbuf);

    isss.is.Read = stdio_read;
    isss.buf = inbuf + CSC_PROP_SIZE;
	isss.len = insize - CSC_PROP_SIZE;
	
    osss.os.Write = stdio_write;
    osss.buf = outbuf;
	osss.len = 0;

	CSCDecHandle h = CSCDec_Create(&p, (ISeqInStream*)&isss);
	CSCDec_Decode(h, (ISeqOutStream*)&osss, NULL);
	CSCDec_Destroy(h);
	
	return osss.len;
}
示例#3
0
static SquashStatus
squash_csc_splice (SquashCodec* codec,
                   SquashOptions* options,
                   SquashStreamType stream_type,
                   SquashReadFunc read_cb,
                   SquashWriteFunc write_cb,
                   void* user_data) {
  int csc_res;
  SquashStatus res = SQUASH_OK;
  const struct SquashCscInStream in_stream = {
    { squash_csc_reader },
    user_data,
    read_cb,
    write_cb
  };
  const struct SquashCscOutStream out_stream = {
    { squash_csc_writer },
    user_data,
    read_cb,
    write_cb
  };

  CSCProps props;
  unsigned char props_buf[CSC_PROP_SIZE];

  if (stream_type == SQUASH_STREAM_COMPRESS) {
    CSCEncProps_Init (&props,
                      squash_codec_get_option_size_index (codec, options, SQUASH_CSC_OPT_DICT_SIZE),
                      squash_options_get_int_at (options, codec, SQUASH_CSC_OPT_LEVEL));
    props.DLTFilter = squash_options_get_bool_at (options, codec, SQUASH_CSC_OPT_DELTA_FILTER);
    props.EXEFilter = squash_options_get_bool_at (options, codec, SQUASH_CSC_OPT_EXE_FILTER);
    props.TXTFilter = squash_options_get_bool_at (options, codec, SQUASH_CSC_OPT_TXT_FILTER);

    CSCEnc_WriteProperties (&props, props_buf, 0);
    size_t bytes_written = squash_csc_writer ((void*) &out_stream, props_buf, CSC_PROP_SIZE);
    if (SQUASH_UNLIKELY(bytes_written != CSC_PROP_SIZE))
      return squash_error (SQUASH_FAILED);

    CSCEncHandle comp = CSCEnc_Create (&props, (ISeqOutStream*) &out_stream, (ISzAlloc*) &squash_csc_allocator);
    csc_res = CSCEnc_Encode (comp, (ISeqInStream*) &in_stream, NULL);
    if (SQUASH_UNLIKELY(csc_res != 0)) {
      res = squash_error (SQUASH_FAILED);
    } else {
      csc_res = CSCEnc_Encode_Flush (comp);
      if (SQUASH_UNLIKELY(csc_res != 0)) {
        res = squash_error (SQUASH_FAILED);
      }
    }
    CSCEnc_Destroy (comp);
  } else {
    size_t prop_l = CSC_PROP_SIZE;
    squash_csc_reader ((void*) &in_stream, props_buf, &prop_l);
    if (SQUASH_UNLIKELY(prop_l != CSC_PROP_SIZE))
      return squash_error (SQUASH_FAILED);

    CSCDec_ReadProperties (&props, props_buf);

    CSCDecHandle decomp = CSCDec_Create (&props, (ISeqInStream*) &in_stream, (ISzAlloc*) &squash_csc_allocator);
    csc_res = CSCDec_Decode (decomp, (ISeqOutStream*) &out_stream, NULL);
    if (csc_res != 0) {
      res = squash_error (SQUASH_FAILED);
    }
    CSCDec_Destroy (decomp);
  }

  return res;
}
示例#4
0
文件: csc.cpp 项目: pombredanne/CSC
int main(int argc, char *argv[])
{
    FILE *fin, *fout;

    if (argc < 4)
        ShowUsage(argv[0]);

    fin = fopen(argv[argc - 2], "rb");
    fout = fopen(argv[argc - 1], "wb");
    if (fin == NULL || fout == NULL) {
        fprintf(stderr, "File open failed\n");
        return 1;
    }

    StdioSeqStream isss, osss;
    isss.f = fin;
    isss.is.Read = stdio_read;
    osss.f = fout;
    osss.os.Write = stdio_write;
    ICompressProgress prog;
    prog.Progress = show_progress;

    if (argv[1][0] == 'c') {
        CSCProps p;
        uint32_t dict_size = 64000000;
        uint64_t filesize = GetFileSize(fin);
        int level = 2;
        for(int i = 2; i < argc - 2; i++) {
            if (ParseBasicOpt(argv[i], &dict_size, &level) < 0)
                ShowUsage(argv[0]);
        }

        if (filesize < dict_size)
            dict_size = filesize;

        // init the default settings
        CSCEncProps_Init(&p, dict_size, level);
        // Then make extra settings
        for(int i = 2; i < argc - 2; i++) {
            if (ParseOpt(&p, argv[i]) < 0)
                ShowUsage(argv[0]);
        }

        printf("Estimated memory usage: %llu MB\n", CSCEnc_EstMemUsage(&p) / 1048576ull);
        unsigned char buf[CSC_PROP_SIZE];
        CSCEnc_WriteProperties(&p, buf, 0);
        (void)(fwrite(buf, 1, CSC_PROP_SIZE, fout) + 1);
        CSCEncHandle h = CSCEnc_Create(&p, (ISeqOutStream*)&osss);
        CSCEnc_Encode(h, (ISeqInStream*)&isss, &prog);
        CSCEnc_Encode_Flush(h);
        CSCEnc_Destroy(h);
    } else {
        CSCProps p;
        unsigned char buf[CSC_PROP_SIZE];
        (void)(fread(buf, 1, CSC_PROP_SIZE, fin) + 1);
        CSCDec_ReadProperties(&p, buf);
        CSCDecHandle h = CSCDec_Create(&p, (ISeqInStream*)&isss);
        CSCDec_Decode(h, (ISeqOutStream*)&osss, &prog);
        CSCDec_Destroy(h);
    }
    fclose(fin);
    fclose(fout);

    printf("\n");
    return 0;
}