Skip to main content

gio/auto/
zlib_decompressor.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Converter, FileInfo, ZlibCompressorFormat, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// `GZlibDecompressor` is an implementation of [`Converter`][crate::Converter] that
15    /// decompresses data compressed with zlib.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `file-info`
21    ///  s [`format`][struct@crate::ZlibDecompressor#format]
22    /// property is not [enum@Gio.ZlibCompressorFormat.GZIP].
23    ///
24    /// Readable
25    ///
26    ///
27    /// #### `format`
28    ///  The format of the compressed data.
29    ///
30    /// Readable | Writable | Construct Only
31    ///
32    /// # Implements
33    ///
34    /// [`trait@glib::ObjectExt`], [`ConverterExt`][trait@crate::prelude::ConverterExt], [`ConverterExtManual`][trait@crate::prelude::ConverterExtManual]
35    #[doc(alias = "GZlibDecompressor")]
36    pub struct ZlibDecompressor(Object<ffi::GZlibDecompressor, ffi::GZlibDecompressorClass>) @implements Converter;
37
38    match fn {
39        type_ => || ffi::g_zlib_decompressor_get_type(),
40    }
41}
42
43impl ZlibDecompressor {
44    /// Creates a new decompressor.
45    /// ## `format`
46    /// the format to use for the compressed data
47    ///
48    /// # Returns
49    ///
50    /// a new [`ZlibDecompressor`][crate::ZlibDecompressor]
51    #[doc(alias = "g_zlib_decompressor_new")]
52    pub fn new(format: ZlibCompressorFormat) -> ZlibDecompressor {
53        unsafe { from_glib_full(ffi::g_zlib_decompressor_new(format.into_glib())) }
54    }
55
56    /// Gets the [`file-info`][struct@crate::ZlibDecompressor#file-info] property.
57    ///
58    /// # Returns
59    ///
60    /// file info from the gzip header, if available
61    #[doc(alias = "g_zlib_decompressor_get_file_info")]
62    #[doc(alias = "get_file_info")]
63    #[doc(alias = "file-info")]
64    pub fn file_info(&self) -> Option<FileInfo> {
65        unsafe {
66            from_glib_none(ffi::g_zlib_decompressor_get_file_info(
67                self.to_glib_none().0,
68            ))
69        }
70    }
71
72    /// The format of the compressed data.
73    pub fn format(&self) -> ZlibCompressorFormat {
74        ObjectExt::property(self, "format")
75    }
76
77    #[doc(alias = "file-info")]
78    pub fn connect_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
79        unsafe extern "C" fn notify_file_info_trampoline<F: Fn(&ZlibDecompressor) + 'static>(
80            this: *mut ffi::GZlibDecompressor,
81            _param_spec: glib::ffi::gpointer,
82            f: glib::ffi::gpointer,
83        ) {
84            unsafe {
85                let f: &F = &*(f as *const F);
86                f(&from_glib_borrow(this))
87            }
88        }
89        unsafe {
90            let f: Box_<F> = Box_::new(f);
91            connect_raw(
92                self.as_ptr() as *mut _,
93                c"notify::file-info".as_ptr(),
94                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
95                    notify_file_info_trampoline::<F> as *const (),
96                )),
97                Box_::into_raw(f),
98            )
99        }
100    }
101}