33 #include <zlib/zlib.h>
49 const char record_separator;
54 std::vector<char> buffer;
55 size_t read_ptr, valid_size;
58 BufferedTextFile(
const char *fname,
char record_separator =
'\n',
size_t buffer_size = 256 * 1024)
59 : record_separator(record_separator), eof(false), read_ptr(0), valid_size(0)
67 buffer.resize(buffer_size + 1);
68 buffer[buffer_size] = 0;
88 if (read_ptr != valid_size && read_ptr != 0)
90 memmove(&buffer[0], &buffer[read_ptr], valid_size - read_ptr);
93 valid_size -= read_ptr;
96 size_t bytes_read =
gzread(fp, &buffer[valid_size], buffer.size() - valid_size - 1);
104 valid_size += bytes_read;
106 buffer[valid_size] = 0;
113 return (read_ptr == 0 && valid_size == buffer.size() - 1);
118 return (valid_size == 0 || read_ptr == valid_size);
129 start = &buffer[read_ptr];
130 end = (
char *) memchr(start, record_separator, valid_size - read_ptr);
143 end = &buffer[valid_size];
151 buffer.resize(buffer.size() * 2);
158 }
while(end == NULL);
163 read_ptr += end - start + 1;