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.SeekableT; 26 27 public import gio.Cancellable; 28 public import gio.c.functions; 29 public import gio.c.types; 30 public import glib.ErrorG; 31 public import glib.GException; 32 public import gtkc.giotypes; 33 34 35 /** 36 * #GSeekable is implemented by streams (implementations of 37 * #GInputStream or #GOutputStream) that support seeking. 38 * 39 * Seekable streams largely fall into two categories: resizable and 40 * fixed-size. 41 * 42 * #GSeekable on fixed-sized streams is approximately the same as POSIX 43 * lseek() on a block device (for example: attmepting to seek past the 44 * end of the device is an error). Fixed streams typically cannot be 45 * truncated. 46 * 47 * #GSeekable on resizable streams is approximately the same as POSIX 48 * lseek() on a normal file. Seeking past the end and writing data will 49 * usually cause the stream to resize by introducing zero bytes. 50 */ 51 public template SeekableT(TStruct) 52 { 53 /** Get the main Gtk struct */ 54 public GSeekable* getSeekableStruct(bool transferOwnership = false) 55 { 56 if (transferOwnership) 57 ownedRef = false; 58 return cast(GSeekable*)getStruct(); 59 } 60 61 62 /** 63 * Tests if the stream supports the #GSeekableIface. 64 * 65 * Returns: %TRUE if @seekable can be seeked. %FALSE otherwise. 66 */ 67 public bool canSeek() 68 { 69 return g_seekable_can_seek(getSeekableStruct()) != 0; 70 } 71 72 /** 73 * Tests if the length of the stream can be adjusted with 74 * g_seekable_truncate(). 75 * 76 * Returns: %TRUE if the stream can be truncated, %FALSE otherwise. 77 */ 78 public bool canTruncate() 79 { 80 return g_seekable_can_truncate(getSeekableStruct()) != 0; 81 } 82 83 /** 84 * Seeks in the stream by the given @offset, modified by @type. 85 * 86 * Attempting to seek past the end of the stream will have different 87 * results depending on if the stream is fixed-sized or resizable. If 88 * the stream is resizable then seeking past the end and then writing 89 * will result in zeros filling the empty space. Seeking past the end 90 * of a resizable stream and reading will result in EOF. Seeking past 91 * the end of a fixed-sized stream will fail. 92 * 93 * Any operation that would result in a negative offset will fail. 94 * 95 * If @cancellable is not %NULL, then the operation can be cancelled by 96 * triggering the cancellable object from another thread. If the operation 97 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 98 * 99 * Params: 100 * offset = a #goffset. 101 * type = a #GSeekType. 102 * cancellable = optional #GCancellable object, %NULL to ignore. 103 * 104 * Returns: %TRUE if successful. If an error 105 * has occurred, this function will return %FALSE and set @error 106 * appropriately if present. 107 * 108 * Throws: GException on failure. 109 */ 110 public bool seek(long offset, GSeekType type, Cancellable cancellable) 111 { 112 GError* err = null; 113 114 auto p = g_seekable_seek(getSeekableStruct(), offset, type, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 115 116 if (err !is null) 117 { 118 throw new GException( new ErrorG(err) ); 119 } 120 121 return p; 122 } 123 124 /** 125 * Tells the current position within the stream. 126 * 127 * Returns: the offset from the beginning of the buffer. 128 */ 129 public long tell() 130 { 131 return g_seekable_tell(getSeekableStruct()); 132 } 133 134 /** 135 * Sets the length of the stream to @offset. If the stream was previously 136 * larger than @offset, the extra data is discarded. If the stream was 137 * previouly shorter than @offset, it is extended with NUL ('\0') bytes. 138 * 139 * If @cancellable is not %NULL, then the operation can be cancelled by 140 * triggering the cancellable object from another thread. If the operation 141 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. If an 142 * operation was partially finished when the operation was cancelled the 143 * partial result will be returned, without an error. 144 * 145 * Params: 146 * offset = new length for @seekable, in bytes. 147 * cancellable = optional #GCancellable object, %NULL to ignore. 148 * 149 * Returns: %TRUE if successful. If an error 150 * has occurred, this function will return %FALSE and set @error 151 * appropriately if present. 152 * 153 * Throws: GException on failure. 154 */ 155 public bool truncate(long offset, Cancellable cancellable) 156 { 157 GError* err = null; 158 159 auto p = g_seekable_truncate(getSeekableStruct(), offset, (cancellable is null) ? null : cancellable.getCancellableStruct(), &err) != 0; 160 161 if (err !is null) 162 { 163 throw new GException( new ErrorG(err) ); 164 } 165 166 return p; 167 } 168 }