byteme
C++ wrappers for buffered inputs
Loading...
Searching...
No Matches
GzipFileReader.hpp
Go to the documentation of this file.
1#ifndef BYTEME_GZIP_FILE_READER_HPP
2#define BYTEME_GZIP_FILE_READER_HPP
3
4#include "zlib.h"
5#include <stdexcept>
6#include <vector>
7#include <string>
8#include "SelfClosingGzFile.hpp"
9#include "Reader.hpp"
10
17namespace byteme {
18
24class GzipFileReader : public Reader {
25public:
30 GzipFileReader(const char* path, size_t buffer_size = 65536) : my_gzfile(path, "rb"), my_buffer(buffer_size) {}
31
36 GzipFileReader(const std::string& path, size_t buffer_size = 65536) : GzipFileReader(path.c_str(), buffer_size) {}
37
38public:
39 bool load() {
40 my_read = gzread(my_gzfile.handle, my_buffer.data(), my_buffer.size());
41 if (my_read) {
42 return true;
43 }
44
45 if (!gzeof(my_gzfile.handle)) {
46 int dummy;
47 throw std::runtime_error(gzerror(my_gzfile.handle, &dummy));
48 }
49
50 return false;
51 }
52
53 const unsigned char* buffer() const {
54 return my_buffer.data();
55 }
56
57 size_t available() const {
58 return my_read;
59 }
60
61private:
62 SelfClosingGzFile my_gzfile;
63 std::vector<unsigned char> my_buffer;
64 size_t my_read = 0;
65};
66
67}
68
69#endif
Read an input source.
Read uncompressed bytes from a Gzip-compressed file.
Definition GzipFileReader.hpp:24
size_t available() const
Definition GzipFileReader.hpp:57
const unsigned char * buffer() const
Definition GzipFileReader.hpp:53
GzipFileReader(const std::string &path, size_t buffer_size=65536)
Definition GzipFileReader.hpp:36
bool load()
Definition GzipFileReader.hpp:39
GzipFileReader(const char *path, size_t buffer_size=65536)
Definition GzipFileReader.hpp:30
Virtual class for reading bytes from a source.
Definition Reader.hpp:15
Simple byte readers and writers.