-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathzlib_wrapper.cpp
51 lines (43 loc) · 1.35 KB
/
zlib_wrapper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright (C) 2019 Meng Zhou and Andrew D. Smith
*
* Author: Meng Zhou and Andrew D. Smith
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "zlib_wrapper.hpp"
#include <algorithm>
using std::string;
char igzfstream::peek() {
const char c = gzgetc(fileobj);
if (!gzeof(fileobj))
gzungetc(c, fileobj);
return c;
}
igzfstream &getline(igzfstream &in, string &line) {
if (gzgets(in.fileobj, &in.buf[0], in.chunk_size)) {
auto eol = std::find(begin(in.buf), end(in.buf), '\n');
line.clear();
// in case line already has a reserve
copy(begin(in.buf), eol, std::back_inserter(line));
}
return in;
}
igzfstream &operator>>(igzfstream &in, string &line) {
return getline(in, line);
}
ogzfstream &operator<<(ogzfstream &out, const string &line) {
gzputs(out.fileobj, line.c_str());
return out;
}
ogzfstream &operator<<(ogzfstream &out, const char c) {
gzputc(out.fileobj, c);
return out;
}