Skip to content

Commit

Permalink
Added open and close
Browse files Browse the repository at this point in the history
  • Loading branch information
CMurtagh-LGTM committed Jun 20, 2021
1 parent e171289 commit f5c8c50
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/zstr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ class ifstream
exceptions(std::ios_base::badbit);
}
explicit ifstream(): detail::strict_fstream_holder< strict_fstream::ifstream >(), std::istream(new istreambuf(_fs.rdbuf())){}
void close() {
_fs.close();
}
void open(const std::string& filename, std::ios_base::openmode mode = std::ios_base::in){
_fs.open(filename, mode);
std::istream::operator=(std::istream(new istreambuf(_fs.rdbuf())));
}
virtual ~ifstream()
{
if (rdbuf()) delete rdbuf();
Expand All @@ -449,6 +456,15 @@ class ofstream
exceptions(std::ios_base::badbit);
}
explicit ofstream(): detail::strict_fstream_holder< strict_fstream::ofstream >(), std::ostream(new ostreambuf(_fs.rdbuf())){}
void close() {
std::ostream::flush();
_fs.close();
}
void open(const std::string& filename, std::ios_base::openmode mode = std::ios_base::out, int level = Z_DEFAULT_COMPRESSION){
flush();
_fs.open(filename, mode | std::ios_base::binary);
std::ostream::operator=(std::ostream(new ostreambuf(_fs.rdbuf(), ostreambuf::default_buff_size, level)));
}
ofstream& flush() {
std::ostream::flush();
_fs.flush();
Expand Down

0 comments on commit f5c8c50

Please sign in to comment.