4 #include <Ecore_File.h>
7 * ecore_file_download() example
10 * gcc ecore_file_download_example.c `pkg-config --libs --cflags ecore-file` \
11 * -o ecore_file_download_example
15 #define URL "http://www.kernel.org/pub/linux/kernel/v1.0/linux-1.0.tar.gz"
16 #define DST "linux-1.0.tar.gz"
17 #define DST_MIME "[x-gzip]linux-1.0.tar.gz"
20 completion_cb(void *data, const char *file, int status)
22 printf("Done (status: %d)\n", status);
23 ecore_main_loop_quit();
27 progress_cb(void *data, const char *file,
28 long int dltotal, long int dlnow,
29 long int ultotal, long int ulnow)
31 printf("Progress: %ld/%ld\n", dlnow, dltotal);
32 return ECORE_FILE_PROGRESS_CONTINUE; // continue the download
45 if (ecore_file_exists(DST))
46 ecore_file_unlink(DST);
48 start = ecore_time_get();
50 if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL))
52 printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST);
53 ecore_main_loop_begin();
54 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
55 printf("Downloaded %lld bytes\n", ecore_file_size(DST));
59 printf("Error, can't start download\n");
63 headers = eina_hash_string_small_new(NULL);
64 eina_hash_add(headers, "Content-type", "application/x-gzip");
66 if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, NULL, headers))
68 printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST_MIME);
69 ecore_main_loop_begin();
70 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
71 printf("Downloaded %lld bytes\n", ecore_file_size(DST));
75 printf("Error, can't start download\n");
80 if (headers) eina_hash_free(headers);
81 ecore_file_shutdown();