OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 ptrdiff_t read (const void **buff)
 
const std::string url_part (const int i)
 
std::string entryName ()
 

Private Attributes

char * buf = nullptr
 
FILE * fp = nullptr
 

Additional Inherited Members

- Static Public Member Functions inherited from Archive
static ptrdiff_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
 
archive_entry * entry
 
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  auto const ext = boost::filesystem::path(url_part(5)).extension();
36  this->plain_text = ext == ".csv" || ext == ".tsv" || ext == ".txt" || ext == "";
37  }
38 
39  if (this->plain_text) {
40  buf = new char[g_archive_read_buf_size];
41  }
42 
43  init_for_read();
44  }
size_t g_archive_read_buf_size
Definition: Importer.cpp:109
const std::string url_part(const int i)
Definition: Archive.h:193
void init_for_read() override
std::string url
Definition: Archive.h:202
bool plain_text
Definition: Archive.h:206
Archive(const std::string url, const bool plain_text)
Definition: Archive.h:34

+ Here is the call graph for this function:

PosixFileArchive::~PosixFileArchive ( )
inlineoverride

Definition at line 46 of file PosixFileArchive.h.

References buf, and fp.

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

Member Function Documentation

void PosixFileArchive::init_for_read ( )
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 55 of file PosixFileArchive.h.

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

Referenced by PosixFileArchive().

55  {
56  auto file_path = url_part(5);
57  if (plain_text) {
58  if (nullptr == (fp = fopen(file_path.c_str(), "r"))) {
59  throw std::runtime_error(std::string("fopen(") + file_path +
60  "): " + strerror(errno));
61  }
62  } else {
63  if (ARCHIVE_OK != archive_read_open_filename(ar, file_path.c_str(), 1 << 16)) {
64  throw std::runtime_error(std::string("fopen(") + file_path +
65  "): " + strerror(errno));
66  }
67  }
68  }
archive * ar
Definition: Archive.h:204
::FILE * fopen(const char *filename, const char *mode)
Definition: heavyai_fs.cpp:74
const std::string url_part(const int i)
Definition: Archive.h:193
bool plain_text
Definition: Archive.h:206

+ 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 78 of file PosixFileArchive.h.

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

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

+ Here is the call graph for this function:

bool PosixFileArchive::read_next_header ( )
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 70 of file PosixFileArchive.h.

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

70  {
71  if (plain_text) {
72  return !feof(fp);
73  } else {
75  }
76  }
virtual bool read_next_header()
Definition: Archive.h:99
bool plain_text
Definition: Archive.h:206

+ Here is the call graph for this function:

Member Data Documentation

char* PosixFileArchive::buf = nullptr
private

Definition at line 97 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: