Skip to content

fast-down/fast-down-c

Repository files navigation

fast-down-c

GitHub last commit Build License

fast-down C 语言绑定,封装自 fast-down-ffi,由 Rust 驱动,简洁易用。

编译

cargo build --release

编译产物在 target/release/ 目录下:

  • Linux/macOS: libfast_down.solibfast_down.a
  • Windows: fast_down.dllfast_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;
}

查看更多示例

About

fast-down 的 C 接口

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors