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::{ffi, Converter, FileInfo, ZlibCompressorFormat};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
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    ///  A [`FileInfo`][crate::FileInfo] containing the information found in the gzip header
22    /// of the data stream processed.
23    ///
24    /// This will be `NULL` if the header was not yet fully processed, is not
25    /// present at all, or the compressor’s [`format`][struct@crate::ZlibDecompressor#format]
26    /// property is not [enum@Gio.ZlibCompressorFormat.GZIP].
27    ///
28    /// Readable
29    ///
30    ///
31    /// #### `format`
32    ///  The format of the compressed data.
33    ///
34    /// Readable | Writeable | Construct Only
35    ///
36    /// # Implements
37    ///
38    /// [`trait@glib::ObjectExt`], [`ConverterExt`][trait@crate::prelude::ConverterExt], [`ConverterExtManual`][trait@crate::prelude::ConverterExtManual]
39    #[doc(alias = "GZlibDecompressor")]
40    pub struct ZlibDecompressor(Object<ffi::GZlibDecompressor, ffi::GZlibDecompressorClass>) @implements Converter;
41
42    match fn {
43        type_ => || ffi::g_zlib_decompressor_get_type(),
44    }
45}
46
47impl ZlibDecompressor {
48    /// Creates a new decompressor.
49    /// ## `format`
50    /// the format to use for the compressed data
51    ///
52    /// # Returns
53    ///
54    /// a new [`ZlibDecompressor`][crate::ZlibDecompressor]
55    #[doc(alias = "g_zlib_decompressor_new")]
56    pub fn new(format: ZlibCompressorFormat) -> ZlibDecompressor {
57        unsafe { from_glib_full(ffi::g_zlib_decompressor_new(format.into_glib())) }
58    }
59
60    /// Gets the [`file-info`][struct@crate::ZlibDecompressor#file-info] property.
61    ///
62    /// # Returns
63    ///
64    /// file info from the gzip header, if available
65    #[doc(alias = "g_zlib_decompressor_get_file_info")]
66    #[doc(alias = "get_file_info")]
67    #[doc(alias = "file-info")]
68    pub fn file_info(&self) -> Option<FileInfo> {
69        unsafe {
70            from_glib_none(ffi::g_zlib_decompressor_get_file_info(
71                self.to_glib_none().0,
72            ))
73        }
74    }
75
76    /// The format of the compressed data.
77    pub fn format(&self) -> ZlibCompressorFormat {
78        ObjectExt::property(self, "format")
79    }
80
81    #[doc(alias = "file-info")]
82    pub fn connect_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
83        unsafe extern "C" fn notify_file_info_trampoline<F: Fn(&ZlibDecompressor) + 'static>(
84            this: *mut ffi::GZlibDecompressor,
85            _param_spec: glib::ffi::gpointer,
86            f: glib::ffi::gpointer,
87        ) {
88            let f: &F = &*(f as *const F);
89            f(&from_glib_borrow(this))
90        }
91        unsafe {
92            let f: Box_<F> = Box_::new(f);
93            connect_raw(
94                self.as_ptr() as *mut _,
95                c"notify::file-info".as_ptr() as *const _,
96                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
97                    notify_file_info_trampoline::<F> as *const (),
98                )),
99                Box_::into_raw(f),
100            )
101        }
102    }
103}