forked from Shuhua-Group/ArchaicSeeker2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgzfstream.cpp
112 lines (94 loc) · 1.91 KB
/
gzfstream.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* gzfstream.cpp
*
* Created on: Sep 30, 2018
* Author: yuankai
*/
# include "gzfstream.hpp"
igzfd::igzfd(const std::string& path)
{
fd = gzopen(path.c_str(), "rb");
}
std::streamsize igzfd::read(char* s, std::streamsize n)
{
std::streamsize rd = gzread(fd, s, n);
if(rd != 0)
return rd;
else
return -1;
}
boost::iostreams::stream_offset igzfd::seek(boost::iostreams::stream_offset off, \
std::ios_base::seekdir way)
{
if(off < 0)
throw std::ios_base::failure("bad seek offset");
if(way == std::ios_base::cur)
gzseek(fd, off, SEEK_CUR);
else if(way == std::ios_base::beg)
gzseek(fd, off, SEEK_SET);
else
throw std::ios_base::failure("bad seek direction");
return gztell(fd);
}
int igzfd::open(const std::string& path)
{
fd = gzopen(path.c_str(), "rb");
int ret = 1;
if(NULL == fd)
ret = 0;
return ret;
}
void igzfd::close()
{
gzclose(fd);
}
ogzfd::ogzfd(const std::string& path)
{
fd = gzopen(path.c_str(), "wb");
}
std::streamsize ogzfd::write(const char* s, std::streamsize n)
{
std::streamsize wd = gzwrite(fd, s, n);
return wd;
}
boost::iostreams::stream_offset ogzfd::seek(boost::iostreams::stream_offset off, \
std::ios_base::seekdir way)
{
if(off < 0)
throw std::ios_base::failure("bad seek offset");
if(way == std::ios_base::cur)
gzseek(fd, off, SEEK_CUR);
else if(way == std::ios_base::beg)
gzseek(fd, off, SEEK_SET);
else
throw std::ios_base::failure("bad seek direction");
return gztell(fd);
}
int ogzfd::open(const std::string& path)
{
fd = gzopen(path.c_str(), "wb");
int ret = 1;
if(NULL == fd)
ret = 0;
return ret;
}
void ogzfd::close()
{
gzclose(fd);
}
gzifstream::~gzifstream()
{
this->operator->()->close();
}
int gzifstream::open(const std::string& path)
{
return this->operator->()->open(path);
}
gzofstream::~gzofstream()
{
this->operator->()->close();
}
int gzofstream::open(const std::string& path)
{
return this->operator->()->open(path);
}