X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_file_snappy.cpp;h=41d86ea00ded834e33dadd3a3ca65c5d5ef7da63;hb=0ae84f58eee1c239d5bc2cc148a1d007b328d2e1;hp=5901bfb33f0b312b6fb78d00278283fd37c87d2f;hpb=565b80cc4a88ab420cf5e2138300856888ad9968;p=apitrace diff --git a/common/trace_file_snappy.cpp b/common/trace_file_snappy.cpp index 5901bfb..41d86ea 100644 --- a/common/trace_file_snappy.cpp +++ b/common/trace_file_snappy.cpp @@ -54,6 +54,7 @@ #include #include +#include #include #include @@ -63,8 +64,6 @@ #define SNAPPY_CHUNK_SIZE (1 * 1024 * 1024) -#define SNAPPY_BYTE1 'a' -#define SNAPPY_BYTE2 't' using namespace trace; @@ -82,7 +81,7 @@ public: protected: virtual bool rawOpen(const std::string &filename, File::Mode mode); virtual bool rawWrite(const void *buffer, size_t length); - virtual bool rawRead(void *buffer, size_t length); + virtual size_t rawRead(void *buffer, size_t length); virtual int rawGetc(); virtual void rawClose(); virtual void rawFlush(); @@ -209,10 +208,10 @@ bool SnappyFile::rawWrite(const void *buffer, size_t length) return true; } -bool SnappyFile::rawRead(void *buffer, size_t length) +size_t SnappyFile::rawRead(void *buffer, size_t length) { if (endOfData()) { - return false; + return 0; } if (freeCacheSize() >= length) { @@ -231,18 +230,18 @@ bool SnappyFile::rawRead(void *buffer, size_t length) flushReadCache(); } if (!m_cacheSize) { - break; + return length - sizeToRead; } } } - return true; + return length; } int SnappyFile::rawGetc() { - int c = 0; - if (!rawRead(&c, 1)) + unsigned char c = 0; + if (rawRead(&c, 1) != 1) return -1; return c; } @@ -399,25 +398,10 @@ bool SnappyFile::rawSkip(size_t length) int SnappyFile::rawPercentRead() { - return 100 * (double(m_stream.tellg()) / double(m_endPos)); + return int(100 * (double(m_stream.tellg()) / double(m_endPos))); } File* File::createSnappy(void) { return new SnappyFile; } - -bool File::isSnappyCompressed(const std::string &filename) -{ - std::fstream stream(filename.c_str(), - std::fstream::binary | std::fstream::in); - if (!stream.is_open()) - return false; - - unsigned char byte1, byte2; - stream >> byte1; - stream >> byte2; - stream.close(); - - return (byte1 == SNAPPY_BYTE1 && byte2 == SNAPPY_BYTE2); -}