JayBeams  0.1
Another project to have fun coding.
fileio.cpp
Go to the documentation of this file.
1 #include "jb/fileio.hpp"
2 
3 #include <jb/filetype.hpp>
4 
5 #include <boost/iostreams/device/file.hpp>
6 #include <boost/iostreams/filter/gzip.hpp>
7 #include <boost/iostreams/filtering_stream.hpp>
8 
9 #include <fstream>
10 #include <iostream>
11 
13  boost::iostreams::filtering_ostream& out, std::string const& filename) {
14 
15  if (filename == "stdout") {
16  out.push(std::cout);
17  return;
18  }
19  if (jb::is_gz(filename)) {
20  out.push(boost::iostreams::gzip_compressor());
21  }
22  boost::iostreams::file_sink file(
23  filename, std::ios_base::out | std::ios_base::binary);
24  out.push(file);
25 }
26 
28  boost::iostreams::filtering_istream& in, std::string const& filename) {
29 
30  boost::iostreams::file_source file(
31  filename, std::ios_base::in | std::ios_base::binary);
32  if (jb::is_gz(filename)) {
33  in.push(boost::iostreams::gzip_decompressor());
34  }
35  in.push(file);
36 }
void open_output_file(boost::iostreams::filtering_ostream &out, std::string const &filename)
Open a file for writing.
Definition: fileio.cpp:12
void open_input_file(boost::iostreams::filtering_istream &in, std::string const &filename)
Open a file for reading.
Definition: fileio.cpp:27
bool is_gz(std::string const &filename)
Return true if the filename ends in .gz.
Definition: filetype.cpp:3