eina: allow convertion to BLOB from Eina_File Eina_Value by mmap the file.
authorCedric Bail <cedric@osg.samsung.com>
Wed, 13 Sep 2017 17:38:36 +0000 (10:38 -0700)
committerCedric Bail <cedric@osg.samsung.com>
Wed, 13 Sep 2017 17:38:36 +0000 (10:38 -0700)
src/lib/eina/eina_value.c

index 59d54d8..6088d63 100644 (file)
@@ -4722,7 +4722,25 @@ _eina_value_type_file_convert_to(const Eina_Value_Type *type EINA_UNUSED, const
         filename = eina_file_filename_get(f);
         ret = eina_value_type_pset(convert, convert_mem, &filename);
      }
+   else if (convert == EINA_VALUE_TYPE_BLOB)
+     {
+        Eina_Value_Blob *c = convert_mem;
+        const void *m;
+
+        m = eina_file_map_all((Eina_File*) f, EINA_FILE_WILLNEED);
+        if (!m) goto end;
+
+        c->ops = EINA_VALUE_BLOB_OPERATIONS_MALLOC;
+        c->memory = malloc(eina_file_size_get(f));
+        memcpy((void*)c->memory, m, eina_file_size_get(f));
+        c->size = eina_file_size_get(f);
+
+        eina_file_map_free((Eina_File*)f, (void*)m);
+
+        ret = EINA_TRUE;
+     }
 
+ end:
    return ret;
 }