Fix the S3Store get operation to handle arbitrarily-sized objects.
[bluesky.git] / bluesky / s3store.c
index 2ac2c3a..083023e 100644 (file)
@@ -61,17 +61,14 @@ static void s3store_destroy(gpointer store)
 }
 
 struct get_info {
-    gchar *buf;
-    gint offset;
+    GString *buf;
 };
 
 static S3Status s3store_get_handler(int bufferSize, const char *buffer,
                                     void *callbackData)
 {
     struct get_info *info = (struct get_info *)callbackData;
-    gint bytes = MIN(bufferSize, (int)(BLUESKY_BLOCK_SIZE - info->offset));
-    memcpy(info->buf + info->offset, buffer, bytes);
-    info->offset += bytes;
+    g_string_append_len(info->buf, buffer, bufferSize);
     return S3StatusOK;
 }
 
@@ -113,8 +110,7 @@ static BlueSkyRCStr *s3store_get(gpointer s, const gchar *key)
     S3Store *store = (S3Store *)s;
 
     struct get_info info;
-    info.buf = (char *)g_malloc0(BLUESKY_BLOCK_SIZE);
-    info.offset = 0;
+    info.buf = g_string_new("");
 
     struct S3GetObjectHandler handler;
     handler.responseHandler.propertiesCallback = s3store_properties_callback;
@@ -126,7 +122,7 @@ static BlueSkyRCStr *s3store_get(gpointer s, const gchar *key)
                   &handler, &info);
 
     BlueSkyRCStr *raw, *decrypted;
-    raw = bluesky_string_new(info.buf, BLUESKY_BLOCK_SIZE);
+    raw = bluesky_string_new_from_string(info.buf);
     decrypted = bluesky_crypt_decrypt(raw, store->encryption_key);
     bluesky_string_unref(raw);
     return decrypted;