OmniSciDB  b24e664e58
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PosixFileArchive Class Reference

#include <PosixFileArchive.h>

+ Inheritance diagram for PosixFileArchive:
+ Collaboration diagram for PosixFileArchive:

Public Member Functions

 PosixFileArchive (const std::string url, const bool plain_text)
 
 ~PosixFileArchive () override
 
void init_for_read () override
 
bool read_next_header () override
 
bool read_data_block (const void **buff, size_t *size, int64_t *offset) override
 
- Public Member Functions inherited from Archive
 Archive (const std::string url, const bool plain_text)
 
virtual ~Archive ()
 
virtual std::string archive_error (int err)
 
virtual int64_t get_position_compressed () const
 
virtual int open ()
 
virtual int close ()
 
virtual ssize_t read (const void **buff)
 
const std::string url_part (const int i)
 

Private Attributes

char * buf = nullptr
 
FILE * fp = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Archive
static ssize_t read (struct archive *a, void *client_data, const void **buff)
 
static int open (struct archive *a, void *client_data)
 
static int close (struct archive *a, void *client_data)
 
static void parse_url (const std::string url, std::map< int, std::string > &url_parts)
 
- Protected Attributes inherited from Archive
std::string url
 
std::map< int, std::string > url_parts
 
archive * ar = 0
 
bool plain_text
 

Detailed Description

Definition at line 29 of file PosixFileArchive.h.

Constructor & Destructor Documentation

PosixFileArchive::PosixFileArchive ( const std::string  url,
const bool  plain_text 
)
inline

Definition at line 31 of file PosixFileArchive.h.

References buf, g_archive_read_buf_size, init_for_read(), and Archive::url_part().

32  : Archive(url, plain_text) {
33  // some well-known file.exts imply plain text
34  if (!this->plain_text) {
35  this->plain_text = boost::filesystem::extension(url_part(5)) == ".csv" ||
36  boost::filesystem::extension(url_part(5)) == ".tsv" ||
37  boost::filesystem::extension(url_part(5)) == ".txt" ||
38  boost::filesystem::extension(url_part(5)) == "";
39  }
40 
41  if (this->plain_text) {
42  buf = new char[g_archive_read_buf_size];
43  }
44 
45  init_for_read();
46  }
size_t g_archive_read_buf_size
Definition: Importer.cpp:75
const std::string url_part(const int i)
Definition: Archive.h:183
void init_for_read() override
std::string url
Definition: Archive.h:186
bool plain_text
Definition: Archive.h:189
Archive(const std::string url, const bool plain_text)
Definition: Archive.h:31

+ Here is the call graph for this function:

PosixFileArchive::~PosixFileArchive ( )
inlineoverride

Definition at line 48 of file PosixFileArchive.h.

References buf, and fp.

48  {
49  if (fp) {
50  fclose(fp);
51  }
52  if (buf) {
53  delete[] buf;
54  }
55  }

Member Function Documentation

void PosixFileArchive::init_for_read ( )
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 57 of file PosixFileArchive.h.

References Archive::ar, fp, Archive::plain_text, and Archive::url_part().

Referenced by PosixFileArchive().

57  {
58  auto file_path = url_part(5);
59  if (plain_text) {
60  if (nullptr == (fp = fopen(file_path.c_str(), "r"))) {
61  throw std::runtime_error(std::string("fopen(") + file_path +
62  "): " + strerror(errno));
63  }
64  } else {
65  if (ARCHIVE_OK != archive_read_open_filename(ar, file_path.c_str(), 1 << 16)) {
66  throw std::runtime_error(std::string("fopen(") + file_path +
67  "): " + strerror(errno));
68  }
69  }
70  }
archive * ar
Definition: Archive.h:188
const std::string url_part(const int i)
Definition: Archive.h:183
bool plain_text
Definition: Archive.h:189

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool PosixFileArchive::read_data_block ( const void **  buff,
size_t *  size,
int64_t *  offset 
)
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 80 of file PosixFileArchive.h.

References buf, fp, g_archive_read_buf_size, Archive::get_position_compressed(), Archive::plain_text, and Archive::read_data_block().

80  {
81  if (plain_text) {
82  size_t nread;
83  if (0 >= (nread = fread(buf, 1, g_archive_read_buf_size, fp))) {
84  return false;
85  }
86  *buff = buf;
87  *size = nread;
88  *offset = ftell(fp);
89  return true;
90  } else {
91  // need original (compressed) offset for row estimation of compressed files
92  auto ret = Archive::read_data_block(buff, size, offset);
94  return ret;
95  }
96  }
virtual bool read_data_block(const void **buff, size_t *size, int64_t *offset)
Definition: Archive.h:108
size_t g_archive_read_buf_size
Definition: Importer.cpp:75
virtual int64_t get_position_compressed() const
Definition: Archive.h:119
bool plain_text
Definition: Archive.h:189

+ Here is the call graph for this function:

bool PosixFileArchive::read_next_header ( )
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 72 of file PosixFileArchive.h.

References fp, Archive::plain_text, and Archive::read_next_header().

72  {
73  if (plain_text) {
74  return !feof(fp);
75  } else {
77  }
78  }
virtual bool read_next_header()
Definition: Archive.h:96
bool plain_text
Definition: Archive.h:189

+ Here is the call graph for this function:

Member Data Documentation

char* PosixFileArchive::buf = nullptr
private

Definition at line 99 of file PosixFileArchive.h.

Referenced by PosixFileArchive(), read_data_block(), and ~PosixFileArchive().

FILE* PosixFileArchive::fp = nullptr
private

The documentation for this class was generated from the following file: