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