blob: 9946ec613b8ccee24c5a54979b38b01eef4eb156 (
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
36
37
|
#include "scriptLoader.h"
#include "task.h"
#include "stream.h"
#include "variables.h"
#include <scriptStorage.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(ExecContext * ec) const
{
std::fstream ddd(path(ec).as<std::string>(), std::fstream::trunc | std::fstream::out);
if (!ddd.good()) {
throw OpenTargetFile(path(ec));
}
stream->runStream([&ddd](const char * data, size_t len) -> size_t {
ddd.write(data, len);
return len;
}, ec);
}
const Variable path;
StreamPtr stream;
};
DECLARE_LOADER("writestream", WriteStream);
|