Skip to content

Commit

Permalink
chunk-loader: provide chunks as GBytes instances rather than GStrings
Browse files Browse the repository at this point in the history
We don't want chunks to be interpreted as utf8 strings in python.
  • Loading branch information
Jonathan Matthew committed Apr 21, 2013
1 parent 4ce2a9d commit f71e871
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
13 changes: 7 additions & 6 deletions lib/rb-chunk-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ struct _RBChunkLoaderPrivate
char *uri;
gssize chunk_size;
guint8 *chunk;
GString chunk_string;
guint64 total;

GError *error;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 ();

Expand Down
2 changes: 1 addition & 1 deletion lib/rb-chunk-loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
6 changes: 3 additions & 3 deletions plugins/magnatune/MagnatuneSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ def download_finished(copy, success, self):

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?
Expand All @@ -334,7 +334,7 @@ def catalogue_chunk_cb(loader, data, total, parser):
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", "-")

Expand Down

0 comments on commit f71e871

Please sign in to comment.