Git Product home page Git Product logo

fastdownloader's Introduction

fastdownloader

Basic utility library based on Qt/C++ for fast, parallel downloads. It lets you download a file with more than one simultaneous connection.

Basic usage

C++11 needed

#include <QCoreApplication>
#include <QBuffer>
#include <QFile>
#include <fastdownloader.h>

int main(int argc, char* argv[])
{
    QCoreApplication a(argc, argv);

    auto buffer = new QBuffer;
    auto file = new QFile("/Users/omergoktas/Desktop/Dragon and Toast.mp3"); //!!! Change this
    auto downloader = new FastDownloader(QUrl("https://bit.ly/2EXm5LF"));
    
    buffer->open(QIODevice::WriteOnly);
    downloader->setNumberOfSimultaneousConnections(FastDownloader::MAX_SIMULTANEOUS_CONNECTIONS);
    
    if (!downloader->start()) {
        qWarning("Cannot start downloading for some reason");
        return EXIT_FAILURE;
    }

    QObject::connect(downloader, &FastDownloader::readyRead, [=] (int id) {
        buffer->seek(downloader->head(id) + downloader->pos(id));
        buffer->write(downloader->readAll(id));
    });
    QObject::connect(downloader, QOverload<qint64,qint64>::of(&FastDownloader::downloadProgress),
                     [=] (qint64 bytesReceived, qint64 bytesTotal) {
        qWarning("Download Progress: %lld of %lld", bytesReceived, bytesTotal);
    });
    QObject::connect(downloader, QOverload<>::of(&FastDownloader::finished), [=] {
        buffer->close();
        if (downloader->bytesReceived() > 0) {
            file->open(QIODevice::WriteOnly);
            file->write(buffer->data());
            file->close();
        }
        qWarning("All done!");
        qWarning("Any errors: %s", downloader->isError() ? "yes" : "nope");
        QCoreApplication::quit();
    });

    return a.exec();
}

Advanced usage

Please check out following example Qt project for more detailed use cases fastdownloadertest

fastdownloader's People

Contributors

omergoktas avatar

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.