项目作者: winsoft666

项目描述 :
C++ File Download Library.
高级语言: C++
项目地址: git://github.com/winsoft666/teemo.git
创建时间: 2019-11-26T09:24:44Z
项目社区:https://github.com/winsoft666/teemo

开源协议:GNU General Public License v3.0

下载


Zoe

Vcpkg package
badge

English | 简体中文

A C++ file download library.

Features

  • Multi-protocol, such as HTTP(s), FTP(s)…

  • Multi-threaded Segmented downloads and breakpoint transmission.

  • Limit download speed.

  • Disk cache.

  • Support large file (PB level).

  • Compatible with server leeching detection(or limit).

Compile and Install

Zoe only depends on curl. After installing curl, use CMake to compile and install Zoe.

In addition, the Zoe library has been included in Microsoft’s vcpkg, which can be quickly installed directly using the following command:

  1. vcpkg install zoe

If running the test case fails, check if the download link in the http_test_datas variable (test_data.h) is valid.

Getting Started

The following example uses Zoe’s default configuration parameters to demonstrate how to quickly use Zoe to download file:

  1. #include <iostream>
  2. #include "zoe.h"
  3. int main(int argc, char** argv) {
  4. using namespace zoe;
  5. Zoe::GlobalInit();
  6. Zoe z;
  7. std::shared_future<Result> r = z.start(u8"http://xxx.xxx.com/test.exe", u8"D:\\test.exe");
  8. Result result = r.get();
  9. Zoe::GlobalUnInit();
  10. return 0;
  11. }

The following example is a bit more complex and sets some configuration parameters and callback functions:

  1. #include <iostream>
  2. #include "zoe.h"
  3. int main(int argc, char** argv) {
  4. using namespace zoe;
  5. Zoe::GlobalInit();
  6. Zoe z;
  7. z.setThreadNum(10); // Optional
  8. z.setTmpFileExpiredTime(3600); // Optional
  9. z.setDiskCacheSize(20 * (2 << 19)); // Optional
  10. z.setMaxDownloadSpeed(50 * (2 << 19)); // Optional
  11. z.setHashVerifyPolicy(ALWAYS, MD5, "6fe294c3ef4765468af4950d44c65525"); // Optional, support MD5, CRC32, SHA256
  12. // There are more options available, please check zoe.h
  13. z.setVerboseOutput([](const utf8string& verbose) { // Optional
  14. printf("%s\n", verbose.c_str());
  15. });
  16. z.setHttpHeaders({ // Optional
  17. {u8"Origin", u8"http://xxx.xxx.com"},
  18. {u8"User-Agent", u8"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"}
  19. });
  20. std::shared_future<Result> r = z.start(
  21. u8"http://xxx.xxx.com/test.exe", u8"D:\\test.exe",
  22. [](Result result) { // Optional
  23. // result callback
  24. },
  25. [](int64_t total, int64_t downloaded) { // Optional
  26. // progress callback
  27. },
  28. [](int64_t byte_per_secs) { // Optional
  29. // real-time speed callback
  30. });
  31. r.wait();
  32. Zoe::GlobalUnInit();
  33. return 0;
  34. }

Command-line tool

zoe_tool is command-line tool based on zoe library.

Usage:

  1. zoe_tool URL TargetFilePath [ThreadNum] [DiskCacheMb] [MD5] [TmpExpiredSeconds] [MaxSpeed]
  • URL: Download URL.
  • TargetFilePath: target file saved path.
  • ThreadNum: thread number, optional, default is 1.
  • DiskCacheMb: Disk cache size(Mb), default is 20Mb.
  • MD5: target file md5, optional, if this value isn’t empty, tools will check file md5 after download finished.
  • TmpExpiredSeconds: seconds, optional, the temporary file will expired after these senconds.
  • MaxSpeed: max download speed(byte/s).

Sponsor

Thank you for using this project. It would be a great pleasure for me if this project can be of help to you.

You can go to my Github homepage to make a donation.