File size: 813 Bytes
158b61b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include "FileStream.h"

#include <stdexcept>
#include "GzFileBuf.h"

using namespace std;

namespace
{
bool IsGzipFile(const std::string &filename)
{
  return filename.size() > 3 &&
         filename.substr(filename.size() - 3, 3) == ".gz";
}
} // namespace

inputfilestream::inputfilestream(const std::string &filePath)
  : std::istream(0), m_streambuf(0), m_is_good(false)
{
  // check if file is readable
  std::filebuf* fb = new std::filebuf();
  m_is_good = (fb->open(filePath.c_str(), std::ios::in) != NULL);

  if (IsGzipFile(filePath)) {
    fb->close();
    delete fb;
    m_streambuf = new GzFileBuf(filePath.c_str());
  } else {
    m_streambuf = fb;
  }
  this->init(m_streambuf);
}

inputfilestream::~inputfilestream()
{
  delete m_streambuf;
  m_streambuf = 0;
}

void inputfilestream::close()
{
}