diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/ecore/src/examples/ecore_file_download_example.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_file_download_example.c b/libraries/ecore/src/examples/ecore_file_download_example.c new file mode 100644 index 0000000..c03940b --- /dev/null +++ b/libraries/ecore/src/examples/ecore_file_download_example.c | |||
@@ -0,0 +1,86 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <Eina.h> | ||
3 | #include <Ecore.h> | ||
4 | #include <Ecore_File.h> | ||
5 | |||
6 | /* | ||
7 | * ecore_file_download() example | ||
8 | * | ||
9 | * compile with: | ||
10 | * gcc ecore_file_download_example.c `pkg-config --libs --cflags ecore-file` \ | ||
11 | * -o ecore_file_download_example | ||
12 | * | ||
13 | */ | ||
14 | |||
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" | ||
18 | |||
19 | |||
20 | void | ||
21 | completion_cb(void *data, const char *file, int status) | ||
22 | { | ||
23 | printf("Done (status: %d)\n", status); | ||
24 | ecore_main_loop_quit(); | ||
25 | } | ||
26 | |||
27 | int | ||
28 | progress_cb(void *data, const char *file, | ||
29 | long int dltotal, long int dlnow, | ||
30 | long int ultotal, long int ulnow) | ||
31 | { | ||
32 | printf("Progress: %ld/%ld\n", dlnow, dltotal); | ||
33 | return ECORE_FILE_PROGRESS_CONTINUE; // continue the download | ||
34 | } | ||
35 | |||
36 | |||
37 | int main(void) | ||
38 | { | ||
39 | double start; | ||
40 | Eina_Hash *headers; | ||
41 | |||
42 | eina_init(); | ||
43 | ecore_init(); | ||
44 | ecore_file_init(); | ||
45 | |||
46 | if (ecore_file_exists(DST)) | ||
47 | ecore_file_unlink(DST); | ||
48 | |||
49 | start = ecore_time_get(); | ||
50 | |||
51 | if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL)) | ||
52 | { | ||
53 | printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST); | ||
54 | ecore_main_loop_begin(); | ||
55 | printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start); | ||
56 | printf("Downloaded %lld bytes\n", ecore_file_size(DST)); | ||
57 | } | ||
58 | else | ||
59 | { | ||
60 | printf("Error, can't start download\n"); | ||
61 | goto done; | ||
62 | } | ||
63 | |||
64 | headers = eina_hash_string_small_new(NULL); | ||
65 | eina_hash_add(headers, "Content-type", "application/x-gzip"); | ||
66 | |||
67 | if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, NULL, headers)) | ||
68 | { | ||
69 | printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST_MIME); | ||
70 | ecore_main_loop_begin(); | ||
71 | printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start); | ||
72 | printf("Downloaded %lld bytes\n", ecore_file_size(DST)); | ||
73 | } | ||
74 | else | ||
75 | { | ||
76 | printf("Error, can't start download\n"); | ||
77 | goto done; | ||
78 | } | ||
79 | |||
80 | done: | ||
81 | if (headers) eina_hash_free(headers); | ||
82 | ecore_file_shutdown(); | ||
83 | ecore_shutdown(); | ||
84 | eina_shutdown(); | ||
85 | return 0; | ||
86 | } | ||