X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=common%2Ftrace_file_snappy.cpp;h=f47c89b046c37fe282478a9ca6a014bb108df553;hb=570d8ccab67e230f61f9c79e4eaa6a1159bb6428;hp=4d4ecea7a73c8f4251a59116af61b7636db78402;hpb=712b03a91d7a8494bd75bb2a1b6257d474694c1e;p=apitrace diff --git a/common/trace_file_snappy.cpp b/common/trace_file_snappy.cpp index 4d4ecea..f47c89b 100644 --- a/common/trace_file_snappy.cpp +++ b/common/trace_file_snappy.cpp @@ -63,8 +63,6 @@ #define SNAPPY_CHUNK_SIZE (1 * 1024 * 1024) -#define SNAPPY_BYTE1 'a' -#define SNAPPY_BYTE2 't' using namespace trace; @@ -82,7 +80,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(); @@ -141,6 +139,7 @@ SnappyFile::SnappyFile(const std::string &filename, SnappyFile::~SnappyFile() { + close(); delete [] m_compressedCache; delete [] m_cache; } @@ -208,10 +207,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) { @@ -230,18 +229,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; } @@ -405,18 +404,3 @@ int SnappyFile::rawPercentRead() 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); -}