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; }
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; }