Updated python scripts to use new eblob class
[elliptics.git] / example / eblob_gen / dir.cpp
blobaa277ce7fe1c45daf505a076a238a19f19ab64b4
1 /*
2 * 2011+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include "eblob_gen.h"
18 eblob_dir_source::eblob_dir_source(const std::string &path) : itr(fs::path(path))
22 eblob_dir_source::~eblob_dir_source()
26 bool eblob_dir_source::next(const bool prepend, const struct timespec *ts, std::string &name, std::string &data)
28 if (itr == end_itr)
29 return false;
31 std::ifstream file(itr->path().string().c_str(), std::ios::binary | std::ios::in);
32 std::filebuf *pbuf = file.rdbuf();
33 std::stringstream ss;
35 if (prepend) {
36 size_t size = pbuf->pubseekoff(0, std::ios::end, std::ios::in);
37 pbuf->pubseekpos(0, std::ios::in);
39 prepend_data(data, size, (struct timespec *)ts);
42 ss << pbuf;
44 name.assign(itr->leaf());
45 data.append(ss.str());
46 ++itr;
48 return true;