http: make download_file() return an optional

pull/6939/head
Alexander Medvednikov 2020-11-24 18:07:04 +01:00
parent a042966082
commit 98034e5504
2 changed files with 3 additions and 4 deletions

View File

@ -5,14 +5,13 @@ module http
import os import os
pub fn download_file(url string, out string) bool { pub fn download_file(url string, out string)? {
$if debug_http? { $if debug_http? {
println('download file url=$url out=$out') println('download file url=$url out=$out')
} }
s := get(url) or { s := get(url) or {
return false return error(err)
} }
os.write_file(out, s.text) os.write_file(out, s.text)
return true
// download_file_with_progress(url, out, empty, empty) // download_file_with_progress(url, out, empty, empty)
} }

View File

@ -49,7 +49,7 @@ $dec_fn_dec {
if (!root) { if (!root) {
const char *error_ptr = cJSON_GetErrorPtr(); const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL) { if (error_ptr != NULL) {
// fprintf(stderr, "Error in decode() for $styp error_ptr=: %%s\\n", error_ptr); // fprintf(stderr, "Error in decode() for $styp error_ptr=: %s\\n", error_ptr);
// printf("\\nbad js=%%s\\n", js.str); // printf("\\nbad js=%%s\\n", js.str);
Option err = v_error(tos2(error_ptr)); Option err = v_error(tos2(error_ptr));
return *(Option_$styp *)&err; return *(Option_$styp *)&err;