Skip to content

Commit 168cb24

Browse files
Added a peek function for the igzfstream. Wish this wasn't needed, but some of our line oriented reading requires checking for eof to avoid reading an empty line. This is included in the istream so we are doing the same here. If this were put into the getline function it might cause slowdown because I'm not sure about the gaurantees on speed of ugzungetc
1 parent ef5258d commit 168cb24

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

zlib_wrapper.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919

2020
using std::string;
2121

22+
char
23+
igzfstream::peek() {
24+
const char c = gzgetc(fileobj);
25+
if (!gzeof(fileobj))
26+
gzungetc(c, fileobj);
27+
return c;
28+
}
29+
2230
igzfstream&
2331
getline(igzfstream &in, string &line) {
2432
if (gzgets(in.fileobj, &in.buf[0], in.chunk_size)) {
25-
auto eol = std::find(begin(in.buf), end(in.buf), '\n');
26-
line = string(begin(in.buf), eol);
33+
auto eol = std::find(begin(in.buf), end(in.buf), '\n');
34+
line = string(begin(in.buf), eol);
2735
}
2836
return in;
2937
}

zlib_wrapper.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct igzfstream {
3232
}
3333
~igzfstream() {gzclose_r(fileobj);}
3434
operator bool() const {return !gzeof(fileobj);}
35+
char peek();
3536

3637
size_t chunk_size;
3738
std::vector<char> buf;

0 commit comments

Comments
 (0)