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