tb_void_t tb_zip_zlibraw_exit(tb_zip_ref_t zip) { tb_zip_zlibraw_t* zlibraw = tb_zip_zlibraw_cast(zip); if (zlibraw) { // close zst if (zip->action == TB_ZIP_ACTION_INFLATE) inflateEnd(&(zlibraw->zst)); else if (zip->action == TB_ZIP_ACTION_DEFLATE) deflateEnd(&(zlibraw->zst)); // free it tb_free(zlibraw); } }
tb_void_t tb_zip_zlibraw_exit(tb_zip_ref_t zip) { // check tb_zip_zlibraw_t* zlibraw = tb_zip_zlibraw_cast(zip); tb_assert_and_check_return(zlibraw); // exit zstream if (zip->action == TB_ZIP_ACTION_INFLATE) inflateEnd(&(zlibraw->zstream)); else if (zip->action == TB_ZIP_ACTION_DEFLATE) deflateEnd(&(zlibraw->zstream)); // free it tb_free(zlibraw); }
static tb_long_t tb_zip_zlibraw_spak_inflate(tb_zip_ref_t zip, tb_static_stream_ref_t ist, tb_static_stream_ref_t ost, tb_long_t sync) { tb_zip_zlibraw_t* zlibraw = tb_zip_zlibraw_cast(zip); tb_assert_and_check_return_val(zlibraw && ist && ost, -1); // the input stream tb_byte_t* ip = ist->p; tb_byte_t* ie = ist->e; tb_check_return_val(ip && ip < ie, 0); // the output stream tb_byte_t* op = ost->p; tb_byte_t* oe = ost->e; tb_assert_and_check_return_val(op && oe, -1); // attach zst zlibraw->zst.next_in = (Bytef*)ip; zlibraw->zst.avail_in = (uInt)(ie - ip); zlibraw->zst.next_out = (Bytef*)op; zlibraw->zst.avail_out = (uInt)(oe - op); // inflate tb_int_t r = inflate(&zlibraw->zst, !sync? Z_NO_FLUSH : Z_SYNC_FLUSH); tb_assertf_and_check_return_val(r == Z_OK || r == Z_STREAM_END, -1, "sync: %ld, error: %d", sync, r); tb_trace_d("inflate: %u => %u, sync: %ld", ie - ip, (tb_byte_t*)zlibraw->zst.next_out - op, sync); // update ist->p = (tb_byte_t*)zlibraw->zst.next_in; ost->p = (tb_byte_t*)zlibraw->zst.next_out; // end? tb_check_return_val(r != Z_STREAM_END || ost->p > op, -1); // ok? return (ost->p - op); }