#[export_name = "deflateInit_"]
pub unsafe extern "C-unwind" fn deflateInit_(
strm: z_streamp,
level: c_int,
version: *const c_char,
stream_size: c_int,
) -> c_int
Expand description
Initializes the state for compression
The stream’s zalloc
, zfree
and opaque
fields must be initialized before by the caller.
If zalloc
and zfree
are set to NULL
, deflateInit_
updates them to use default allocation functions.
The total_in
, total_out
, adler
, and msg
fields are initialized.
The compression level must be Z_DEFAULT_COMPRESSION
, or between 0
and 9
:
- level
0
gives no compression at all (the input data is simply copied a block at a time) - level
1
gives best speed - level
9
gives best compression Z_DEFAULT_COMPRESSION
requests a default compromise between speed and compression (currently equivalent to level6
).
A call to inflateInit_
is equivalent to inflateInit2_
where
method
is8
(deflate)windowBits
is15
memLevel
is8
strategy
is0
(default)
§Returns
Z_OK
if successZ_MEM_ERROR
if there was not enough memoryZ_VERSION_ERROR
if the zlib library version is incompatible with the version assumed by the callerZ_STREAM_ERROR
if a parameter is invalid, such as a null pointer to the structure
§Safety
The caller must guarantee that
- Either
strm
isNULL
strm
satisfies the requirements of&mut *strm
- Either
version
is NULLversion
satisfies the requirements ofcore::ffi::CStr::from_ptr
- If
strm
is notNULL
, the following fields contain valid valueszalloc
zfree
opaque
§Example
use core::mem::MaybeUninit;
use libz_rs_sys::{z_stream, deflateInit_, zlibVersion, Z_OK};
// the zalloc and zfree fields are initialized as zero/NULL.
// `deflateInit_` will set a default allocation and deallocation function.
let mut strm = MaybeUninit::zeroed();
let err = unsafe {
deflateInit_(
strm.as_mut_ptr(),
6,
zlibVersion(),
core::mem::size_of::<z_stream>() as _,
)
};
assert_eq!(err, Z_OK);
// the stream is now fully initialized. Prefer `assume_init_mut` over
// `assume_init` so the stream does not get moved.
let strm = unsafe { strm.assume_init_mut() };