blob: 921804fcb50844de7864fd56cc3b5a9cafa62d18 (
plain)
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
|
#include "scriptLoader.h"
#include "task.h"
#include "stream.h"
#include <fstream>
SimpleMessageException(OpenTargetFile);
class WriteStream : public Task {
public:
WriteStream(const ScriptNodePtr & s) :
SourceObject(s),
Task(s),
path(s, "path")
{
s->script->loader.addLoadTarget(s, Storer::into<ElementLoader>(&stream));
}
void execute() const
{
std::fstream ddd(path().as<std::string>(), std::fstream::trunc | std::fstream::out);
if (!ddd.good()) {
throw OpenTargetFile(path());
}
stream->runStream([&ddd](const char * data, size_t len) -> size_t {
ddd.write(data, len);
return len;
});
}
const Variable path;
StreamPtr stream;
};
DECLARE_LOADER("writestream", WriteStream);
|