- m_stream.read((char*)m_compressedCache, compressedLength);
- /*
- * The reason we peek here is because the last read will
- * read all the way until the last character, but that will not
- * trigger m_stream.eof() to be set, so by calling peek
- * we assure that if we in fact have read the entire stream
- * then the m_stream.eof() is always set.
- */
- m_stream.peek();
- ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
- &m_cacheSize);
- if (m_cache)
- delete [] m_cache;
- createCache(m_cacheSize);
- ::snappy::RawUncompress(m_compressedCache, compressedLength,
- m_cache);
+
+ if (compressedLength) {
+ m_stream.read((char*)m_compressedCache, compressedLength);
+ ::snappy::GetUncompressedLength(m_compressedCache, compressedLength,
+ &m_cacheSize);
+ createCache(m_cacheSize);
+ ::snappy::RawUncompress(m_compressedCache, compressedLength,
+ m_cache);
+ } else {
+ createCache(0);
+ }