From a6dfe20348526572093c005f82a0d8f4e2d72a5c Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Mon, 27 Jun 2011 20:17:27 -0400 Subject: [PATCH] shell-util: Add a helper method for saving files from HTTP Unfortunately, gjs cannot handle binary C strings directly from gobject-introspection. Add a simple workaround method in C to help us save random files from the web. https://bugzilla.gnome.org/show_bug.cgi?id=653989 --- src/shell-util.c | 23 +++++++++++++++++++++++ src/shell-util.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/src/shell-util.c b/src/shell-util.c index 3234faf0e..ef00f44a5 100644 --- a/src/shell-util.c +++ b/src/shell-util.c @@ -560,6 +560,29 @@ shell_get_event_state (ClutterEvent *event) return state & CLUTTER_MODIFIER_MASK; } +/** + * shell_write_soup_message_to_stream: + * @stream: a #GOutputStream + * @message: a #SoupMessage + * @error: location to store GError + * + * Write a string to a GOutputStream as binary data. This is a + * workaround for the lack of proper binary strings in GJS. + */ +void +shell_write_soup_message_to_stream (GOutputStream *stream, + SoupMessage *message, + GError **error) +{ + SoupMessageBody *body; + + body = message->response_body; + + g_output_stream_write_all (stream, + body->data, body->length, + NULL, NULL, error); +} + /** * shell_write_string_to_stream: * @stream: a #GOutputStream diff --git a/src/shell-util.h b/src/shell-util.h index 7887f9e89..1f431ff62 100644 --- a/src/shell-util.h +++ b/src/shell-util.h @@ -5,6 +5,7 @@ #include #include +#include G_BEGIN_DECLS @@ -25,6 +26,10 @@ char *shell_util_format_date (const char *format, ClutterModifierType shell_get_event_state (ClutterEvent *event); +void shell_write_soup_message_to_stream (GOutputStream *stream, + SoupMessage *message, + GError **error); + gboolean shell_write_string_to_stream (GOutputStream *stream, const char *str, GError **error);