]> git.cworth.org Git - apitrace/blobdiff - trace_file.cpp
Automatically detect whether trace is zlib or snappy compressed
[apitrace] / trace_file.cpp
index 0272a5c29767bacb76fed998613113b56b2a6424..10e6565925449f3b820088587cdad1453139dea5 100644 (file)
@@ -89,6 +89,21 @@ int File::getc()
     return rawGetc();
 }
 
+bool File::isZLibCompressed(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 == 0x1f && byte2 == 0x8b);
+}
+
 ZLibFile::ZLibFile(const std::string &filename,
                    File::Mode mode)
     : File(filename, mode),