Class: Gio::MemoryOutputStream

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#dataGObject

Pointer to buffer where data will be written.

Returns:

  • (GObject)

    data

#data=(data) ⇒ GObject

Pointer to buffer where data will be written.

Parameters:

  • data (GObject)

Returns:

  • (GObject)

    data

  • (GObject)

    data

#data_sizeGio::gulong

Size of data written to the buffer.

Returns:

  • (Gio::gulong)

    data-size

#data_size=(data_size) ⇒ Gio::gulong

Size of data written to the buffer.

Parameters:

  • data_size (Gio::gulong)

Returns:

  • (Gio::gulong)

    data-size

  • (Gio::gulong)

    data-size

#destroy_functionGObject

Function called with the buffer as argument when the stream is destroyed.

Returns:

  • (GObject)

    destroy-function

#destroy_function=(destroy_function) ⇒ GObject

Function called with the buffer as argument when the stream is destroyed.

Parameters:

  • destroy_function (GObject)

Returns:

  • (GObject)

    destroy-function

  • (GObject)

    destroy-function

#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);

Parameters:

  • data (GObject)

    pointer to a chunk of memory to use, or nil

  • size (Integer)

    the size of data

  • realloc_function (Gio::ReallocFunc)

    a function with realloc() semantics (like g_realloc()) to be called when data needs to be grown, or nil

  • destroy_function (GLib::DestroyNotify)

    a function to be called on data when the stream is finalized, or nil

Returns:

#new_resizableGio::OutputStream

Creates a new GMemory::OutputStream, using g_realloc() and g_free() for memory allocation.

Returns:

#realloc_functionGObject

Function with realloc semantics called to enlarge the buffer.

Returns:

  • (GObject)

    realloc-function

#realloc_function=(realloc_function) ⇒ GObject

Function with realloc semantics called to enlarge the buffer.

Parameters:

  • realloc_function (GObject)

Returns:

  • (GObject)

    realloc-function

  • (GObject)

    realloc-function

#sizeGio::gulong

Current size of the data buffer.

Returns:

  • (Gio::gulong)

    size

#size=(size) ⇒ Gio::gulong

Current size of the data buffer.

Parameters:

  • size (Gio::gulong)

Returns:

  • (Gio::gulong)

    size

  • (Gio::gulong)

    size

#steal_as_bytesGLib::Bytes

Returns data from the ostream as a #GBytes. ostream must be closed before calling this function.

Returns:

  • (GLib::Bytes)

    the stream’s data

#steal_dataGObject

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.

Returns:

  • (GObject)

    the stream’s data, or nil if it has previously been stolen