16 static bool isZLibCompressed(const std::string &filename);
17 static bool isSnappyCompressed(const std::string &filename);
19 File(const std::string &filename = std::string(),
20 File::Mode mode = File::Read);
23 bool isOpened() const;
24 File::Mode mode() const;
25 std::string filename() const;
27 bool open(const std::string &filename, File::Mode mode);
28 bool write(const void *buffer, int length);
29 bool read(void *buffer, int length);
35 virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0;
36 virtual bool rawWrite(const void *buffer, int length) = 0;
37 virtual bool rawRead(void *buffer, int length) = 0;
38 virtual int rawGetc() = 0;
39 virtual void rawClose() = 0;
40 virtual void rawFlush() = 0;
43 std::string m_filename;
48 class ZLibFile : public File {
50 ZLibFile(const std::string &filename = std::string(),
51 File::Mode mode = File::Read);
55 virtual bool rawOpen(const std::string &filename, File::Mode mode);
56 virtual bool rawWrite(const void *buffer, int length);
57 virtual bool rawRead(void *buffer, int length);
58 virtual int rawGetc();
59 virtual void rawClose();
60 virtual void rawFlush();
69 #define SNAPPY_CHUNK_SIZE (1 * 1024 * 1024)
70 class SnappyFile : public File {
72 SnappyFile(const std::string &filename = std::string(),
73 File::Mode mode = File::Read);
74 virtual ~SnappyFile();
77 virtual bool rawOpen(const std::string &filename, File::Mode mode);
78 virtual bool rawWrite(const void *buffer, int length);
79 virtual bool rawRead(void *buffer, int length);
80 virtual int rawGetc();
81 virtual void rawClose();
82 virtual void rawFlush();
85 inline int freeCacheSize() const
88 return m_cacheSize - (m_cachePtr - m_cache);
93 void createCache(size_t size);
95 std::fstream m_stream;
100 char *m_compressedCache;