30 class gzfstreambuf :
public std::streambuf {
45 if ((
mode ^ std::ios::in ^ std::ios::out) == 0) {
50 std::string gzmode((
mode & std::ios::in) != 0 ?
"rb" :
"wb");
51 fileHandle = gzopen(filename.c_str(), gzmode.c_str());
85 int_type
overflow(
int c = EOF)
override {
86 if (((
mode & std::ios::out) == 0) || !
isOpen) {
94 int toWrite = pptr() - pbase();
95 if (gzwrite(
fileHandle, pbase(), toWrite) != toWrite) {
104 if (((
mode & std::ios::in) == 0) || !
isOpen) {
107 if ((gptr() !=
nullptr) && (gptr() < egptr())) {
108 return traits_type::to_int_type(*gptr());
111 unsigned charsPutBack = gptr() - eback();
115 memcpy(
buffer +
reserveSize - charsPutBack, gptr() - charsPutBack, charsPutBack);
118 if (charsRead <= 0) {
124 return traits_type::to_int_type(*gptr());
127 int sync()
override {
128 if ((pptr() !=
nullptr) && pptr() > pbase()) {
129 int toWrite = pptr() - pbase();
130 if (gzwrite(
fileHandle, pbase(), toWrite) != toWrite) {
139 static constexpr
unsigned int bufferSize = 65536;
145 std::ios_base::openmode
mode = std::ios_base::in;
148 class gzfstream :
virtual public std::ios {
154 gzfstream(
const std::string& filename, std::ios_base::openmode mode) {
156 open(filename, mode);
165 void open(
const std::string& filename, std::ios_base::openmode mode) {
166 if (
buf.
open(filename, mode) ==
nullptr) {
167 clear(rdstate() | std::ios::badbit);
178 clear(rdstate() | std::ios::badbit);
183 gzfstreambuf*
rdbuf()
const {
197 explicit igzfstream(
const std::string& filename, std::ios_base::openmode mode = std::ios::in)
208 void open(
const std::string& filename, std::ios_base::openmode mode = std::ios::in) {
213 class ogzfstream :
public internal::gzfstream,
public std::ostream {
217 explicit ogzfstream(
const std::string& filename, std::ios_base::openmode mode = std::ios::out)
228 void open(
const std::string& filename, std::ios_base::openmode mode = std::ios::out) {