soup-message-body: Add a soup_buffer_get_as_bytes method
authorJasper St. Pierre <jstpierre@mecheye.net>
Thu, 24 May 2012 19:05:10 +0000 (15:05 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Thu, 24 May 2012 21:48:22 +0000 (17:48 -0400)
This new method will return a GBytes instance containing the
contents of the SoupBuffer.

https://bugzilla.gnome.org/show_bug.cgi?id=676776

docs/reference/libsoup-2.4-sections.txt
libsoup/soup-message-body.c
libsoup/soup-message-body.h

index 8731edd..87633c7 100644 (file)
@@ -159,6 +159,7 @@ soup_buffer_get_owner
 soup_buffer_get_data
 soup_buffer_copy
 soup_buffer_free
+soup_buffer_get_as_bytes
 <SUBSECTION>
 SoupMessageBody
 soup_message_body_new
index daf9d1e..899c04a 100644 (file)
@@ -308,6 +308,24 @@ soup_buffer_free (SoupBuffer *buffer)
        }
 }
 
+/**
+ * soup_buffer_get_as_bytes:
+ * @buffer: a #SoupBuffer
+ *
+ * Returns: (transfer full): a new #GBytes which has the same content
+ * as the #SoupBuffer.
+ *
+ * Since: 2.40
+ */
+GBytes *
+soup_buffer_get_as_bytes (SoupBuffer *buffer)
+{
+       SoupBuffer *copy;
+
+       copy = soup_buffer_copy (buffer);
+       return g_bytes_new_with_free_func (copy->data, copy->length, soup_buffer_free, copy);
+}
+
 GType
 soup_buffer_get_type (void)
 {
index 4edaaf0..ee84083 100644 (file)
@@ -44,6 +44,7 @@ void        soup_buffer_get_data       (SoupBuffer     *buffer,
                                        gsize          *length);
 SoupBuffer *soup_buffer_copy           (SoupBuffer     *buffer);
 void        soup_buffer_free           (SoupBuffer     *buffer);
+GBytes     *soup_buffer_get_as_bytes   (SoupBuffer *buffer);
 
 typedef struct {
        const char *data;