|
a/src/utils/readfile.h |
|
b/src/utils/readfile.h |
|
... |
|
... |
19 |
|
19 |
|
20 |
#include <sys/types.h>
|
20 |
#include <sys/types.h>
|
21 |
|
21 |
|
22 |
#include <string>
|
22 |
#include <string>
|
23 |
|
23 |
|
24 |
/**
|
24 |
/**
|
25 |
* Read file in chunks, calling an accumulator for each chunk. Can be used
|
25 |
* Read file in chunks, calling an accumulator for each chunk. Can be used
|
26 |
* for reading in a file, computing an md5...
|
26 |
* for reading in a file, computing an md5...
|
27 |
*/
|
27 |
*/
|
28 |
class FileScanDo {
|
28 |
class FileScanDo {
|
29 |
public:
|
29 |
public:
|
30 |
virtual ~FileScanDo() {}
|
30 |
virtual ~FileScanDo() {}
|
31 |
virtual bool init(size_t size, std::string *reason) = 0;
|
31 |
virtual bool init(size_t size, std::string *reason) = 0;
|
32 |
virtual bool data(const char *buf, int cnt, std::string* reason) = 0;
|
32 |
virtual bool data(const char *buf, int cnt, std::string* reason) = 0;
|
33 |
};
|
33 |
};
|
34 |
bool file_scan(const std::string &filename, FileScanDo* doer, std::string *reason = 0);
|
34 |
bool file_scan(const std::string& filename, FileScanDo* doer, std::string *reason = 0);
|
35 |
/* Same but only process count cnt from offset offs. Set cnt to size_t(-1)
|
35 |
/* Same but only process count cnt from offset offs. Set cnt to size_t(-1)
|
36 |
* for no limit */
|
36 |
* for no limit */
|
37 |
bool file_scan(const std::string &fn, FileScanDo* doer, off_t offs, size_t cnt,
|
37 |
bool file_scan(const std::string& fn, FileScanDo* doer, off_t offs, size_t cnt,
|
38 |
std::string *reason = 0);
|
38 |
std::string *reason = 0);
|
39 |
|
39 |
|
40 |
/**
|
40 |
/**
|
41 |
* Read file into string.
|
41 |
* Read file into string.
|
42 |
* @return true for ok, false else
|
42 |
* @return true for ok, false else
|
43 |
*/
|
43 |
*/
|
44 |
bool file_to_string(const std::string &filename, std::string &data, std::string *reason = 0);
|
44 |
bool file_to_string(const std::string& filename, std::string& data, std::string *reason = 0);
|
45 |
|
45 |
|
46 |
/** Read file chunk into string. Set cnt to size_t(-1) for whole file */
|
46 |
/** Read file chunk into string. Set cnt to size_t(-1) for whole file */
|
47 |
bool file_to_string(const std::string &filename, std::string &data,
|
47 |
bool file_to_string(const std::string& filename, std::string& data,
|
48 |
off_t offs, size_t cnt, std::string *reason = 0);
|
48 |
off_t offs, size_t cnt, std::string *reason = 0);
|
49 |
|
49 |
|
50 |
#endif /* _READFILE_H_INCLUDED_ */
|
50 |
#endif /* _READFILE_H_INCLUDED_ */
|