9 #ifndef FST_EXTENSIONS_COMPRESS_GZFILE_H_ 10 #define FST_EXTENSIONS_COMPRESS_GZFILE_H_ 30 GzFile(
const char *source,
const char *mode)
31 : gzfile_(gzopen(source, mode)), error_(gzfile_ == nullptr) {}
38 int Read(
void *buf,
unsigned int size) {
39 const auto bytes_read = gzread(gzfile_, buf, size);
40 if ((bytes_read < size) && !gzeof(gzfile_)) error_ =
true;
45 void Write(
const char *buf,
unsigned int size) {
46 if (gzwrite(gzfile_, buf, size) != size) error_ =
true;
63 void Write(
const std::stringstream &ssbuf) {
64 const auto sbuf = ssbuf.str();
65 gz_.Write(sbuf.data(), sbuf.size());
83 std::unique_ptr<std::stringstream>
Read() {
85 std::unique_ptr<std::stringstream> sstrm(
new std::stringstream);
90 while ((bytes_read = gz_.Read(buf, bufsize_)) == bufsize_) {
91 sstrm->write(buf, bufsize_);
93 sstrm->write(buf, bytes_read);
100 static const size_t bufsize_ = 8192;
105 #endif // FST_EXTENSIONS_COMPRESS_GZFILE_H_ IGzFile(const char *source)
void Write(const std::stringstream &ssbuf)
OGzFile(const char *source)
std::unique_ptr< std::stringstream > Read()
IGzFile(const std::string &source)
int Read(void *buf, unsigned int size)
GzFile(const char *source, const char *mode)
void Write(const char *buf, unsigned int size)
OGzFile(const std::string &source)