fpzip-sys

Crates.iofpzip-sys
lib.rsfpzip-sys
version0.2.0
sourcesrc
created_at2020-06-18 04:39:28.982152
updated_at2024-10-24 04:16:32.315891
descriptionRaw Rust bindings to FPZIP (https://github.com/LLNL/fpzip).
homepage
repositoryhttps://github.com/jvo203/fpzip-sys
max_upload_size
id255210
size106,832
(jvo203)

documentation

README

fpzip-sys

Raw Rust bindings to FPZIP (https://github.com/LLNL/fpzip).

An example compression function for a 1D f32 vector:

use fpzip_sys::*;

// ...

fn fpzip_compress(src: &Vec<f32>, high_quality: bool) -> Option<Vec<u8>> {
    let prec = if high_quality {
        24
    } else {
        16
    };
    
    /* allocate buffer for compressed data */
    let bufsize = 1024 + src.len() * std::mem::size_of::<f32>();
    let mut buffer: Vec<u8> = vec![0; bufsize];

    /* compress to memory */
    let fpz = unsafe {
        fpzip_write_to_buffer(buffer.as_mut_ptr() as *mut std::ffi::c_void, bufsize as u64)
    };

    unsafe {
        (*fpz).type_ = FPZIP_TYPE_FLOAT as i32;
        (*fpz).prec = prec;
        (*fpz).nx = src.len() as i32;
        (*fpz).ny = 1;
        (*fpz).nz = 1;
        (*fpz).nf = 1;
    }

    let stat = unsafe { fpzip_write_header(fpz) };

    if stat == 0 {
        unsafe { fpzip_write_close(fpz) };
        return None;
    };

    let outbytes = unsafe { fpzip_write(fpz, src.as_ptr() as *const std::ffi::c_void) };

    unsafe { fpzip_write_close(fpz) };

    if outbytes == 0 {
        return None;
    };

    println!("[fpzip::compress] {} reduced to {} bytes.", src.len() * std::mem::size_of::<f32>(), outbytes);

    return Some(buffer[0..outbytes as usize].to_vec());
}
Commit count: 25

cargo fmt