OmniSciDB  04ee39c94c
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

const size_t buf_size = (1 << 20)
 
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 26 of file PosixFileArchive.h.

Constructor & Destructor Documentation

◆ PosixFileArchive()

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

Definition at line 30 of file PosixFileArchive.h.

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

31  : Archive(url, plain_text) {
32  // some well-known file.exts imply plain text
33  if (!this->plain_text) {
34  this->plain_text = boost::filesystem::extension(url_part(5)) == ".csv" ||
35  boost::filesystem::extension(url_part(5)) == ".tsv" ||
36  boost::filesystem::extension(url_part(5)) == ".txt" ||
37  boost::filesystem::extension(url_part(5)) == "";
38  }
39 
40  if (this->plain_text) {
41  buf = new char[buf_size];
42  }
43 
44  init_for_read();
45  }
const size_t buf_size
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::~PosixFileArchive ( )
inlineoverride

Definition at line 47 of file PosixFileArchive.h.

References buf, and fp.

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

Member Function Documentation

◆ init_for_read()

void PosixFileArchive::init_for_read ( )
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 56 of file PosixFileArchive.h.

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

Referenced by PosixFileArchive().

56  {
57  auto file_path = url_part(5);
58  if (plain_text) {
59  if (nullptr == (fp = fopen(file_path.c_str(), "r"))) {
60  throw std::runtime_error(std::string("fopen(") + file_path +
61  "): " + strerror(errno));
62  }
63  } else {
64  if (ARCHIVE_OK != archive_read_open_filename(ar, file_path.c_str(), 1 << 16)) {
65  throw std::runtime_error(std::string("fopen(") + file_path +
66  "): " + strerror(errno));
67  }
68  }
69  }
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:

◆ read_data_block()

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

Reimplemented from Archive.

Definition at line 79 of file PosixFileArchive.h.

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

79  {
80  if (plain_text) {
81  size_t nread;
82  if (0 >= (nread = fread(buf, 1, buf_size, fp))) {
83  return false;
84  }
85  *buff = buf;
86  *size = nread;
87  *offset = ftell(fp);
88  return true;
89  } else {
90  // need original (compressed) offset for row estimation of compressed files
91  auto ret = Archive::read_data_block(buff, size, offset);
93  return ret;
94  }
95  }
virtual bool read_data_block(const void **buff, size_t *size, int64_t *offset)
Definition: Archive.h:108
const size_t buf_size
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:

◆ read_next_header()

bool PosixFileArchive::read_next_header ( )
inlineoverridevirtual

Reimplemented from Archive.

Definition at line 71 of file PosixFileArchive.h.

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

71  {
72  if (plain_text) {
73  return !feof(fp);
74  } else {
76  }
77  }
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

◆ buf

char* PosixFileArchive::buf = nullptr
private

Definition at line 98 of file PosixFileArchive.h.

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

◆ buf_size

const size_t PosixFileArchive::buf_size = (1 << 20)
private

Definition at line 27 of file PosixFileArchive.h.

Referenced by PosixFileArchive().

◆ fp

FILE* PosixFileArchive::fp = nullptr
private

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