Debian Codegraph @

src/GZFileWriter.h

raw symbols SCIP
1 /**
2 * Contact: [email protected]
3 */
4
5 #ifndef GZFILEWRITER_H_
6 #define GZFILEWRITER_H_
7
8 #include <stdio.h>
9 #include <stdarg.h>
10 #include <iostream>
11 #include <cstring>
12
13 #include "NGMThreads.h"
14 #include "ILog.h"
15 #include "zlib.h"
16
17 class GZFileWriter : public FileWriter {
18
19 public:
20
21 gzFile m_Output;
22
23 GZFileWriter(char const * const filename) {
24 std::string strFilename = std::string(filename);
25 if(!hasSuffix(strFilename, ".gz")) {
26 strFilename += ".gz";
27 }
28 if (!(m_Output = gzopen(strFilename.c_str(), "wb"))) {
29 Log.Error("Unable to open output file %s", filename);
30 }
31 }
32
33 ~GZFileWriter() {
34 gzclose(m_Output);
35 }
36
37 void doFlush(int & bufferPosition, int const BUFFER_LIMIT, char * writeBuffer, bool last = false) {
38
39 if (bufferPosition > BUFFER_LIMIT || last) {
40 if(gzwrite(m_Output, writeBuffer, bufferPosition) < 0) {
41 Log.Error("Writing");
42 }
43 bufferPosition = 0;
44
45 }
46
47 }
48
49 private:
50 bool hasSuffix(const std::string &str, const std::string &suffix)
51 {
52 return str.size() >= suffix.size() &&
53 str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
54 }
55
56 };
57
58 #endif /* GZFILEWRITER_H_ */