mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
x64: function calls; http: download_file()
This commit is contained in:
14
vlib/http/download.v
Normal file
14
vlib/http/download.v
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2019 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
module http
|
||||
|
||||
import os
|
||||
|
||||
fn download_file(url, out string) bool {
|
||||
s := http.get(url) or { return false }
|
||||
os.write_file(out, s.text)
|
||||
return true
|
||||
//download_file_with_progress(url, out, empty, empty)
|
||||
}
|
@ -5,57 +5,53 @@
|
||||
module http
|
||||
|
||||
type downloadfn fn (written int)
|
||||
type download_finished_fn fn ()
|
||||
type download_finished_fn fn ()
|
||||
|
||||
/*
|
||||
/*
|
||||
struct DownloadStruct {
|
||||
mut:
|
||||
mut:
|
||||
stream voidptr
|
||||
written int
|
||||
cb downloadfn
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
fn download_cb(ptr voidptr, size, nmemb size_t, userp voidptr) {
|
||||
/*
|
||||
fn download_cb(ptr voidptr, size, nmemb size_t, userp voidptr) {
|
||||
/*
|
||||
mut data := &DownloadStruct(userp)
|
||||
written := C.fwrite(ptr, size, nmemb, data.stream)
|
||||
data.written += written
|
||||
data.cb(data.written)
|
||||
//#data->cb(data->written); // TODO
|
||||
return written
|
||||
*/
|
||||
written := C.fwrite(ptr, size, nmemb, data.stream)
|
||||
data.written += written
|
||||
data.cb(data.written)
|
||||
//#data->cb(data->written); // TODO
|
||||
return written
|
||||
*/
|
||||
}
|
||||
|
||||
fn download_file_with_progress(url, out string, cb downloadfn, cb_finished fn()) {
|
||||
/*
|
||||
fn download_file_with_progress(url, out string, cb downloadfn, cb_finished fn()) {
|
||||
/*
|
||||
curl := C.curl_easy_init()
|
||||
if isnil(curl) {
|
||||
return
|
||||
}
|
||||
cout := out.str
|
||||
fp := C.fopen(cout, 'wb')
|
||||
C.curl_easy_setopt(curl, CURLOPT_URL, url.str)
|
||||
cout := out.str
|
||||
fp := C.fopen(cout, 'wb')
|
||||
C.curl_easy_setopt(curl, CURLOPT_URL, url.str)
|
||||
C.curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_cb)
|
||||
data := &DownloadStruct {
|
||||
stream:fp
|
||||
cb: cb
|
||||
}
|
||||
C.curl_easy_setopt(curl, CURLOPT_WRITEDATA, data)
|
||||
mut d := 0.0
|
||||
C.curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)
|
||||
C.curl_easy_perform(curl)
|
||||
C.curl_easy_cleanup(curl)
|
||||
C.fclose(fp)
|
||||
cb_finished()
|
||||
*/
|
||||
}
|
||||
|
||||
fn download_file(url, out string) {
|
||||
//download_file_with_progress(url, out, empty, empty)
|
||||
C.curl_easy_setopt(curl, CURLOPT_WRITEDATA, data)
|
||||
mut d := 0.0
|
||||
C.curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)
|
||||
C.curl_easy_perform(curl)
|
||||
C.curl_easy_cleanup(curl)
|
||||
C.fclose(fp)
|
||||
cb_finished()
|
||||
*/
|
||||
}
|
||||
|
||||
fn empty() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ module http
|
||||
fn download_file_with_progress(url, out string, cb, cb_finished voidptr) {
|
||||
}
|
||||
|
||||
/*
|
||||
pub fn download_file(url, out string) {
|
||||
C.URLDownloadToFile(0, url.to_wide(), out.to_wide(), 0, 0)
|
||||
/*
|
||||
@ -25,3 +26,4 @@ pub fn download_file(url, out string) {
|
||||
# }
|
||||
*/
|
||||
}
|
||||
*/
|
||||
|
Reference in New Issue
Block a user