Class: Gio::MemoryOutputStream
- Inherits:
-
Object
- Object
- Gio::MemoryOutputStream
- Defined in:
- (unknown)
Instance Method Summary collapse
-
#data ⇒ GObject
Pointer to buffer where data will be written.
-
#data=(data) ⇒ GObject
Pointer to buffer where data will be written.
-
#data_size ⇒ Gio::gulong
Size of data written to the buffer.
-
#data_size=(data_size) ⇒ Gio::gulong
Size of data written to the buffer.
-
#destroy_function ⇒ GObject
Function called with the buffer as argument when the stream is destroyed.
-
#destroy_function=(destroy_function) ⇒ GObject
Function called with the buffer as argument when the stream is destroyed.
-
#new(data, size, realloc_function, destroy_function) ⇒ Gio::OutputStream
Creates a new GMemory::OutputStream.
-
#new_resizable ⇒ Gio::OutputStream
Creates a new GMemory::OutputStream, using g_realloc() and g_free() for memory allocation.
-
#realloc_function ⇒ GObject
Function with realloc semantics called to enlarge the buffer.
-
#realloc_function=(realloc_function) ⇒ GObject
Function with realloc semantics called to enlarge the buffer.
-
#size ⇒ Gio::gulong
Current size of the data buffer.
-
#size=(size) ⇒ Gio::gulong
Current size of the data buffer.
-
#steal_as_bytes ⇒ GLib::Bytes
Returns data from the ostream as a #GBytes.
-
#steal_data ⇒ GObject
Gets any loaded data from the ostream.
Instance Method Details
#data ⇒ GObject
Pointer to buffer where data will be written.
#data=(data) ⇒ GObject
Pointer to buffer where data will be written.
#data_size ⇒ Gio::gulong
Size of data written to the buffer.
#data_size=(data_size) ⇒ Gio::gulong
Size of data written to the buffer.
#destroy_function ⇒ GObject
Function called with the buffer as argument when the stream is destroyed.
#destroy_function=(destroy_function) ⇒ GObject
Function called with the buffer as argument when the stream is destroyed.
#new(data, size, realloc_function, destroy_function) ⇒ Gio::OutputStream
Creates a new GMemory::OutputStream.
In most cases this is not the function you want. See g_memory_output_stream_new_resizable() instead.
If data is non-nil, the stream will use that for its internal storage.
If realloc_fn is non-nil, it will be used for resizing the internal storage when necessary and the stream will be considered resizable. In that case, the stream will start out being (conceptually) empty. size is used only as a hint for how big data is. Specifically, seeking to the end of a newly-created stream will seek to zero, not size. Seeking past the end of the stream and then writing will introduce a zero-filled gap.
If realloc_fn is nil then the stream is fixed-sized. Seeking to the end will seek to size exactly. Writing past the end will give an ‘out of space’ error. Attempting to seek past the end will fail. Unlike the resizable case, seeking to an offset within the stream and writing will preserve the bytes passed in as data before that point and will return them as part of g_memory_output_stream_steal_data(). If you intend to seek you should probably therefore ensure that data is properly initialised.
It is probably only meaningful to provide data and size in the case that you want a fixed-sized stream. Put another way: if realloc_fn is non-nil then it makes most sense to give data as nil and size as 0 (allowing GMemory::OutputStream to do the initial allocation for itself).
// a stream that can grow
stream = g_memory_output_stream_new (NULL, 0, realloc, free);
// another stream that can grow
stream2 = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
// a fixed-size stream
data = malloc (200);
stream3 = g_memory_output_stream_new (data, 200, NULL, free);
#new_resizable ⇒ Gio::OutputStream
Creates a new GMemory::OutputStream, using g_realloc() and g_free() for memory allocation.
#realloc_function ⇒ GObject
Function with realloc semantics called to enlarge the buffer.
#realloc_function=(realloc_function) ⇒ GObject
Function with realloc semantics called to enlarge the buffer.
#size ⇒ Gio::gulong
Current size of the data buffer.
#size=(size) ⇒ Gio::gulong
Current size of the data buffer.
#steal_as_bytes ⇒ GLib::Bytes
Returns data from the ostream as a #GBytes. ostream must be closed before calling this function.
#steal_data ⇒ GObject
Gets any loaded data from the ostream. Ownership of the data is transferred to the caller; when no longer needed it must be freed using the free function set in ostream’s GMemory::OutputStream:destroy-function property.
ostream must be closed before calling this function.