1// Package gio was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gio
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14)
15
16type ZlibCompressorClass struct {
17 _ structs.HostLayout
18
19 ParentClass gobject.ObjectClass
20}
21
22func (x *ZlibCompressorClass) GoPointer() uintptr {
23 return uintptr(unsafe.Pointer(x))
24}
25
26// `GZlibCompressor` is an implementation of [iface@Gio.Converter] that
27// compresses data using zlib.
28type ZlibCompressor struct {
29 gobject.Object
30}
31
32var xZlibCompressorGLibType func() types.GType
33
34func ZlibCompressorGLibType() types.GType {
35 return xZlibCompressorGLibType()
36}
37
38func ZlibCompressorNewFromInternalPtr(ptr uintptr) *ZlibCompressor {
39 cls := &ZlibCompressor{}
40 cls.Ptr = ptr
41 return cls
42}
43
44var xNewZlibCompressor func(ZlibCompressorFormat, int) uintptr
45
46// Creates a compressor.
47func NewZlibCompressor(FormatVar ZlibCompressorFormat, LevelVar int) *ZlibCompressor {
48 var cls *ZlibCompressor
49
50 cret := xNewZlibCompressor(FormatVar, LevelVar)
51
52 if cret == 0 {
53 return nil
54 }
55 cls = &ZlibCompressor{}
56 cls.Ptr = cret
57 return cls
58}
59
60var xZlibCompressorGetFileInfo func(uintptr) uintptr
61
62// Gets the [property@Gio.ZlibCompressor:file-info] property.
63func (x *ZlibCompressor) GetFileInfo() *FileInfo {
64 var cls *FileInfo
65
66 cret := xZlibCompressorGetFileInfo(x.GoPointer())
67
68 if cret == 0 {
69 return nil
70 }
71 gobject.IncreaseRef(cret)
72 cls = &FileInfo{}
73 cls.Ptr = cret
74 return cls
75}
76
77var xZlibCompressorGetOs func(uintptr) int
78
79// Gets the [property@Gio.ZlibCompressor:os] property.
80func (x *ZlibCompressor) GetOs() int {
81
82 cret := xZlibCompressorGetOs(x.GoPointer())
83 return cret
84}
85
86var xZlibCompressorSetFileInfo func(uintptr, uintptr)
87
88// Sets the [property@Gio.ZlibCompressor:file-info] property.
89//
90// Note: it is an error to call this function while a compression is in
91// progress; it may only be called immediately after creation of @compressor,
92// or after resetting it with [method@Gio.Converter.reset].
93func (x *ZlibCompressor) SetFileInfo(FileInfoVar *FileInfo) {
94
95 xZlibCompressorSetFileInfo(x.GoPointer(), FileInfoVar.GoPointer())
96
97}
98
99var xZlibCompressorSetOs func(uintptr, int)
100
101// Sets the [property@Gio.ZlibCompressor:os] property.
102//
103// Note: it is an error to call this function while a compression is in
104// progress; it may only be called immediately after creation of @compressor,
105// or after resetting it with [method@Gio.Converter.reset].
106func (x *ZlibCompressor) SetOs(OsVar int) {
107
108 xZlibCompressorSetOs(x.GoPointer(), OsVar)
109
110}
111
112func (c *ZlibCompressor) GoPointer() uintptr {
113 if c == nil {
114 return 0
115 }
116 return c.Ptr
117}
118
119func (c *ZlibCompressor) SetGoPointer(ptr uintptr) {
120 c.Ptr = ptr
121}
122
123// SetPropertyLevel sets the "level" property.
124// The level of compression from `0` (no compression) to `9` (most
125// compression).
126//
127// `-1` for the default level.
128func (x *ZlibCompressor) SetPropertyLevel(value int) {
129 var v gobject.Value
130 v.Init(gobject.TypeIntVal)
131 v.SetInt(value)
132 x.SetProperty("level", &v)
133}
134
135// GetPropertyLevel gets the "level" property.
136// The level of compression from `0` (no compression) to `9` (most
137// compression).
138//
139// `-1` for the default level.
140func (x *ZlibCompressor) GetPropertyLevel() int {
141 var v gobject.Value
142 x.GetProperty("level", &v)
143 return v.GetInt()
144}
145
146// SetPropertyOs sets the "os" property.
147// The OS code of the gzip header.
148//
149// This will be used if set to a non-negative value, and if
150// [property@Gio.ZlibCompressor:format] is
151// [enum@Gio.ZlibCompressorFormat.GZIP], the compressor will set the OS code of
152// the gzip header to this value.
153//
154// If the value is unset, zlib will set the OS code depending on the platform.
155// This may be undesirable when reproducible output is desired. In that case setting
156// the OS code to `3` (for Unix) is recommended.
157func (x *ZlibCompressor) SetPropertyOs(value int) {
158 var v gobject.Value
159 v.Init(gobject.TypeIntVal)
160 v.SetInt(value)
161 x.SetProperty("os", &v)
162}
163
164// GetPropertyOs gets the "os" property.
165// The OS code of the gzip header.
166//
167// This will be used if set to a non-negative value, and if
168// [property@Gio.ZlibCompressor:format] is
169// [enum@Gio.ZlibCompressorFormat.GZIP], the compressor will set the OS code of
170// the gzip header to this value.
171//
172// If the value is unset, zlib will set the OS code depending on the platform.
173// This may be undesirable when reproducible output is desired. In that case setting
174// the OS code to `3` (for Unix) is recommended.
175func (x *ZlibCompressor) GetPropertyOs() int {
176 var v gobject.Value
177 x.GetProperty("os", &v)
178 return v.GetInt()
179}
180
181// This is the main operation used when converting data. It is to be called
182// multiple times in a loop, and each time it will do some work, i.e.
183// producing some output (in @outbuf) or consuming some input (from @inbuf) or
184// both. If its not possible to do any work an error is returned.
185//
186// Note that a single call may not consume all input (or any input at all).
187// Also a call may produce output even if given no input, due to state stored
188// in the converter producing output.
189//
190// If any data was either produced or consumed, and then an error happens, then
191// only the successful conversion is reported and the error is returned on the
192// next call.
193//
194// A full conversion loop involves calling this method repeatedly, each time
195// giving it new input and space output space. When there is no more input
196// data after the data in @inbuf, the flag %G_CONVERTER_INPUT_AT_END must be set.
197// The loop will be (unless some error happens) returning %G_CONVERTER_CONVERTED
198// each time until all data is consumed and all output is produced, then
199// %G_CONVERTER_FINISHED is returned instead. Note, that %G_CONVERTER_FINISHED
200// may be returned even if %G_CONVERTER_INPUT_AT_END is not set, for instance
201// in a decompression converter where the end of data is detectable from the
202// data (and there might even be other data after the end of the compressed data).
203//
204// When some data has successfully been converted @bytes_read and is set to
205// the number of bytes read from @inbuf, and @bytes_written is set to indicate
206// how many bytes was written to @outbuf. If there are more data to output
207// or consume (i.e. unless the %G_CONVERTER_INPUT_AT_END is specified) then
208// %G_CONVERTER_CONVERTED is returned, and if no more data is to be output
209// then %G_CONVERTER_FINISHED is returned.
210//
211// On error %G_CONVERTER_ERROR is returned and @error is set accordingly.
212// Some errors need special handling:
213//
214// %G_IO_ERROR_NO_SPACE is returned if there is not enough space
215// to write the resulting converted data, the application should
216// call the function again with a larger @outbuf to continue.
217//
218// %G_IO_ERROR_PARTIAL_INPUT is returned if there is not enough
219// input to fully determine what the conversion should produce,
220// and the %G_CONVERTER_INPUT_AT_END flag is not set. This happens for
221// example with an incomplete multibyte sequence when converting text,
222// or when a regexp matches up to the end of the input (and may match
223// further input). It may also happen when @inbuf_size is zero and
224// there is no more data to produce.
225//
226// When this happens the application should read more input and then
227// call the function again. If further input shows that there is no
228// more data call the function again with the same data but with
229// the %G_CONVERTER_INPUT_AT_END flag set. This may cause the conversion
230// to finish as e.g. in the regexp match case (or, to fail again with
231// %G_IO_ERROR_PARTIAL_INPUT in e.g. a charset conversion where the
232// input is actually partial).
233//
234// After g_converter_convert() has returned %G_CONVERTER_FINISHED the
235// converter object is in an invalid state where its not allowed
236// to call g_converter_convert() anymore. At this time you can only
237// free the object or call g_converter_reset() to reset it to the
238// initial state.
239//
240// If the flag %G_CONVERTER_FLUSH is set then conversion is modified
241// to try to write out all internal state to the output. The application
242// has to call the function multiple times with the flag set, and when
243// the available input has been consumed and all internal state has
244// been produced then %G_CONVERTER_FLUSHED (or %G_CONVERTER_FINISHED if
245// really at the end) is returned instead of %G_CONVERTER_CONVERTED.
246// This is somewhat similar to what happens at the end of the input stream,
247// but done in the middle of the data.
248//
249// This has different meanings for different conversions. For instance
250// in a compression converter it would mean that we flush all the
251// compression state into output such that if you uncompress the
252// compressed data you get back all the input data. Doing this may
253// make the final file larger due to padding though. Another example
254// is a regexp conversion, where if you at the end of the flushed data
255// have a match, but there is also a potential longer match. In the
256// non-flushed case we would ask for more input, but when flushing we
257// treat this as the end of input and do the match.
258//
259// Flushing is not always possible (like if a charset converter flushes
260// at a partial multibyte sequence). Converters are supposed to try
261// to produce as much output as possible and then return an error
262// (typically %G_IO_ERROR_PARTIAL_INPUT).
263func (x *ZlibCompressor) Convert(InbufVar []byte, InbufSizeVar uint, OutbufVar []byte, OutbufSizeVar uint, FlagsVar ConverterFlags, BytesReadVar *uint, BytesWrittenVar *uint) (ConverterResult, error) {
264 var cerr *glib.Error
265
266 cret := XGConverterConvert(x.GoPointer(), InbufVar, InbufSizeVar, OutbufVar, OutbufSizeVar, FlagsVar, BytesReadVar, BytesWrittenVar, &cerr)
267 if cerr == nil {
268 return cret, nil
269 }
270 return cret, cerr
271
272}
273
274// Applies @converter to the data in @bytes.
275func (x *ZlibCompressor) ConvertBytes(BytesVar *glib.Bytes) (*glib.Bytes, error) {
276 var cerr *glib.Error
277
278 cret := XGConverterConvertBytes(x.GoPointer(), BytesVar, &cerr)
279 if cerr == nil {
280 return cret, nil
281 }
282 return cret, cerr
283
284}
285
286// Resets all internal state in the converter, making it behave
287// as if it was just created. If the converter has any internal
288// state that would produce output then that output is lost.
289func (x *ZlibCompressor) Reset() {
290
291 XGConverterReset(x.GoPointer())
292
293}
294
295func init() {
296 core.SetPackageName("GIO", "gio-2.0")
297 core.SetSharedLibraries("GIO", []string{"libgio-2.0.so.0"})
298 var libs []uintptr
299 for _, libPath := range core.GetPaths("GIO") {
300 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
301 if err != nil {
302 panic(err)
303 }
304 libs = append(libs, lib)
305 }
306
307 core.PuregoSafeRegister(&xZlibCompressorGLibType, libs, "g_zlib_compressor_get_type")
308
309 core.PuregoSafeRegister(&xNewZlibCompressor, libs, "g_zlib_compressor_new")
310
311 core.PuregoSafeRegister(&xZlibCompressorGetFileInfo, libs, "g_zlib_compressor_get_file_info")
312 core.PuregoSafeRegister(&xZlibCompressorGetOs, libs, "g_zlib_compressor_get_os")
313 core.PuregoSafeRegister(&xZlibCompressorSetFileInfo, libs, "g_zlib_compressor_set_file_info")
314 core.PuregoSafeRegister(&xZlibCompressorSetOs, libs, "g_zlib_compressor_set_os")
315
316}