fast-down C 语言绑定,封装自 fast-down-ffi,由 Rust 驱动,简洁易用。
cargo build --release编译产物在 target/release/ 目录下:
- Linux/macOS:
libfast_down.so或libfast_down.a - Windows:
fast_down.dll或fast_down.lib
cd example
gcc -O3 -o basic_download basic_download.c -I../include ../target/release/libfast_down.a
./basic_download#include "fast_down.h"
#include <stdio.h>
int main() {
const char *url = "https://example.com/test.zip";
// 创建下载任务
DownloadTask *task = prefetch(url, NULL, NULL);
if (task == NULL) {
printf("Url parse failed\n");
return 1;
}
const char *error = download_task_get_error(task);
if (error != NULL) {
printf("Error: %s\n", error);
download_task_free(&task);
return 1;
}
// 获取文件信息
UrlInfo *info = download_task_get_info(task);
const char *filename = url_info_get_filename(info);
uint64_t size = url_info_get_size(info);
printf("File: %s, Size: %llu bytes\n", filename, size);
// 开始下载
int ret = download_task_start_to_file(task, filename, NULL, NULL);
if (ret != 0) {
printf("Download failed: %d\n", ret);
}
// 释放资源
download_task_free(&task);
return 0;
}