source: appstream-generator/build/girepo/gio/BufferedInputStream.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 10.0 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.BufferedInputStream;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import gio.AsyncResultIF;
26private import gio.Cancellable;
27private import gio.FilterInputStream;
28private import gio.InputStream;
29private import gio.SeekableIF;
30private import gio.SeekableT;
31private import glib.ConstructionException;
32private import glib.ErrorG;
33private import glib.GException;
34private import gobject.ObjectG;
35
36
37/**
38 * Buffered input stream implements #GFilterInputStream and provides
39 * for buffered reads.
40 *
41 * By default, #GBufferedInputStream's buffer size is set at 4 kilobytes.
42 *
43 * To create a buffered input stream, use g_buffered_input_stream_new(),
44 * or g_buffered_input_stream_new_sized() to specify the buffer's size at
45 * construction.
46 *
47 * To get the size of a buffer within a buffered input stream, use
48 * g_buffered_input_stream_get_buffer_size(). To change the size of a
49 * buffered input stream's buffer, use
50 * g_buffered_input_stream_set_buffer_size(). Note that the buffer's size
51 * cannot be reduced below the size of the data within the buffer.
52 */
53public class BufferedInputStream : FilterInputStream, SeekableIF
54{
55        /** the main Gtk struct */
56        protected GBufferedInputStream* gBufferedInputStream;
57
58        /** Get the main Gtk struct */
59        public GBufferedInputStream* getBufferedInputStreamStruct()
60        {
61                return gBufferedInputStream;
62        }
63
64        /** the main Gtk struct as a void* */
65        protected override void* getStruct()
66        {
67                return cast(void*)gBufferedInputStream;
68        }
69
70        protected override void setStruct(GObject* obj)
71        {
72                gBufferedInputStream = cast(GBufferedInputStream*)obj;
73                super.setStruct(obj);
74        }
75
76        /**
77         * Sets our main struct and passes it to the parent class.
78         */
79        public this (GBufferedInputStream* gBufferedInputStream, bool ownedRef = false)
80        {
81                this.gBufferedInputStream = gBufferedInputStream;
82                super(cast(GFilterInputStream*)gBufferedInputStream, ownedRef);
83        }
84
85        // add the Seekable capabilities
86        mixin SeekableT!(GBufferedInputStream);
87
88        /**
89         * Returns the buffer with the currently available bytes. The returned
90         * buffer must not be modified and will become invalid when reading from
91         * the stream or filling the buffer.
92         *
93         * Params:
94         *     count = a #gsize to get the number of bytes available in the buffer
95         *
96         * Return: read-only buffer
97         */
98        public ubyte[] peekBuffer()
99        {
100                size_t count;
101               
102                auto p = g_buffered_input_stream_peek_buffer(gBufferedInputStream, &count);
103               
104                return (cast(ubyte*)p)[0 .. count];
105        }
106
107        /**
108         */
109
110        /** */
111        public static GType getType()
112        {
113                return g_buffered_input_stream_get_type();
114        }
115
116        /**
117         * Creates a new #GInputStream from the given @base_stream, with
118         * a buffer set to the default size (4 kilobytes).
119         *
120         * Params:
121         *     baseStream = a #GInputStream
122         *
123         * Returns: a #GInputStream for the given @base_stream.
124         *
125         * Throws: ConstructionException GTK+ fails to create the object.
126         */
127        public this(InputStream baseStream)
128        {
129                auto p = g_buffered_input_stream_new((baseStream is null) ? null : baseStream.getInputStreamStruct());
130               
131                if(p is null)
132                {
133                        throw new ConstructionException("null returned by new");
134                }
135               
136                this(cast(GBufferedInputStream*) p, true);
137        }
138
139        /**
140         * Creates a new #GBufferedInputStream from the given @base_stream,
141         * with a buffer set to @size.
142         *
143         * Params:
144         *     baseStream = a #GInputStream
145         *     size = a #gsize
146         *
147         * Returns: a #GInputStream.
148         *
149         * Throws: ConstructionException GTK+ fails to create the object.
150         */
151        public this(InputStream baseStream, size_t size)
152        {
153                auto p = g_buffered_input_stream_new_sized((baseStream is null) ? null : baseStream.getInputStreamStruct(), size);
154               
155                if(p is null)
156                {
157                        throw new ConstructionException("null returned by new_sized");
158                }
159               
160                this(cast(GBufferedInputStream*) p, true);
161        }
162
163        /**
164         * Tries to read @count bytes from the stream into the buffer.
165         * Will block during this read.
166         *
167         * If @count is zero, returns zero and does nothing. A value of @count
168         * larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error.
169         *
170         * On success, the number of bytes read into the buffer is returned.
171         * It is not an error if this is not the same as the requested size, as it
172         * can happen e.g. near the end of a file. Zero is returned on end of file
173         * (or if @count is zero),  but never otherwise.
174         *
175         * If @count is -1 then the attempted read size is equal to the number of
176         * bytes that are required to fill the buffer.
177         *
178         * If @cancellable is not %NULL, then the operation can be cancelled by
179         * triggering the cancellable object from another thread. If the operation
180         * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
181         * operation was partially finished when the operation was cancelled the
182         * partial result will be returned, without an error.
183         *
184         * On error -1 is returned and @error is set accordingly.
185         *
186         * For the asynchronous, non-blocking, version of this function, see
187         * g_buffered_input_stream_fill_async().
188         *
189         * Params:
190         *     count = the number of bytes that will be read from the stream
191         *     cancellable = optional #GCancellable object, %NULL to ignore
192         *
193         * Returns: the number of bytes read into @stream's buffer, up to @count,
194         *     or -1 on error.
195         *
196         * Throws: GException on failure.
197         */
198        public ptrdiff_t fill(ptrdiff_t count, Cancellable cancellable)
199        {
200                GError* err = null;
201               
202                auto p = g_buffered_input_stream_fill(gBufferedInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
203               
204                if (err !is null)
205                {
206                        throw new GException( new ErrorG(err) );
207                }
208               
209                return p;
210        }
211
212        /**
213         * Reads data into @stream's buffer asynchronously, up to @count size.
214         * @io_priority can be used to prioritize reads. For the synchronous
215         * version of this function, see g_buffered_input_stream_fill().
216         *
217         * If @count is -1 then the attempted read size is equal to the number
218         * of bytes that are required to fill the buffer.
219         *
220         * Params:
221         *     count = the number of bytes that will be read from the stream
222         *     ioPriority = the [I/O priority][io-priority] of the request
223         *     cancellable = optional #GCancellable object
224         *     callback = a #GAsyncReadyCallback
225         *     userData = a #gpointer
226         */
227        public void fillAsync(ptrdiff_t count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
228        {
229                g_buffered_input_stream_fill_async(gBufferedInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
230        }
231
232        /**
233         * Finishes an asynchronous read.
234         *
235         * Params:
236         *     result = a #GAsyncResult
237         *
238         * Returns: a #gssize of the read stream, or %-1 on an error.
239         *
240         * Throws: GException on failure.
241         */
242        public ptrdiff_t fillFinish(AsyncResultIF result)
243        {
244                GError* err = null;
245               
246                auto p = g_buffered_input_stream_fill_finish(gBufferedInputStream, (result is null) ? null : result.getAsyncResultStruct(), &err);
247               
248                if (err !is null)
249                {
250                        throw new GException( new ErrorG(err) );
251                }
252               
253                return p;
254        }
255
256        /**
257         * Gets the size of the available data within the stream.
258         *
259         * Returns: size of the available stream.
260         */
261        public size_t getAvailable()
262        {
263                return g_buffered_input_stream_get_available(gBufferedInputStream);
264        }
265
266        /**
267         * Gets the size of the input buffer.
268         *
269         * Returns: the current buffer size.
270         */
271        public size_t getBufferSize()
272        {
273                return g_buffered_input_stream_get_buffer_size(gBufferedInputStream);
274        }
275
276        /**
277         * Peeks in the buffer, copying data of size @count into @buffer,
278         * offset @offset bytes.
279         *
280         * Params:
281         *     buffer = a pointer to
282         *         an allocated chunk of memory
283         *     offset = a #gsize
284         *     count = a #gsize
285         *
286         * Returns: a #gsize of the number of bytes peeked, or -1 on error.
287         */
288        public size_t peek(ubyte[] buffer, size_t offset)
289        {
290                return g_buffered_input_stream_peek(gBufferedInputStream, buffer.ptr, offset, cast(size_t)buffer.length);
291        }
292
293        /**
294         * Tries to read a single byte from the stream or the buffer. Will block
295         * during this read.
296         *
297         * On success, the byte read from the stream is returned. On end of stream
298         * -1 is returned but it's not an exceptional error and @error is not set.
299         *
300         * If @cancellable is not %NULL, then the operation can be cancelled by
301         * triggering the cancellable object from another thread. If the operation
302         * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an
303         * operation was partially finished when the operation was cancelled the
304         * partial result will be returned, without an error.
305         *
306         * On error -1 is returned and @error is set accordingly.
307         *
308         * Params:
309         *     cancellable = optional #GCancellable object, %NULL to ignore
310         *
311         * Returns: the byte read from the @stream, or -1 on end of stream or error.
312         *
313         * Throws: GException on failure.
314         */
315        public int readByte(Cancellable cancellable)
316        {
317                GError* err = null;
318               
319                auto p = g_buffered_input_stream_read_byte(gBufferedInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
320               
321                if (err !is null)
322                {
323                        throw new GException( new ErrorG(err) );
324                }
325               
326                return p;
327        }
328
329        /**
330         * Sets the size of the internal buffer of @stream to @size, or to the
331         * size of the contents of the buffer. The buffer can never be resized
332         * smaller than its current contents.
333         *
334         * Params:
335         *     size = a #gsize
336         */
337        public void setBufferSize(size_t size)
338        {
339                g_buffered_input_stream_set_buffer_size(gBufferedInputStream, size);
340        }
341}
Note: See TracBrowser for help on using the repository browser.