1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

clean up download_lin.v

This commit is contained in:
Alexander Medvednikov 2019-06-23 18:32:08 +02:00
parent a401b5e242
commit ec87ca37fa

View File

@ -6,7 +6,6 @@ module http
import os import os
@size_t kek
type downloadfn fn (written int) type downloadfn fn (written int)
struct DownloadStruct { struct DownloadStruct {
@ -16,10 +15,8 @@ struct DownloadStruct {
} }
fn download_cb(ptr voidptr, size, nmemb size_t, userp voidptr) int { fn download_cb(ptr voidptr, size, nmemb size_t, userp voidptr) int {
// # struct http__MemoryStruct *mem = (struct http__MemoryStruct *)userp;
data := &DownloadStruct(userp) data := &DownloadStruct(userp)
# size_t written = fwrite(ptr, size, nmemb, (FILE*)(data->stream)); # size_t written = fwrite(ptr, size, nmemb, (FILE*)(data->stream));
// # printf("!!!%d\n", written);
# data->written += written; # data->written += written;
if !isnil(data.cb) { if !isnil(data.cb) {
# data->cb(data->written); # data->cb(data->written);
@ -36,7 +33,6 @@ fn download_file_with_progress(url, out string, cb, cb_finished voidptr) {
# FILE* fp = fopen(out.str,"wb"); # FILE* fp = fopen(out.str,"wb");
# curl_easy_setopt(curl, CURLOPT_URL, url.str); # curl_easy_setopt(curl, CURLOPT_URL, url.str);
C.curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_cb) C.curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_cb)
// # curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, http__download_cb);
data := &DownloadStruct { data := &DownloadStruct {
// stream:fp // stream:fp
cb: cb cb: cb
@ -46,18 +42,11 @@ fn download_file_with_progress(url, out string, cb, cb_finished voidptr) {
# double d = 0; # double d = 0;
# curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d); # curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d);
# CURLcode res = curl_easy_perform(curl); # CURLcode res = curl_easy_perform(curl);
println('DONE!')
# curl_easy_cleanup(curl); # curl_easy_cleanup(curl);
# fclose(fp); # fclose(fp);
# void (*finished)() =cb_finished; finished(); # void (*finished)() =cb_finished; finished();
} }
fn download_file(url, out string) { fn download_file(url, out string) {
// println('\nDOWNLOAD FILE $out url=$url')
// -L follow redirects
// println('curl -L -o "$out" "$url"')
res := os.system('curl -s -L -o "$out" "$url"')
// res := os.system('curl -s -L -o "$out" "$url"')
// println(res)
} }