Downloader.h 834 Bytes
Newer Older
daFischer's avatar
first  
daFischer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/* 
 * File:   Downloader.h
 * Author: user
 *
 * Created on June 12, 2014, 12:18 AM
 */

#ifndef DOWNLOADER_H
#define	DOWNLOADER_H

#define BUFFER_UNIT 0x10000

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>

using namespace std;

class Downloader {
public:
    Downloader(char* url);
    virtual ~Downloader();
    size_t read(char* buffer, size_t n);
    void download();
    void retarget(char* url);
    bool error;
    double progress;
    bool ready;
    
private:
    static size_t writeOpt( char *ptr, size_t size, size_t nmemb, void *userdata);
    static int progressOpt(void *clientp, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow);
    
    CURL* curl;
    int running;
    char* buffer;
    int bufferPos;
    int bufferLen;
};

#endif	/* DOWNLOADER_H */