1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GInputStream.html
27  * outPack = gio
28  * outFile = InputStream
29  * strct   = GInputStream
30  * realStrct=
31  * ctorStrct=
32  * clss    = InputStream
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_input_stream_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.ErrorG
47  * 	- glib.GException
48  * 	- glib.Bytes
49  * 	- gio.AsyncResultIF
50  * 	- gio.Cancellable
51  * structWrap:
52  * 	- GAsyncResult* -> AsyncResultIF
53  * 	- GBytes* -> Bytes
54  * 	- GCancellable* -> Cancellable
55  * module aliases:
56  * local aliases:
57  * overrides:
58  */
59 
60 module gio.InputStream;
61 
62 public  import gtkc.giotypes;
63 
64 private import gtkc.gio;
65 private import glib.ConstructionException;
66 private import gobject.ObjectG;
67 
68 private import glib.ErrorG;
69 private import glib.GException;
70 private import glib.Bytes;
71 private import gio.AsyncResultIF;
72 private import gio.Cancellable;
73 
74 
75 private import gobject.ObjectG;
76 
77 /**
78  * GInputStream has functions to read from a stream (g_input_stream_read()),
79  * to close a stream (g_input_stream_close()) and to skip some content
80  * (g_input_stream_skip()).
81  *
82  * To copy the content of an input stream to an output stream without
83  * manually handling the reads and writes, use g_output_stream_splice().
84  *
85  * All of these functions have async variants too.
86  */
87 public class InputStream : ObjectG
88 {
89 	
90 	/** the main Gtk struct */
91 	protected GInputStream* gInputStream;
92 	
93 	
94 	/** Get the main Gtk struct */
95 	public GInputStream* getInputStreamStruct()
96 	{
97 		return gInputStream;
98 	}
99 	
100 	
101 	/** the main Gtk struct as a void* */
102 	protected override void* getStruct()
103 	{
104 		return cast(void*)gInputStream;
105 	}
106 	
107 	/**
108 	 * Sets our main struct and passes it to the parent class
109 	 */
110 	public this (GInputStream* gInputStream)
111 	{
112 		super(cast(GObject*)gInputStream);
113 		this.gInputStream = gInputStream;
114 	}
115 	
116 	protected override void setStruct(GObject* obj)
117 	{
118 		super.setStruct(obj);
119 		gInputStream = cast(GInputStream*)obj;
120 	}
121 	
122 	/**
123 	 */
124 	
125 	/**
126 	 * Tries to read count bytes from the stream into the buffer starting at
127 	 * buffer. Will block during this read.
128 	 * If count is zero returns zero and does nothing. A value of count
129 	 * larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
130 	 * On success, the number of bytes read into the buffer is returned.
131 	 * It is not an error if this is not the same as the requested size, as it
132 	 * can happen e.g. near the end of a file. Zero is returned on end of file
133 	 * (or if count is zero), but never otherwise.
134 	 * If cancellable is not NULL, then the operation can be cancelled by
135 	 * triggering the cancellable object from another thread. If the operation
136 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
137 	 * operation was partially finished when the operation was cancelled the
138 	 * partial result will be returned, without an error.
139 	 * On error -1 is returned and error is set accordingly.
140 	 * Params:
141 	 * buffer = a buffer to
142 	 * read data into (which should be at least count bytes long). [array length=count][element-type guint8]
143 	 * count = the number of bytes that will be read from the stream
144 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
145 	 * Returns: Number of bytes read, or -1 on error, or 0 on end of file.
146 	 * Throws: GException on failure.
147 	 */
148 	public gssize read(void* buffer, gsize count, Cancellable cancellable)
149 	{
150 		// gssize g_input_stream_read (GInputStream *stream,  void *buffer,  gsize count,  GCancellable *cancellable,  GError **error);
151 		GError* err = null;
152 		
153 		auto p = g_input_stream_read(gInputStream, buffer, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
154 		
155 		if (err !is null)
156 		{
157 			throw new GException( new ErrorG(err) );
158 		}
159 		
160 		return p;
161 	}
162 	
163 	/**
164 	 * Tries to read count bytes from the stream into the buffer starting at
165 	 * buffer. Will block during this read.
166 	 * This function is similar to g_input_stream_read(), except it tries to
167 	 * read as many bytes as requested, only stopping on an error or end of stream.
168 	 * On a successful read of count bytes, or if we reached the end of the
169 	 * stream, TRUE is returned, and bytes_read is set to the number of bytes
170 	 * read into buffer.
171 	 * If there is an error during the operation FALSE is returned and error
172 	 * is set to indicate the error status, bytes_read is updated to contain
173 	 * the number of bytes read into buffer before the error occurred.
174 	 * Params:
175 	 * buffer = a buffer to
176 	 * read data into (which should be at least count bytes long). [array length=count][element-type guint8]
177 	 * count = the number of bytes that will be read from the stream
178 	 * bytesRead = location to store the number of bytes that was read from the stream. [out]
179 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
180 	 * Returns: TRUE on success, FALSE if there was an error
181 	 * Throws: GException on failure.
182 	 */
183 	public int readAll(void* buffer, gsize count, out gsize bytesRead, Cancellable cancellable)
184 	{
185 		// gboolean g_input_stream_read_all (GInputStream *stream,  void *buffer,  gsize count,  gsize *bytes_read,  GCancellable *cancellable,  GError **error);
186 		GError* err = null;
187 		
188 		auto p = g_input_stream_read_all(gInputStream, buffer, count, &bytesRead, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
189 		
190 		if (err !is null)
191 		{
192 			throw new GException( new ErrorG(err) );
193 		}
194 		
195 		return p;
196 	}
197 	
198 	/**
199 	 * Tries to skip count bytes from the stream. Will block during the operation.
200 	 * This is identical to g_input_stream_read(), from a behaviour standpoint,
201 	 * but the bytes that are skipped are not returned to the user. Some
202 	 * streams have an implementation that is more efficient than reading the data.
203 	 * This function is optional for inherited classes, as the default implementation
204 	 * emulates it using read.
205 	 * If cancellable is not NULL, then the operation can be cancelled by
206 	 * triggering the cancellable object from another thread. If the operation
207 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
208 	 * operation was partially finished when the operation was cancelled the
209 	 * partial result will be returned, without an error.
210 	 * Params:
211 	 * count = the number of bytes that will be skipped from the stream
212 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
213 	 * Returns: Number of bytes skipped, or -1 on error
214 	 * Throws: GException on failure.
215 	 */
216 	public gssize skip(gsize count, Cancellable cancellable)
217 	{
218 		// gssize g_input_stream_skip (GInputStream *stream,  gsize count,  GCancellable *cancellable,  GError **error);
219 		GError* err = null;
220 		
221 		auto p = g_input_stream_skip(gInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
222 		
223 		if (err !is null)
224 		{
225 			throw new GException( new ErrorG(err) );
226 		}
227 		
228 		return p;
229 	}
230 	
231 	/**
232 	 * Closes the stream, releasing resources related to it.
233 	 * Once the stream is closed, all other operations will return G_IO_ERROR_CLOSED.
234 	 * Closing a stream multiple times will not return an error.
235 	 * Streams will be automatically closed when the last reference
236 	 * is dropped, but you might want to call this function to make sure
237 	 * resources are released as early as possible.
238 	 * Some streams might keep the backing store of the stream (e.g. a file descriptor)
239 	 * open after the stream is closed. See the documentation for the individual
240 	 * stream for details.
241 	 * On failure the first error that happened will be reported, but the close
242 	 * operation will finish as much as possible. A stream that failed to
243 	 * close will still return G_IO_ERROR_CLOSED for all operations. Still, it
244 	 * is important to check and report the error to the user.
245 	 * If cancellable is not NULL, then the operation can be cancelled by
246 	 * triggering the cancellable object from another thread. If the operation
247 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned.
248 	 * Cancelling a close will still leave the stream closed, but some streams
249 	 * can use a faster close that doesn't block to e.g. check errors.
250 	 * Params:
251 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
252 	 * Returns: TRUE on success, FALSE on failure
253 	 * Throws: GException on failure.
254 	 */
255 	public int close(Cancellable cancellable)
256 	{
257 		// gboolean g_input_stream_close (GInputStream *stream,  GCancellable *cancellable,  GError **error);
258 		GError* err = null;
259 		
260 		auto p = g_input_stream_close(gInputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
261 		
262 		if (err !is null)
263 		{
264 			throw new GException( new ErrorG(err) );
265 		}
266 		
267 		return p;
268 	}
269 	
270 	/**
271 	 * Request an asynchronous read of count bytes from the stream into the buffer
272 	 * starting at buffer. When the operation is finished callback will be called.
273 	 * You can then call g_input_stream_read_finish() to get the result of the
274 	 * operation.
275 	 * During an async request no other sync and async calls are allowed on stream, and will
276 	 * result in G_IO_ERROR_PENDING errors.
277 	 * A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
278 	 * On success, the number of bytes read into the buffer will be passed to the
279 	 * callback. It is not an error if this is not the same as the requested size, as it
280 	 * can happen e.g. near the end of a file, but generally we try to read
281 	 * as many bytes as requested. Zero is returned on end of file
282 	 * (or if count is zero), but never otherwise.
283 	 * Any outstanding i/o request with higher priority (lower numerical value) will
284 	 * be executed before an outstanding request with lower priority. Default
285 	 * priority is G_PRIORITY_DEFAULT.
286 	 * The asyncronous methods have a default fallback that uses threads to implement
287 	 * asynchronicity, so they are optional for inheriting classes. However, if you
288 	 * override one you must override all.
289 	 * Params:
290 	 * buffer = a buffer to
291 	 * read data into (which should be at least count bytes long). [array length=count][element-type guint8]
292 	 * count = the number of bytes that will be read from the stream
293 	 * ioPriority = the I/O priority
294 	 * of the request.
295 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
296 	 * callback = callback to call when the request is satisfied. [scope async]
297 	 * userData = the data to pass to callback function. [closure]
298 	 */
299 	public void readAsync(void* buffer, gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
300 	{
301 		// void g_input_stream_read_async (GInputStream *stream,  void *buffer,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
302 		g_input_stream_read_async(gInputStream, buffer, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
303 	}
304 	
305 	/**
306 	 * Finishes an asynchronous stream read operation.
307 	 * Params:
308 	 * result = a GAsyncResult.
309 	 * Returns: number of bytes read in, or -1 on error, or 0 on end of file.
310 	 * Throws: GException on failure.
311 	 */
312 	public gssize readFinish(AsyncResultIF result)
313 	{
314 		// gssize g_input_stream_read_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
315 		GError* err = null;
316 		
317 		auto p = g_input_stream_read_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
318 		
319 		if (err !is null)
320 		{
321 			throw new GException( new ErrorG(err) );
322 		}
323 		
324 		return p;
325 	}
326 	
327 	/**
328 	 * Request an asynchronous skip of count bytes from the stream.
329 	 * When the operation is finished callback will be called.
330 	 * You can then call g_input_stream_skip_finish() to get the result
331 	 * of the operation.
332 	 * During an async request no other sync and async calls are allowed,
333 	 * and will result in G_IO_ERROR_PENDING errors.
334 	 * A value of count larger than G_MAXSSIZE will cause a G_IO_ERROR_INVALID_ARGUMENT error.
335 	 * On success, the number of bytes skipped will be passed to the callback.
336 	 * It is not an error if this is not the same as the requested size, as it
337 	 * can happen e.g. near the end of a file, but generally we try to skip
338 	 * as many bytes as requested. Zero is returned on end of file
339 	 * (or if count is zero), but never otherwise.
340 	 * Any outstanding i/o request with higher priority (lower numerical value)
341 	 * will be executed before an outstanding request with lower priority.
342 	 * Default priority is G_PRIORITY_DEFAULT.
343 	 * The asynchronous methods have a default fallback that uses threads to
344 	 * implement asynchronicity, so they are optional for inheriting classes.
345 	 * However, if you override one, you must override all.
346 	 * Params:
347 	 * count = the number of bytes that will be skipped from the stream
348 	 * ioPriority = the I/O priority
349 	 * of the request.
350 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
351 	 * callback = callback to call when the request is satisfied. [scope async]
352 	 * userData = the data to pass to callback function. [closure]
353 	 */
354 	public void skipAsync(gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
355 	{
356 		// void g_input_stream_skip_async (GInputStream *stream,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
357 		g_input_stream_skip_async(gInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
358 	}
359 	
360 	/**
361 	 * Finishes a stream skip operation.
362 	 * Params:
363 	 * result = a GAsyncResult.
364 	 * Returns: the size of the bytes skipped, or -1 on error.
365 	 * Throws: GException on failure.
366 	 */
367 	public gssize skipFinish(AsyncResultIF result)
368 	{
369 		// gssize g_input_stream_skip_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
370 		GError* err = null;
371 		
372 		auto p = g_input_stream_skip_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
373 		
374 		if (err !is null)
375 		{
376 			throw new GException( new ErrorG(err) );
377 		}
378 		
379 		return p;
380 	}
381 	
382 	/**
383 	 * Requests an asynchronous closes of the stream, releasing resources related to it.
384 	 * When the operation is finished callback will be called.
385 	 * You can then call g_input_stream_close_finish() to get the result of the
386 	 * operation.
387 	 * For behaviour details see g_input_stream_close().
388 	 * The asyncronous methods have a default fallback that uses threads to implement
389 	 * asynchronicity, so they are optional for inheriting classes. However, if you
390 	 * override one you must override all.
391 	 * Params:
392 	 * ioPriority = the I/O priority
393 	 * of the request.
394 	 * cancellable = optional cancellable object. [allow-none]
395 	 * callback = callback to call when the request is satisfied. [scope async]
396 	 * userData = the data to pass to callback function. [closure]
397 	 */
398 	public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
399 	{
400 		// void g_input_stream_close_async (GInputStream *stream,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
401 		g_input_stream_close_async(gInputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
402 	}
403 	
404 	/**
405 	 * Finishes closing a stream asynchronously, started from g_input_stream_close_async().
406 	 * Params:
407 	 * result = a GAsyncResult.
408 	 * Returns: TRUE if the stream was closed successfully.
409 	 * Throws: GException on failure.
410 	 */
411 	public int closeFinish(AsyncResultIF result)
412 	{
413 		// gboolean g_input_stream_close_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
414 		GError* err = null;
415 		
416 		auto p = g_input_stream_close_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
417 		
418 		if (err !is null)
419 		{
420 			throw new GException( new ErrorG(err) );
421 		}
422 		
423 		return p;
424 	}
425 	
426 	/**
427 	 * Checks if an input stream is closed.
428 	 * Returns: TRUE if the stream is closed.
429 	 */
430 	public int isClosed()
431 	{
432 		// gboolean g_input_stream_is_closed (GInputStream *stream);
433 		return g_input_stream_is_closed(gInputStream);
434 	}
435 	
436 	/**
437 	 * Checks if an input stream has pending actions.
438 	 * Returns: TRUE if stream has pending actions.
439 	 */
440 	public int hasPending()
441 	{
442 		// gboolean g_input_stream_has_pending (GInputStream *stream);
443 		return g_input_stream_has_pending(gInputStream);
444 	}
445 	
446 	/**
447 	 * Sets stream to have actions pending. If the pending flag is
448 	 * already set or stream is closed, it will return FALSE and set
449 	 * error.
450 	 * Returns: TRUE if pending was previously unset and is now set.
451 	 * Throws: GException on failure.
452 	 */
453 	public int setPending()
454 	{
455 		// gboolean g_input_stream_set_pending (GInputStream *stream,  GError **error);
456 		GError* err = null;
457 		
458 		auto p = g_input_stream_set_pending(gInputStream, &err);
459 		
460 		if (err !is null)
461 		{
462 			throw new GException( new ErrorG(err) );
463 		}
464 		
465 		return p;
466 	}
467 	
468 	/**
469 	 * Clears the pending flag on stream.
470 	 */
471 	public void clearPending()
472 	{
473 		// void g_input_stream_clear_pending (GInputStream *stream);
474 		g_input_stream_clear_pending(gInputStream);
475 	}
476 	
477 	/**
478 	 * Like g_input_stream_read(), this tries to read count bytes from
479 	 * the stream in a blocking fashion. However, rather than reading into
480 	 * a user-supplied buffer, this will create a new GBytes containing
481 	 * the data that was read. This may be easier to use from language
482 	 * bindings.
483 	 * If count is zero, returns a zero-length GBytes and does nothing. A
484 	 * value of count larger than G_MAXSSIZE will cause a
485 	 * G_IO_ERROR_INVALID_ARGUMENT error.
486 	 * On success, a new GBytes is returned. It is not an error if the
487 	 * size of this object is not the same as the requested size, as it
488 	 * can happen e.g. near the end of a file. A zero-length GBytes is
489 	 * returned on end of file (or if count is zero), but never
490 	 * otherwise.
491 	 * If cancellable is not NULL, then the operation can be cancelled by
492 	 * triggering the cancellable object from another thread. If the operation
493 	 * was cancelled, the error G_IO_ERROR_CANCELLED will be returned. If an
494 	 * operation was partially finished when the operation was cancelled the
495 	 * partial result will be returned, without an error.
496 	 * On error NULL is returned and error is set accordingly.
497 	 * Params:
498 	 * count = maximum number of bytes that will be read from the stream. Common
499 	 * values include 4096 and 8192.
500 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
501 	 * Returns: a new GBytes, or NULL on error
502 	 * Throws: GException on failure.
503 	 */
504 	public Bytes readBytes(gsize count, Cancellable cancellable)
505 	{
506 		// GBytes * g_input_stream_read_bytes (GInputStream *stream,  gsize count,  GCancellable *cancellable,  GError **error);
507 		GError* err = null;
508 		
509 		auto p = g_input_stream_read_bytes(gInputStream, count, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
510 		
511 		if (err !is null)
512 		{
513 			throw new GException( new ErrorG(err) );
514 		}
515 		
516 		
517 		if(p is null)
518 		{
519 			return null;
520 		}
521 		
522 		return ObjectG.getDObject!(Bytes)(cast(GBytes*) p);
523 	}
524 	
525 	/**
526 	 * Request an asynchronous read of count bytes from the stream into a
527 	 * new GBytes. When the operation is finished callback will be
528 	 * called. You can then call g_input_stream_read_bytes_finish() to get the
529 	 * result of the operation.
530 	 * During an async request no other sync and async calls are allowed
531 	 * on stream, and will result in G_IO_ERROR_PENDING errors.
532 	 * A value of count larger than G_MAXSSIZE will cause a
533 	 * G_IO_ERROR_INVALID_ARGUMENT error.
534 	 * On success, the new GBytes will be passed to the callback. It is
535 	 * not an error if this is smaller than the requested size, as it can
536 	 * happen e.g. near the end of a file, but generally we try to read as
537 	 * many bytes as requested. Zero is returned on end of file (or if
538 	 * count is zero), but never otherwise.
539 	 * Any outstanding I/O request with higher priority (lower numerical
540 	 * value) will be executed before an outstanding request with lower
541 	 * priority. Default priority is G_PRIORITY_DEFAULT.
542 	 * Params:
543 	 * count = the number of bytes that will be read from the stream
544 	 * ioPriority = the I/O priority
545 	 * of the request.
546 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
547 	 * callback = callback to call when the request is satisfied. [scope async]
548 	 * userData = the data to pass to callback function. [closure]
549 	 */
550 	public void readBytesAsync(gsize count, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
551 	{
552 		// void g_input_stream_read_bytes_async (GInputStream *stream,  gsize count,  int io_priority,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
553 		g_input_stream_read_bytes_async(gInputStream, count, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
554 	}
555 	
556 	/**
557 	 * Finishes an asynchronous stream read-into-GBytes operation.
558 	 * Params:
559 	 * result = a GAsyncResult.
560 	 * Returns: the newly-allocated GBytes, or NULL on error
561 	 * Throws: GException on failure.
562 	 */
563 	public Bytes readBytesFinish(AsyncResultIF result)
564 	{
565 		// GBytes * g_input_stream_read_bytes_finish (GInputStream *stream,  GAsyncResult *result,  GError **error);
566 		GError* err = null;
567 		
568 		auto p = g_input_stream_read_bytes_finish(gInputStream, (result is null) ? null : result.getAsyncResultTStruct(), &err);
569 		
570 		if (err !is null)
571 		{
572 			throw new GException( new ErrorG(err) );
573 		}
574 		
575 		
576 		if(p is null)
577 		{
578 			return null;
579 		}
580 		
581 		return ObjectG.getDObject!(Bytes)(cast(GBytes*) p);
582 	}
583 }