1 #include "trace_file.hpp"
3 #include "trace_snappyfile.hpp"
14 using namespace Trace;
17 File::File(const std::string &filename,
19 : m_filename(filename),
23 if (!m_filename.empty()) {
24 open(m_filename, m_mode);
33 bool File::isZLibCompressed(const std::string &filename)
35 std::fstream stream(filename.c_str(),
36 std::fstream::binary | std::fstream::in);
37 if (!stream.is_open())
40 unsigned char byte1, byte2;
45 return (byte1 == 0x1f && byte2 == 0x8b);
49 bool File::isSnappyCompressed(const std::string &filename)
51 std::fstream stream(filename.c_str(),
52 std::fstream::binary | std::fstream::in);
53 if (!stream.is_open())
56 unsigned char byte1, byte2;
61 return (byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2);
65 ZLibFile::ZLibFile(const std::string &filename,
67 : File(filename, mode),
76 bool ZLibFile::rawOpen(const std::string &filename, File::Mode mode)
78 m_gzFile = gzopen(filename.c_str(),
79 (mode == File::Write) ? "wb" : "rb");
80 return m_gzFile != NULL;
83 bool ZLibFile::rawWrite(const void *buffer, int length)
85 return gzwrite(m_gzFile, buffer, length) != -1;
88 bool ZLibFile::rawRead(void *buffer, int length)
90 return gzread(m_gzFile, buffer, length) != -1;
93 int ZLibFile::rawGetc()
95 return gzgetc(m_gzFile);
98 void ZLibFile::rawClose()
106 void ZLibFile::rawFlush(FlushType type)
108 gzflush(m_gzFile, Z_SYNC_FLUSH);