20 static bool isZLibCompressed(const std::string &filename);
21 static bool isSnappyCompressed(const std::string &filename);
23 File(const std::string &filename = std::string(),
24 File::Mode mode = File::Read);
27 bool isOpened() const;
28 File::Mode mode() const;
29 std::string filename() const;
31 bool open(const std::string &filename, File::Mode mode);
32 bool write(const void *buffer, int length);
33 bool read(void *buffer, int length);
35 void flush(FlushType type = FlushShallow);
39 virtual bool rawOpen(const std::string &filename, File::Mode mode) = 0;
40 virtual bool rawWrite(const void *buffer, int length) = 0;
41 virtual bool rawRead(void *buffer, int length) = 0;
42 virtual int rawGetc() = 0;
43 virtual void rawClose() = 0;
44 virtual void rawFlush(FlushType type) = 0;
47 std::string m_filename;
52 class ZLibFile : public File {
54 ZLibFile(const std::string &filename = std::string(),
55 File::Mode mode = File::Read);
59 virtual bool rawOpen(const std::string &filename, File::Mode mode);
60 virtual bool rawWrite(const void *buffer, int length);
61 virtual bool rawRead(void *buffer, int length);
62 virtual int rawGetc();
63 virtual void rawClose();
64 virtual void rawFlush(FlushType type);
73 #define SNAPPY_CHUNK_SIZE (1 * 1024 * 1024)
74 class SnappyFile : public File {
76 SnappyFile(const std::string &filename = std::string(),
77 File::Mode mode = File::Read);
78 virtual ~SnappyFile();
81 virtual bool rawOpen(const std::string &filename, File::Mode mode);
82 virtual bool rawWrite(const void *buffer, int length);
83 virtual bool rawRead(void *buffer, int length);
84 virtual int rawGetc();
85 virtual void rawClose();
86 virtual void rawFlush(FlushType type);
89 inline int freeCacheSize() const
92 return m_cacheSize - (m_cachePtr - m_cache);
97 void createCache(size_t size);
99 std::fstream m_stream;
104 char *m_compressedCache;