-
- if (data == NULL)
- stream = g_object_new (G_TYPE_MEMORY_OUTPUT_STREAM, NULL);
- else
- stream = g_object_new (G_TYPE_MEMORY_OUTPUT_STREAM,
- "data", data,
- NULL);
-
- return stream;
-}
-
-/**
- * g_memory_output_stream_set_free_data:
- * @ostream: a #GMemoryOutputStream.
- * @free_data: a #gboolean. If %TRUE, frees the data within @stream.
- *
- * Sets if the data within the @stream should be freed when the stream
- * is freed.
- **/
-void
-g_memory_output_stream_set_free_data (GMemoryOutputStream *ostream,
- gboolean free_data)
-{
- GMemoryOutputStreamPrivate *priv;
-
- g_return_if_fail (G_IS_MEMORY_OUTPUT_STREAM (ostream));
-
- priv = ostream->priv;
-
- priv->free_data = free_data;
-}
-
-/**
- * g_memory_output_stream_set_max_size:
- * @ostream: a #GMemoryOutputStream.
- * @max_size: a #guint to set as the maximum stream size.
- *
- * Sets a size limit on the data contained within the output stream.
- **/
-void
-g_memory_output_stream_set_max_size (GMemoryOutputStream *ostream,
- guint max_size)
-{
- GMemoryOutputStreamPrivate *priv;
-
- g_return_if_fail (G_IS_MEMORY_OUTPUT_STREAM (ostream));
-
- priv = ostream->priv;
-
- priv->max_size = max_size;
-
- if (priv->max_size > 0 &&
- priv->max_size < priv->data->len)
- {
-
- g_byte_array_set_size (priv->data, priv->max_size);
-
- if (priv->pos > priv->max_size)
- priv->pos = priv->max_size;
- }
-
- g_object_notify (G_OBJECT (ostream), "size-limit");
-}
-
-static void
-g_memory_output_stream_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GMemoryOutputStream *ostream;
- GMemoryOutputStreamPrivate *priv;
- GByteArray *data;
- guint max_size;
-
- ostream = G_MEMORY_OUTPUT_STREAM (object);
- priv = ostream->priv;
-
- switch (prop_id)
- {
- case PROP_DATA:
-
- if (priv->data && priv->free_data)
- g_byte_array_free (priv->data, TRUE);
-
- data = g_value_get_pointer (value);
-
- if (data == NULL)
- {
- data = g_byte_array_new ();
- priv->free_data = TRUE;
- }
- else
- priv->free_data = FALSE;
-
- priv->data = data;
- priv->pos = 0;
- g_object_notify (G_OBJECT (ostream), "data");
- break;
-
- case PROP_FREE_ARRAY:
- priv->free_data = g_value_get_boolean (value);
- break;
-
- case PROP_SIZE_LIMIT:
- max_size = g_value_get_uint (value);
- g_memory_output_stream_set_max_size (ostream, max_size);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-g_memory_output_stream_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GMemoryOutputStream *ostream;