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 module gio.OutputStream; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.InputStream; 30 private import gio.c.functions; 31 public import gio.c.types; 32 private import glib.Bytes; 33 private import glib.ErrorG; 34 private import glib.GException; 35 private import glib.Str; 36 private import gobject.ObjectG; 37 38 39 /** 40 * #GOutputStream has functions to write to a stream (g_output_stream_write()), 41 * to close a stream (g_output_stream_close()) and to flush pending writes 42 * (g_output_stream_flush()). 43 * 44 * To copy the content of an input stream to an output stream without 45 * manually handling the reads and writes, use g_output_stream_splice(). 46 * 47 * See the documentation for #GIOStream for details of thread safety of 48 * streaming APIs. 49 * 50 * All of these functions have async variants too. 51 */ 52 public class OutputStream : ObjectG 53 { 54 /** the main Gtk struct */ 55 protected GOutputStream* gOutputStream; 56 57 /** Get the main Gtk struct */ 58 public GOutputStream* getOutputStreamStruct(bool transferOwnership = false) 59 { 60 if (transferOwnership) 61 ownedRef = false; 62 return gOutputStream; 63 } 64 65 /** the main Gtk struct as a void* */ 66 protected override void* getStruct() 67 { 68 return cast(void*)gOutputStream; 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GOutputStream* gOutputStream, bool ownedRef = false) 75 { 76 this.gOutputStream = gOutputStream; 77 super(cast(GObject*)gOutputStream, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return g_output_stream_get_type(); 85 } 86 87 /** 88 * Clears the pending flag on @stream. 89 */ 90 public void clearPending() 91 { 92 g_output_stream_clear_pending(gOutputStream); 93 } 94 95 /** 96 * Closes the stream, releasing resources related to it. 97 * 98 * Once the stream is closed, all other operations will return %G_IO_ERROR_CLOSED. 99 * Closing a stream multiple times will not return an error. 100 * 101 * Closing a stream will automatically flush any outstanding buffers in the 102 * stream. 103 * 104 * Streams will be automatically closed when the last reference 105 * is dropped, but you might want to call this function to make sure 106 * resources are released as early as possible. 107 * 108 * Some streams might keep the backing store of the stream (e.g. a file descriptor) 109 * open after the stream is closed. See the documentation for the individual 110 * stream for details. 111 * 112 * On failure the first error that happened will be reported, but the close 113 * operation will finish as much as possible. A stream that failed to 114 * close will still return %G_IO_ERROR_CLOSED for all operations. Still, it 115 * is important to check and report the error to the user, otherwise 116 * there might be a loss of data as all data might not be written. 117 * 118 * If @cancellable is not %NULL, then the operation can be cancelled by 119 * triggering the cancellable object from another thread. If the operation 120 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 121 * Cancelling a close will still leave the stream closed, but there some streams 122 * can use a faster close that doesn't block to e.g. check errors. On 123 * cancellation (as with any error) there is no guarantee that all written 124 * data will reach the target. 125 * 126 * Params: 127 * cancellable = optional cancellable object 128 * 129 * Returns: %TRUE on success, %FALSE on failure 130 * 131 * Throws: GException on failure. 132 */ 133 public bool close(Cancellable cancellable) 134 { 135 GError* err = null; 136 137 auto __p = g_output_stream_close(gOutputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 138 139 if (err !is null) 140 { 141 throw new GException( new ErrorG(err) ); 142 } 143 144 return __p; 145 } 146 147 /** 148 * Requests an asynchronous close of the stream, releasing resources 149 * related to it. When the operation is finished @callback will be 150 * called. You can then call g_output_stream_close_finish() to get 151 * the result of the operation. 152 * 153 * For behaviour details see g_output_stream_close(). 154 * 155 * The asynchronous methods have a default fallback that uses threads 156 * to implement asynchronicity, so they are optional for inheriting 157 * classes. However, if you override one you must override all. 158 * 159 * Params: 160 * ioPriority = the io priority of the request. 161 * cancellable = optional cancellable object 162 * callback = callback to call when the request is satisfied 163 * userData = the data to pass to callback function 164 */ 165 public void closeAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 166 { 167 g_output_stream_close_async(gOutputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 168 } 169 170 /** 171 * Closes an output stream. 172 * 173 * Params: 174 * result = a #GAsyncResult. 175 * 176 * Returns: %TRUE if stream was successfully closed, %FALSE otherwise. 177 * 178 * Throws: GException on failure. 179 */ 180 public bool closeFinish(AsyncResultIF result) 181 { 182 GError* err = null; 183 184 auto __p = g_output_stream_close_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 185 186 if (err !is null) 187 { 188 throw new GException( new ErrorG(err) ); 189 } 190 191 return __p; 192 } 193 194 /** 195 * Forces a write of all user-space buffered data for the given 196 * @stream. Will block during the operation. Closing the stream will 197 * implicitly cause a flush. 198 * 199 * This function is optional for inherited classes. 200 * 201 * If @cancellable is not %NULL, then the operation can be cancelled by 202 * triggering the cancellable object from another thread. If the operation 203 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 204 * 205 * Params: 206 * cancellable = optional cancellable object 207 * 208 * Returns: %TRUE on success, %FALSE on error 209 * 210 * Throws: GException on failure. 211 */ 212 public bool flush(Cancellable cancellable) 213 { 214 GError* err = null; 215 216 auto __p = g_output_stream_flush(gOutputStream, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 217 218 if (err !is null) 219 { 220 throw new GException( new ErrorG(err) ); 221 } 222 223 return __p; 224 } 225 226 /** 227 * Forces an asynchronous write of all user-space buffered data for 228 * the given @stream. 229 * For behaviour details see g_output_stream_flush(). 230 * 231 * When the operation is finished @callback will be 232 * called. You can then call g_output_stream_flush_finish() to get the 233 * result of the operation. 234 * 235 * Params: 236 * ioPriority = the io priority of the request. 237 * cancellable = optional #GCancellable object, %NULL to ignore. 238 * callback = a #GAsyncReadyCallback to call when the request is satisfied 239 * userData = the data to pass to callback function 240 */ 241 public void flushAsync(int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 242 { 243 g_output_stream_flush_async(gOutputStream, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 244 } 245 246 /** 247 * Finishes flushing an output stream. 248 * 249 * Params: 250 * result = a GAsyncResult. 251 * 252 * Returns: %TRUE if flush operation succeeded, %FALSE otherwise. 253 * 254 * Throws: GException on failure. 255 */ 256 public bool flushFinish(AsyncResultIF result) 257 { 258 GError* err = null; 259 260 auto __p = g_output_stream_flush_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 261 262 if (err !is null) 263 { 264 throw new GException( new ErrorG(err) ); 265 } 266 267 return __p; 268 } 269 270 /** 271 * Checks if an output stream has pending actions. 272 * 273 * Returns: %TRUE if @stream has pending actions. 274 */ 275 public bool hasPending() 276 { 277 return g_output_stream_has_pending(gOutputStream) != 0; 278 } 279 280 /** 281 * Checks if an output stream has already been closed. 282 * 283 * Returns: %TRUE if @stream is closed. %FALSE otherwise. 284 */ 285 public bool isClosed() 286 { 287 return g_output_stream_is_closed(gOutputStream) != 0; 288 } 289 290 /** 291 * Checks if an output stream is being closed. This can be 292 * used inside e.g. a flush implementation to see if the 293 * flush (or other i/o operation) is called from within 294 * the closing operation. 295 * 296 * Returns: %TRUE if @stream is being closed. %FALSE otherwise. 297 * 298 * Since: 2.24 299 */ 300 public bool isClosing() 301 { 302 return g_output_stream_is_closing(gOutputStream) != 0; 303 } 304 305 /** 306 * Sets @stream to have actions pending. If the pending flag is 307 * already set or @stream is closed, it will return %FALSE and set 308 * @error. 309 * 310 * Returns: %TRUE if pending was previously unset and is now set. 311 * 312 * Throws: GException on failure. 313 */ 314 public bool setPending() 315 { 316 GError* err = null; 317 318 auto __p = g_output_stream_set_pending(gOutputStream, &err) != 0; 319 320 if (err !is null) 321 { 322 throw new GException( new ErrorG(err) ); 323 } 324 325 return __p; 326 } 327 328 /** 329 * Splices an input stream into an output stream. 330 * 331 * Params: 332 * source = a #GInputStream. 333 * flags = a set of #GOutputStreamSpliceFlags. 334 * cancellable = optional #GCancellable object, %NULL to ignore. 335 * 336 * Returns: a #gssize containing the size of the data spliced, or 337 * -1 if an error occurred. Note that if the number of bytes 338 * spliced is greater than %G_MAXSSIZE, then that will be 339 * returned, and there is no way to determine the actual number 340 * of bytes spliced. 341 * 342 * Throws: GException on failure. 343 */ 344 public ptrdiff_t splice(InputStream source, GOutputStreamSpliceFlags flags, Cancellable cancellable) 345 { 346 GError* err = null; 347 348 auto __p = g_output_stream_splice(gOutputStream, (source is null) ? null : source.getInputStreamStruct(), flags, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 349 350 if (err !is null) 351 { 352 throw new GException( new ErrorG(err) ); 353 } 354 355 return __p; 356 } 357 358 /** 359 * Splices a stream asynchronously. 360 * When the operation is finished @callback will be called. 361 * You can then call g_output_stream_splice_finish() to get the 362 * result of the operation. 363 * 364 * For the synchronous, blocking version of this function, see 365 * g_output_stream_splice(). 366 * 367 * Params: 368 * source = a #GInputStream. 369 * flags = a set of #GOutputStreamSpliceFlags. 370 * ioPriority = the io priority of the request. 371 * cancellable = optional #GCancellable object, %NULL to ignore. 372 * callback = a #GAsyncReadyCallback. 373 * userData = user data passed to @callback. 374 */ 375 public void spliceAsync(InputStream source, GOutputStreamSpliceFlags flags, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 376 { 377 g_output_stream_splice_async(gOutputStream, (source is null) ? null : source.getInputStreamStruct(), flags, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 378 } 379 380 /** 381 * Finishes an asynchronous stream splice operation. 382 * 383 * Params: 384 * result = a #GAsyncResult. 385 * 386 * Returns: a #gssize of the number of bytes spliced. Note that if the 387 * number of bytes spliced is greater than %G_MAXSSIZE, then that 388 * will be returned, and there is no way to determine the actual 389 * number of bytes spliced. 390 * 391 * Throws: GException on failure. 392 */ 393 public ptrdiff_t spliceFinish(AsyncResultIF result) 394 { 395 GError* err = null; 396 397 auto __p = g_output_stream_splice_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &err); 398 399 if (err !is null) 400 { 401 throw new GException( new ErrorG(err) ); 402 } 403 404 return __p; 405 } 406 407 /** 408 * This is a utility function around g_output_stream_write_all(). It 409 * uses g_strdup_vprintf() to turn @format and @args into a string that 410 * is then written to @stream. 411 * 412 * See the documentation of g_output_stream_write_all() about the 413 * behavior of the actual write operation. 414 * 415 * Note that partial writes cannot be properly checked with this 416 * function due to the variable length of the written string, if you 417 * need precise control over partial write failures, you need to 418 * create you own printf()-like wrapper around g_output_stream_write() 419 * or g_output_stream_write_all(). 420 * 421 * Params: 422 * bytesWritten = location to store the number of bytes that was 423 * written to the stream 424 * cancellable = optional #GCancellable object, %NULL to ignore. 425 * error = location to store the error occurring, or %NULL to ignore 426 * format = the format string. See the printf() documentation 427 * args = the parameters to insert into the format string 428 * 429 * Returns: %TRUE on success, %FALSE if there was an error 430 * 431 * Since: 2.40 432 */ 433 public bool vprintf(out size_t bytesWritten, Cancellable cancellable, out ErrorG error, string format, void* args) 434 { 435 GError* outerror = null; 436 437 auto __p = g_output_stream_vprintf(gOutputStream, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &outerror, Str.toStringz(format), args) != 0; 438 439 error = new ErrorG(outerror); 440 441 return __p; 442 } 443 444 /** 445 * Tries to write @count bytes from @buffer into the stream. Will block 446 * during the operation. 447 * 448 * If count is 0, returns 0 and does nothing. A value of @count 449 * larger than %G_MAXSSIZE will cause a %G_IO_ERROR_INVALID_ARGUMENT error. 450 * 451 * On success, the number of bytes written to the stream is returned. 452 * It is not an error if this is not the same as the requested size, as it 453 * can happen e.g. on a partial I/O error, or if there is not enough 454 * storage in the stream. All writes block until at least one byte 455 * is written or an error occurs; 0 is never returned (unless 456 * @count is 0). 457 * 458 * If @cancellable is not %NULL, then the operation can be cancelled by 459 * triggering the cancellable object from another thread. If the operation 460 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an 461 * operation was partially finished when the operation was cancelled the 462 * partial result will be returned, without an error. 463 * 464 * On error -1 is returned and @error is set accordingly. 465 * 466 * Params: 467 * buffer = the buffer containing the data to write. 468 * cancellable = optional cancellable object 469 * 470 * Returns: Number of bytes written, or -1 on error 471 * 472 * Throws: GException on failure. 473 */ 474 public ptrdiff_t write(ubyte[] buffer, Cancellable cancellable) 475 { 476 GError* err = null; 477 478 auto __p = g_output_stream_write(gOutputStream, buffer.ptr, cast(size_t)buffer.length, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 479 480 if (err !is null) 481 { 482 throw new GException( new ErrorG(err) ); 483 } 484 485 return __p; 486 } 487 488 /** 489 * Tries to write @count bytes from @buffer into the stream. Will block 490 * during the operation. 491 * 492 * This function is similar to g_output_stream_write(), except it tries to 493 * write as many bytes as requested, only stopping on an error. 494 * 495 * On a successful write of @count bytes, %TRUE is returned, and @bytes_written 496 * is set to @count. 497 * 498 * If there is an error during the operation %FALSE is returned and @error 499 * is set to indicate the error status. 500 * 501 * As a special exception to the normal conventions for functions that 502 * use #GError, if this function returns %FALSE (and sets @error) then 503 * @bytes_written will be set to the number of bytes that were 504 * successfully written before the error was encountered. This 505 * functionality is only available from C. If you need it from another 506 * language then you must write your own loop around 507 * g_output_stream_write(). 508 * 509 * Params: 510 * buffer = the buffer containing the data to write. 511 * bytesWritten = location to store the number of bytes that was 512 * written to the stream 513 * cancellable = optional #GCancellable object, %NULL to ignore. 514 * 515 * Returns: %TRUE on success, %FALSE if there was an error 516 * 517 * Throws: GException on failure. 518 */ 519 public bool writeAll(ubyte[] buffer, out size_t bytesWritten, Cancellable cancellable) 520 { 521 GError* err = null; 522 523 auto __p = g_output_stream_write_all(gOutputStream, buffer.ptr, cast(size_t)buffer.length, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 524 525 if (err !is null) 526 { 527 throw new GException( new ErrorG(err) ); 528 } 529 530 return __p; 531 } 532 533 /** 534 * Request an asynchronous write of @count bytes from @buffer into 535 * the stream. When the operation is finished @callback will be called. 536 * You can then call g_output_stream_write_all_finish() to get the result of the 537 * operation. 538 * 539 * This is the asynchronous version of g_output_stream_write_all(). 540 * 541 * Call g_output_stream_write_all_finish() to collect the result. 542 * 543 * Any outstanding I/O request with higher priority (lower numerical 544 * value) will be executed before an outstanding request with lower 545 * priority. Default priority is %G_PRIORITY_DEFAULT. 546 * 547 * Note that no copy of @buffer will be made, so it must stay valid 548 * until @callback is called. 549 * 550 * Params: 551 * buffer = the buffer containing the data to write 552 * ioPriority = the io priority of the request 553 * cancellable = optional #GCancellable object, %NULL to ignore 554 * callback = callback to call when the request is satisfied 555 * userData = the data to pass to callback function 556 * 557 * Since: 2.44 558 */ 559 public void writeAllAsync(ubyte[] buffer, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 560 { 561 g_output_stream_write_all_async(gOutputStream, buffer.ptr, cast(size_t)buffer.length, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 562 } 563 564 /** 565 * Finishes an asynchronous stream write operation started with 566 * g_output_stream_write_all_async(). 567 * 568 * As a special exception to the normal conventions for functions that 569 * use #GError, if this function returns %FALSE (and sets @error) then 570 * @bytes_written will be set to the number of bytes that were 571 * successfully written before the error was encountered. This 572 * functionality is only available from C. If you need it from another 573 * language then you must write your own loop around 574 * g_output_stream_write_async(). 575 * 576 * Params: 577 * result = a #GAsyncResult 578 * bytesWritten = location to store the number of bytes that was written to the stream 579 * 580 * Returns: %TRUE on success, %FALSE if there was an error 581 * 582 * Since: 2.44 583 * 584 * Throws: GException on failure. 585 */ 586 public bool writeAllFinish(AsyncResultIF result, out size_t bytesWritten) 587 { 588 GError* err = null; 589 590 auto __p = g_output_stream_write_all_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &bytesWritten, &err) != 0; 591 592 if (err !is null) 593 { 594 throw new GException( new ErrorG(err) ); 595 } 596 597 return __p; 598 } 599 600 /** 601 * Request an asynchronous write of @count bytes from @buffer into 602 * the stream. When the operation is finished @callback will be called. 603 * You can then call g_output_stream_write_finish() to get the result of the 604 * operation. 605 * 606 * During an async request no other sync and async calls are allowed, 607 * and will result in %G_IO_ERROR_PENDING errors. 608 * 609 * A value of @count larger than %G_MAXSSIZE will cause a 610 * %G_IO_ERROR_INVALID_ARGUMENT error. 611 * 612 * On success, the number of bytes written will be passed to the 613 * @callback. It is not an error if this is not the same as the 614 * requested size, as it can happen e.g. on a partial I/O error, 615 * but generally we try to write as many bytes as requested. 616 * 617 * You are guaranteed that this method will never fail with 618 * %G_IO_ERROR_WOULD_BLOCK - if @stream can't accept more data, the 619 * method will just wait until this changes. 620 * 621 * Any outstanding I/O request with higher priority (lower numerical 622 * value) will be executed before an outstanding request with lower 623 * priority. Default priority is %G_PRIORITY_DEFAULT. 624 * 625 * The asynchronous methods have a default fallback that uses threads 626 * to implement asynchronicity, so they are optional for inheriting 627 * classes. However, if you override one you must override all. 628 * 629 * For the synchronous, blocking version of this function, see 630 * g_output_stream_write(). 631 * 632 * Note that no copy of @buffer will be made, so it must stay valid 633 * until @callback is called. See g_output_stream_write_bytes_async() 634 * for a #GBytes version that will automatically hold a reference to 635 * the contents (without copying) for the duration of the call. 636 * 637 * Params: 638 * buffer = the buffer containing the data to write. 639 * ioPriority = the io priority of the request. 640 * cancellable = optional #GCancellable object, %NULL to ignore. 641 * callback = callback to call when the request is satisfied 642 * userData = the data to pass to callback function 643 */ 644 public void writeAsync(ubyte[] buffer, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 645 { 646 g_output_stream_write_async(gOutputStream, buffer.ptr, cast(size_t)buffer.length, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 647 } 648 649 /** 650 * A wrapper function for g_output_stream_write() which takes a 651 * #GBytes as input. This can be more convenient for use by language 652 * bindings or in other cases where the refcounted nature of #GBytes 653 * is helpful over a bare pointer interface. 654 * 655 * However, note that this function may still perform partial writes, 656 * just like g_output_stream_write(). If that occurs, to continue 657 * writing, you will need to create a new #GBytes containing just the 658 * remaining bytes, using g_bytes_new_from_bytes(). Passing the same 659 * #GBytes instance multiple times potentially can result in duplicated 660 * data in the output stream. 661 * 662 * Params: 663 * bytes = the #GBytes to write 664 * cancellable = optional cancellable object 665 * 666 * Returns: Number of bytes written, or -1 on error 667 * 668 * Throws: GException on failure. 669 */ 670 public ptrdiff_t writeBytes(Bytes bytes, Cancellable cancellable) 671 { 672 GError* err = null; 673 674 auto __p = g_output_stream_write_bytes(gOutputStream, (bytes is null) ? null : bytes.getBytesStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 675 676 if (err !is null) 677 { 678 throw new GException( new ErrorG(err) ); 679 } 680 681 return __p; 682 } 683 684 /** 685 * This function is similar to g_output_stream_write_async(), but 686 * takes a #GBytes as input. Due to the refcounted nature of #GBytes, 687 * this allows the stream to avoid taking a copy of the data. 688 * 689 * However, note that this function may still perform partial writes, 690 * just like g_output_stream_write_async(). If that occurs, to continue 691 * writing, you will need to create a new #GBytes containing just the 692 * remaining bytes, using g_bytes_new_from_bytes(). Passing the same 693 * #GBytes instance multiple times potentially can result in duplicated 694 * data in the output stream. 695 * 696 * For the synchronous, blocking version of this function, see 697 * g_output_stream_write_bytes(). 698 * 699 * Params: 700 * bytes = The bytes to write 701 * ioPriority = the io priority of the request. 702 * cancellable = optional #GCancellable object, %NULL to ignore. 703 * callback = callback to call when the request is satisfied 704 * userData = the data to pass to callback function 705 */ 706 public void writeBytesAsync(Bytes bytes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 707 { 708 g_output_stream_write_bytes_async(gOutputStream, (bytes is null) ? null : bytes.getBytesStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 709 } 710 711 /** 712 * Finishes a stream write-from-#GBytes operation. 713 * 714 * Params: 715 * result = a #GAsyncResult. 716 * 717 * Returns: a #gssize containing the number of bytes written to the stream. 718 * 719 * Throws: GException on failure. 720 */ 721 public ptrdiff_t writeBytesFinish(AsyncResultIF result) 722 { 723 GError* err = null; 724 725 auto __p = g_output_stream_write_bytes_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &err); 726 727 if (err !is null) 728 { 729 throw new GException( new ErrorG(err) ); 730 } 731 732 return __p; 733 } 734 735 /** 736 * Finishes a stream write operation. 737 * 738 * Params: 739 * result = a #GAsyncResult. 740 * 741 * Returns: a #gssize containing the number of bytes written to the stream. 742 * 743 * Throws: GException on failure. 744 */ 745 public ptrdiff_t writeFinish(AsyncResultIF result) 746 { 747 GError* err = null; 748 749 auto __p = g_output_stream_write_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &err); 750 751 if (err !is null) 752 { 753 throw new GException( new ErrorG(err) ); 754 } 755 756 return __p; 757 } 758 759 /** 760 * Tries to write the bytes contained in the @n_vectors @vectors into the 761 * stream. Will block during the operation. 762 * 763 * If @n_vectors is 0 or the sum of all bytes in @vectors is 0, returns 0 and 764 * does nothing. 765 * 766 * On success, the number of bytes written to the stream is returned. 767 * It is not an error if this is not the same as the requested size, as it 768 * can happen e.g. on a partial I/O error, or if there is not enough 769 * storage in the stream. All writes block until at least one byte 770 * is written or an error occurs; 0 is never returned (unless 771 * @n_vectors is 0 or the sum of all bytes in @vectors is 0). 772 * 773 * If @cancellable is not %NULL, then the operation can be cancelled by 774 * triggering the cancellable object from another thread. If the operation 775 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an 776 * operation was partially finished when the operation was cancelled the 777 * partial result will be returned, without an error. 778 * 779 * Some implementations of g_output_stream_writev() may have limitations on the 780 * aggregate buffer size, and will return %G_IO_ERROR_INVALID_ARGUMENT if these 781 * are exceeded. For example, when writing to a local file on UNIX platforms, 782 * the aggregate buffer size must not exceed %G_MAXSSIZE bytes. 783 * 784 * Params: 785 * vectors = the buffer containing the #GOutputVectors to write. 786 * bytesWritten = location to store the number of bytes that were 787 * written to the stream 788 * cancellable = optional cancellable object 789 * 790 * Returns: %TRUE on success, %FALSE if there was an error 791 * 792 * Since: 2.60 793 * 794 * Throws: GException on failure. 795 */ 796 public bool writev(GOutputVector[] vectors, out size_t bytesWritten, Cancellable cancellable) 797 { 798 GError* err = null; 799 800 auto __p = g_output_stream_writev(gOutputStream, vectors.ptr, cast(size_t)vectors.length, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 801 802 if (err !is null) 803 { 804 throw new GException( new ErrorG(err) ); 805 } 806 807 return __p; 808 } 809 810 /** 811 * Tries to write the bytes contained in the @n_vectors @vectors into the 812 * stream. Will block during the operation. 813 * 814 * This function is similar to g_output_stream_writev(), except it tries to 815 * write as many bytes as requested, only stopping on an error. 816 * 817 * On a successful write of all @n_vectors vectors, %TRUE is returned, and 818 * @bytes_written is set to the sum of all the sizes of @vectors. 819 * 820 * If there is an error during the operation %FALSE is returned and @error 821 * is set to indicate the error status. 822 * 823 * As a special exception to the normal conventions for functions that 824 * use #GError, if this function returns %FALSE (and sets @error) then 825 * @bytes_written will be set to the number of bytes that were 826 * successfully written before the error was encountered. This 827 * functionality is only available from C. If you need it from another 828 * language then you must write your own loop around 829 * g_output_stream_write(). 830 * 831 * The content of the individual elements of @vectors might be changed by this 832 * function. 833 * 834 * Params: 835 * vectors = the buffer containing the #GOutputVectors to write. 836 * bytesWritten = location to store the number of bytes that were 837 * written to the stream 838 * cancellable = optional #GCancellable object, %NULL to ignore. 839 * 840 * Returns: %TRUE on success, %FALSE if there was an error 841 * 842 * Since: 2.60 843 * 844 * Throws: GException on failure. 845 */ 846 public bool writevAll(GOutputVector[] vectors, out size_t bytesWritten, Cancellable cancellable) 847 { 848 GError* err = null; 849 850 auto __p = g_output_stream_writev_all(gOutputStream, vectors.ptr, cast(size_t)vectors.length, &bytesWritten, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 851 852 if (err !is null) 853 { 854 throw new GException( new ErrorG(err) ); 855 } 856 857 return __p; 858 } 859 860 /** 861 * Request an asynchronous write of the bytes contained in the @n_vectors @vectors into 862 * the stream. When the operation is finished @callback will be called. 863 * You can then call g_output_stream_writev_all_finish() to get the result of the 864 * operation. 865 * 866 * This is the asynchronous version of g_output_stream_writev_all(). 867 * 868 * Call g_output_stream_writev_all_finish() to collect the result. 869 * 870 * Any outstanding I/O request with higher priority (lower numerical 871 * value) will be executed before an outstanding request with lower 872 * priority. Default priority is %G_PRIORITY_DEFAULT. 873 * 874 * Note that no copy of @vectors will be made, so it must stay valid 875 * until @callback is called. The content of the individual elements 876 * of @vectors might be changed by this function. 877 * 878 * Params: 879 * vectors = the buffer containing the #GOutputVectors to write. 880 * ioPriority = the I/O priority of the request 881 * cancellable = optional #GCancellable object, %NULL to ignore 882 * callback = callback to call when the request is satisfied 883 * userData = the data to pass to callback function 884 * 885 * Since: 2.60 886 */ 887 public void writevAllAsync(GOutputVector[] vectors, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 888 { 889 g_output_stream_writev_all_async(gOutputStream, vectors.ptr, cast(size_t)vectors.length, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 890 } 891 892 /** 893 * Finishes an asynchronous stream write operation started with 894 * g_output_stream_writev_all_async(). 895 * 896 * As a special exception to the normal conventions for functions that 897 * use #GError, if this function returns %FALSE (and sets @error) then 898 * @bytes_written will be set to the number of bytes that were 899 * successfully written before the error was encountered. This 900 * functionality is only available from C. If you need it from another 901 * language then you must write your own loop around 902 * g_output_stream_writev_async(). 903 * 904 * Params: 905 * result = a #GAsyncResult 906 * bytesWritten = location to store the number of bytes that were written to the stream 907 * 908 * Returns: %TRUE on success, %FALSE if there was an error 909 * 910 * Since: 2.60 911 * 912 * Throws: GException on failure. 913 */ 914 public bool writevAllFinish(AsyncResultIF result, out size_t bytesWritten) 915 { 916 GError* err = null; 917 918 auto __p = g_output_stream_writev_all_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &bytesWritten, &err) != 0; 919 920 if (err !is null) 921 { 922 throw new GException( new ErrorG(err) ); 923 } 924 925 return __p; 926 } 927 928 /** 929 * Request an asynchronous write of the bytes contained in @n_vectors @vectors into 930 * the stream. When the operation is finished @callback will be called. 931 * You can then call g_output_stream_writev_finish() to get the result of the 932 * operation. 933 * 934 * During an async request no other sync and async calls are allowed, 935 * and will result in %G_IO_ERROR_PENDING errors. 936 * 937 * On success, the number of bytes written will be passed to the 938 * @callback. It is not an error if this is not the same as the 939 * requested size, as it can happen e.g. on a partial I/O error, 940 * but generally we try to write as many bytes as requested. 941 * 942 * You are guaranteed that this method will never fail with 943 * %G_IO_ERROR_WOULD_BLOCK — if @stream can't accept more data, the 944 * method will just wait until this changes. 945 * 946 * Any outstanding I/O request with higher priority (lower numerical 947 * value) will be executed before an outstanding request with lower 948 * priority. Default priority is %G_PRIORITY_DEFAULT. 949 * 950 * The asynchronous methods have a default fallback that uses threads 951 * to implement asynchronicity, so they are optional for inheriting 952 * classes. However, if you override one you must override all. 953 * 954 * For the synchronous, blocking version of this function, see 955 * g_output_stream_writev(). 956 * 957 * Note that no copy of @vectors will be made, so it must stay valid 958 * until @callback is called. 959 * 960 * Params: 961 * vectors = the buffer containing the #GOutputVectors to write. 962 * ioPriority = the I/O priority of the request. 963 * cancellable = optional #GCancellable object, %NULL to ignore. 964 * callback = callback to call when the request is satisfied 965 * userData = the data to pass to callback function 966 * 967 * Since: 2.60 968 */ 969 public void writevAsync(GOutputVector[] vectors, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 970 { 971 g_output_stream_writev_async(gOutputStream, vectors.ptr, cast(size_t)vectors.length, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 972 } 973 974 /** 975 * Finishes a stream writev operation. 976 * 977 * Params: 978 * result = a #GAsyncResult. 979 * bytesWritten = location to store the number of bytes that were written to the stream 980 * 981 * Returns: %TRUE on success, %FALSE if there was an error 982 * 983 * Since: 2.60 984 * 985 * Throws: GException on failure. 986 */ 987 public bool writevFinish(AsyncResultIF result, out size_t bytesWritten) 988 { 989 GError* err = null; 990 991 auto __p = g_output_stream_writev_finish(gOutputStream, (result is null) ? null : result.getAsyncResultStruct(), &bytesWritten, &err) != 0; 992 993 if (err !is null) 994 { 995 throw new GException( new ErrorG(err) ); 996 } 997 998 return __p; 999 } 1000 }