[rhythmbox/wip/python3: 25/35] chunk-loader: provide chunks as GBytes instances rather than GStrings



commit 96d95608487c7da9d029459a101846b4441b0720
Author: Jonathan Matthew <jonathan d14n org>
Date:   Wed Apr 17 08:39:06 2013 +1000

    chunk-loader: provide chunks as GBytes instances rather than GStrings
    
    We don't want chunks to be interpreted as utf8 strings in python.

 lib/rb-chunk-loader.c                | 13 +++++++------
 lib/rb-chunk-loader.h                |  2 +-
 plugins/magnatune/MagnatuneSource.py |  6 +++---
 3 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/lib/rb-chunk-loader.c b/lib/rb-chunk-loader.c
index 6b8354d..cf7d5e3 100644
--- a/lib/rb-chunk-loader.c
+++ b/lib/rb-chunk-loader.c
@@ -46,7 +46,6 @@ struct _RBChunkLoaderPrivate
        char *uri;
        gssize chunk_size;
        guint8 *chunk;
-       GString chunk_string;
        guint64 total;
 
        GError *error;
@@ -107,8 +106,13 @@ stream_read_async_cb (GObject *obj, GAsyncResult *res, gpointer data)
                loader->priv->callback (loader, NULL, 0, loader->priv->callback_data);
                cleanup (loader);
        } else {
-               loader->priv->chunk_string.len = done;
-               loader->priv->callback (loader, &loader->priv->chunk_string, loader->priv->total, 
loader->priv->callback_data);
+               GBytes *bytes;
+
+               bytes = g_bytes_new_take (loader->priv->chunk, done);
+               loader->priv->callback (loader, bytes, loader->priv->total, loader->priv->callback_data);
+               g_bytes_unref (bytes);
+
+               loader->priv->chunk = g_malloc0 (loader->priv->chunk_size+1);
                g_input_stream_read_async (G_INPUT_STREAM (loader->priv->stream),
                                           loader->priv->chunk,
                                           loader->priv->chunk_size,
@@ -185,9 +189,6 @@ rb_chunk_loader_start (RBChunkLoader *loader, const char *uri, gssize chunk_size
        loader->priv->uri = g_strdup (uri);
        loader->priv->chunk_size = chunk_size;
        loader->priv->chunk = g_malloc0 (chunk_size+1);
-       loader->priv->chunk_string.str = (gchar *)loader->priv->chunk;
-       loader->priv->chunk_string.len = 0;
-       loader->priv->chunk_string.allocated_len = chunk_size;
 
        loader->priv->cancel = g_cancellable_new ();
 
diff --git a/lib/rb-chunk-loader.h b/lib/rb-chunk-loader.h
index 2d3588a..e2e6026 100644
--- a/lib/rb-chunk-loader.h
+++ b/lib/rb-chunk-loader.h
@@ -43,7 +43,7 @@ typedef struct _RBChunkLoader RBChunkLoader;
 typedef struct _RBChunkLoaderClass RBChunkLoaderClass;
 typedef struct _RBChunkLoaderPrivate RBChunkLoaderPrivate;
 
-typedef void (*RBChunkLoaderCallback) (RBChunkLoader *loader, GString *data, goffset total, gpointer 
user_data);
+typedef void (*RBChunkLoaderCallback) (RBChunkLoader *loader, GBytes *data, goffset total, gpointer 
user_data);
 
 struct _RBChunkLoader
 {
diff --git a/plugins/magnatune/MagnatuneSource.py b/plugins/magnatune/MagnatuneSource.py
index 5a8f79a..3854c7e 100644
--- a/plugins/magnatune/MagnatuneSource.py
+++ b/plugins/magnatune/MagnatuneSource.py
@@ -306,8 +306,8 @@ class MagnatuneSource(RB.BrowserSource):
 
                def load_catalogue():
 
-                       def catalogue_chunk_cb(loader, data, total, parser):
-                               if data is None:
+                       def catalogue_chunk_cb(loader, chunk, total, parser):
+                               if chunk is None:
                                        error = loader.get_error()
                                        if error:
                                                # report error somehow?
@@ -334,7 +334,7 @@ class MagnatuneSource(RB.BrowserSource):
                                                self.__download_album(uri, name[12:])
                                else:
                                        # hack around some weird chars that show up in the catalogue for some 
reason
-                                       data = str(data.str)
+                                       data = chunk.get_data().decode('utf-8', errors='replace')
                                        data = data.replace("\x19", "'")
                                        data = data.replace("\x13", "-")
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]