gio/auto/zlib_compressor.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 /// `GZlibCompressor` is an implementation of [`Converter`][crate::Converter] that
15 /// compresses data using zlib.
16 ///
17 /// ## Properties
18 ///
19 ///
20 /// #### `file-info`
21 /// A [`FileInfo`][crate::FileInfo] containing file information to put into the gzip
22 /// header.
23 ///
24 /// The file name and modification time from the file info will be used.
25 ///
26 /// This will only be used if non-`NULL` and
27 /// [`format`][struct@crate::ZlibCompressor#format] is
28 /// [enum@Gio.ZlibCompressorFormat.GZIP].
29 ///
30 /// Readable | Writeable
31 ///
32 ///
33 /// #### `format`
34 /// The format of the compressed data.
35 ///
36 /// Readable | Writeable | Construct Only
37 ///
38 ///
39 /// #### `level`
40 /// The level of compression from `0` (no compression) to `9` (most
41 /// compression).
42 ///
43 /// `-1` for the default level.
44 ///
45 /// Readable | Writeable | Construct Only
46 ///
47 ///
48 /// #### `os`
49 /// The OS code of the gzip header.
50 ///
51 /// This will be used if set to a non-negative value, and if
52 /// [`format`][struct@crate::ZlibCompressor#format] is
53 /// [enum@Gio.ZlibCompressorFormat.GZIP], the compressor will set the OS code of
54 /// the gzip header to this value.
55 ///
56 /// If the value is unset, zlib will set the OS code depending on the platform.
57 /// This may be undesirable when reproducible output is desired. In that case setting
58 /// the OS code to `3` (for Unix) is recommended.
59 ///
60 /// Readable | Writeable
61 ///
62 /// # Implements
63 ///
64 /// [`trait@glib::ObjectExt`], [`ConverterExt`][trait@crate::prelude::ConverterExt], [`ConverterExtManual`][trait@crate::prelude::ConverterExtManual]
65 #[doc(alias = "GZlibCompressor")]
66 pub struct ZlibCompressor(Object<ffi::GZlibCompressor, ffi::GZlibCompressorClass>) @implements Converter;
67
68 match fn {
69 type_ => || ffi::g_zlib_compressor_get_type(),
70 }
71}
72
73impl ZlibCompressor {
74 /// Creates a compressor.
75 /// ## `format`
76 /// the format to use for the compressed data
77 /// ## `level`
78 /// compression level (`0`-`9`), `-1` for default
79 ///
80 /// # Returns
81 ///
82 /// a new [`ZlibCompressor`][crate::ZlibCompressor]
83 #[doc(alias = "g_zlib_compressor_new")]
84 pub fn new(format: ZlibCompressorFormat, level: i32) -> ZlibCompressor {
85 unsafe { from_glib_full(ffi::g_zlib_compressor_new(format.into_glib(), level)) }
86 }
87
88 /// Gets the [`file-info`][struct@crate::ZlibCompressor#file-info] property.
89 ///
90 /// # Returns
91 ///
92 /// file info for the gzip header, if set
93 #[doc(alias = "g_zlib_compressor_get_file_info")]
94 #[doc(alias = "get_file_info")]
95 #[doc(alias = "file-info")]
96 pub fn file_info(&self) -> Option<FileInfo> {
97 unsafe { from_glib_none(ffi::g_zlib_compressor_get_file_info(self.to_glib_none().0)) }
98 }
99
100 /// Gets the [`os`][struct@crate::ZlibCompressor#os] property.
101 ///
102 /// # Returns
103 ///
104 /// the previously set OS value, or `-1` if unset
105 #[cfg(feature = "v2_86")]
106 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
107 #[doc(alias = "g_zlib_compressor_get_os")]
108 #[doc(alias = "get_os")]
109 pub fn os(&self) -> i32 {
110 unsafe { ffi::g_zlib_compressor_get_os(self.to_glib_none().0) }
111 }
112
113 /// Sets the [`file-info`][struct@crate::ZlibCompressor#file-info] property.
114 ///
115 /// Note: it is an error to call this function while a compression is in
116 /// progress; it may only be called immediately after creation of @self,
117 /// or after resetting it with [`ConverterExt::reset()`][crate::prelude::ConverterExt::reset()].
118 /// ## `file_info`
119 /// file info for the gzip header
120 #[doc(alias = "g_zlib_compressor_set_file_info")]
121 #[doc(alias = "file-info")]
122 pub fn set_file_info(&self, file_info: Option<&FileInfo>) {
123 unsafe {
124 ffi::g_zlib_compressor_set_file_info(self.to_glib_none().0, file_info.to_glib_none().0);
125 }
126 }
127
128 /// Sets the [`os`][struct@crate::ZlibCompressor#os] property.
129 ///
130 /// Note: it is an error to call this function while a compression is in
131 /// progress; it may only be called immediately after creation of @self,
132 /// or after resetting it with [`ConverterExt::reset()`][crate::prelude::ConverterExt::reset()].
133 /// ## `os`
134 /// the OS code to use, or `-1` to unset
135 #[cfg(feature = "v2_86")]
136 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
137 #[doc(alias = "g_zlib_compressor_set_os")]
138 #[doc(alias = "os")]
139 pub fn set_os(&self, os: i32) {
140 unsafe {
141 ffi::g_zlib_compressor_set_os(self.to_glib_none().0, os);
142 }
143 }
144
145 /// The format of the compressed data.
146 pub fn format(&self) -> ZlibCompressorFormat {
147 ObjectExt::property(self, "format")
148 }
149
150 /// The level of compression from `0` (no compression) to `9` (most
151 /// compression).
152 ///
153 /// `-1` for the default level.
154 pub fn level(&self) -> i32 {
155 ObjectExt::property(self, "level")
156 }
157
158 #[doc(alias = "file-info")]
159 pub fn connect_file_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
160 unsafe extern "C" fn notify_file_info_trampoline<F: Fn(&ZlibCompressor) + 'static>(
161 this: *mut ffi::GZlibCompressor,
162 _param_spec: glib::ffi::gpointer,
163 f: glib::ffi::gpointer,
164 ) {
165 let f: &F = &*(f as *const F);
166 f(&from_glib_borrow(this))
167 }
168 unsafe {
169 let f: Box_<F> = Box_::new(f);
170 connect_raw(
171 self.as_ptr() as *mut _,
172 c"notify::file-info".as_ptr() as *const _,
173 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174 notify_file_info_trampoline::<F> as *const (),
175 )),
176 Box_::into_raw(f),
177 )
178 }
179 }
180
181 #[cfg(feature = "v2_86")]
182 #[cfg_attr(docsrs, doc(cfg(feature = "v2_86")))]
183 #[doc(alias = "os")]
184 pub fn connect_os_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
185 unsafe extern "C" fn notify_os_trampoline<F: Fn(&ZlibCompressor) + 'static>(
186 this: *mut ffi::GZlibCompressor,
187 _param_spec: glib::ffi::gpointer,
188 f: glib::ffi::gpointer,
189 ) {
190 let f: &F = &*(f as *const F);
191 f(&from_glib_borrow(this))
192 }
193 unsafe {
194 let f: Box_<F> = Box_::new(f);
195 connect_raw(
196 self.as_ptr() as *mut _,
197 c"notify::os".as_ptr() as *const _,
198 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
199 notify_os_trampoline::<F> as *const (),
200 )),
201 Box_::into_raw(f),
202 )
203 }
204 }
205}