GithubHelp home page GithubHelp logo

winsoft666 / zoe Goto Github PK

View Code? Open in Web Editor NEW
23.0 1.0 9.0 677 KB

C++ File Download Library.

License: GNU General Public License v3.0

CMake 0.97% C++ 98.97% C 0.06%
speed-limit libcurl http-file-download ftp-file-download vcpkg teemo zoe disk-cache segmented breakpoint-transmission

zoe's Introduction

Zoe

Vcpkg package badge

English | 简体中文

A C++ file download library.

Features

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

  • Segmented downloads and breakpoint transmission.

  • Limit download speed.

  • Configure disk cache.

  • Support downloading large files (TB level).

  • Compatible with server leeching detection(or limit).

Compile and Install

Method 1: Using with vcpkg

The zoe library has been included in Microsoft's vcpkg, you can use the following command to install zoe:

  1. Clone and setup vcpkg (See more detail on https://github.com/microsoft/vcpkg)

    git clone https://github.com/Microsoft/vcpkg.git
    cd vcpkg
    PS> bootstrap-vcpkg.bootstrap
    Linux:~/$ ./bootstrap-vcpkg.sh
  2. Install zoe

    PS> .\vcpkg install zoe [--triplet x64-windows-static/x64-windows/x64-windows-static-md and etc...]
    Linux:~/$ ./vcpkg install zoe

Method 2: Compile from source code

Step 1: Install dependencies

I prefer to use vcpkg to install dependencies. Of course, this is not the only way, you can install dependencies through any ways.

Recommend: add the directory where vcpkg.exe resides to the PATH environment variable.

  • libcurl

    # if you want support non-http protocol, such as ftp, the [non-http] option must be specified.
    vcpkg install curl[non-http]:x86-windows
  • gtest

    vcpkg install gtest:x86-windows

Step 2: Compile

Firstly using CMake to generate project or makefile, then comiple it:

Windows Sample:

cmake.exe -G "Visual Studio 15 2017" -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON -S %~dp0 -B %~dp0build

Linux Sample:

cmake -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON

# If using vcpkg to install dependencies, you have to special CMAKE_TOOLCHAIN_FILE
cmake -DCMAKE_TOOLCHAIN_FILE=/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-linux -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON

make

Getting Started

#include <iostream>
#include "zoe.h"

int main(int argc, char** argv) {
  using namespace zoe;

  Zoe::GlobalInit();

  Zoe z;

  z.setThreadNum(10);                     // Optional
  z.setTmpFileExpiredTime(3600);          // Optional
  z.setDiskCacheSize(20 * (2 << 19));     // Optional
  z.setMaxDownloadSpeed(50 * (2 << 19));  // Optional
  z.setHashVerifyPolicy(ALWAYS, MD5, "6fe294c3ef4765468af4950d44c65525"); // Optional, support MD5, CRC32, SHA256
  // There are more options available, please check zoe.h
  z.setVerboseOutput([](const utf8string& verbose) { // Optional
    printf("%s\n", verbose.c_str());
  });
  z.setHttpHeaders({  // Optional
    {u8"Origin", u8"http://xxx.xxx.com"},
    {u8"User-Agent", u8"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"}
   });
  
  std::shared_future<Result> res = z.start(
      u8"http://xxx.xxx.com/test.exe", u8"D:\\test.exe",
      [](Result result) {  // Optional
        // result callback
      },
      [](int64_t total, int64_t downloaded) {  // Optional
        // progress callback
      },
      [](int64_t byte_per_secs) {  // Optional
        // real-time speed callback
      });

  res.wait();

  Zoe::GlobalUnInit();

  return 0;
}

Command-line tool

zoe_tool is command-line tool based on zoe library.

Usage:

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).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.