]> git.cworth.org Git - apitrace/blobdiff - trace_snappyfile.cpp
Fix silly typo
[apitrace] / trace_snappyfile.cpp
index ad3dc723242fd6a60275bb7a3cdf6e23afba4966..4dbe42dc364264a8db0e717a1af17681b9af271e 100644 (file)
@@ -93,6 +93,10 @@ bool SnappyFile::rawOpen(const std::string &filename, File::Mode mode)
 
     //read in the initial buffer if we're reading
     if (m_stream.is_open() && mode == File::Read) {
+        m_stream.seekg(0, std::ios::end);
+        m_endPos = m_stream.tellg();
+        m_stream.seekg(0, std::ios::beg);
+
         // read the snappy file identifier
         unsigned char byte1, byte2;
         m_stream >> byte1;
@@ -211,7 +215,7 @@ void SnappyFile::flushWriteCache()
     assert(m_cachePtr == m_cache);
 }
 
-void SnappyFile::flushReadCache()
+void SnappyFile::flushReadCache(size_t skipLength)
 {
     //assert(m_cachePtr == m_cache + m_cacheSize);
     m_currentOffset.chunk = m_stream.tellg();
@@ -223,8 +227,10 @@ void SnappyFile::flushReadCache()
         ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
                                         &m_cacheSize);
         createCache(m_cacheSize);
-        ::snappy::RawUncompress(m_compressedCache, compressedLength,
-                                m_cache);
+        if (skipLength < m_cacheSize) {
+            ::snappy::RawUncompress(m_compressedCache, compressedLength,
+                                    m_cache);
+        }
     } else {
         createCache(0);
     }
@@ -315,7 +321,7 @@ bool SnappyFile::rawSkip(size_t length)
             m_cachePtr += chunkSize;
             sizeToRead -= chunkSize;
             if (sizeToRead > 0) {
-                flushReadCache();
+                flushReadCache(sizeToRead);
             }
             if (!m_cacheSize) {
                 break;
@@ -325,3 +331,8 @@ bool SnappyFile::rawSkip(size_t length)
 
     return true;
 }
+
+int SnappyFile::rawPercentRead()
+{
+    return 100 * (double(m_stream.tellg()) / double(m_endPos));
+}