diff options
-rw-r--r-- | project2/url/Jamfile.jam | 3 | ||||
-rw-r--r-- | project2/url/downloadToFile.cpp | 36 |
2 files changed, 37 insertions, 2 deletions
diff --git a/project2/url/Jamfile.jam b/project2/url/Jamfile.jam index 1710e17..1f48e2a 100644 --- a/project2/url/Jamfile.jam +++ b/project2/url/Jamfile.jam @@ -5,8 +5,7 @@ alias glibmm : : : : lib curl : : <name>curl ; lib p2url : - urlRows.cpp - curlHelper.cpp + [ glob *.cpp ] ../../libmisc/curlsup.cpp : <library>../common//p2common diff --git a/project2/url/downloadToFile.cpp b/project2/url/downloadToFile.cpp new file mode 100644 index 0000000..dcd9710 --- /dev/null +++ b/project2/url/downloadToFile.cpp @@ -0,0 +1,36 @@ +#include "curlHelper.h" +#include "task.h" +#include "scopeObject.h" +#include "scriptLoader.h" +#include "exceptions.h" +#include "../libmisc/curlsup.h" + +/// Project2 component to create a row set from the contents of a file accessible via libcurl +class Download : public Task, VariableCurlHelper { + public: + Download(ScriptNodePtr p) : + SourceObject(p), + Task(p), + VariableCurlHelper(p), + destination(p, "destination") + { + } + + void execute() const + { + CurlPtr c = newCurl(); + FILE * file = fopen(destination(), "w"); + if (!file) { + throw syscall_error(errno); + } + ScopeObject tidy([=]{ fclose(file); }); + c->performRead([=](const char * data, size_t len) -> size_t { return fwrite(data, 1, len, file); }); + } + + private: + + const Variable destination; +}; + +DECLARE_LOADER("download", Download); + |