OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Archive Class Reference

#include <Archive.h>

+ Inheritance diagram for Archive:
+ Collaboration diagram for Archive:

Public Member Functions

 Archive (const std::string url, const bool plain_text)
 
virtual ~Archive ()
 
virtual std::string archive_error (int err)
 
virtual bool read_next_header ()
 
virtual bool read_data_block (const void **buff, size_t *size, int64_t *offset)
 
virtual int64_t get_position_compressed () const
 
virtual int open ()
 
virtual int close ()
 
virtual ptrdiff_t read (const void **buff)
 
virtual void init_for_read ()
 
const std::string url_part (const int i)
 
std::string entryName ()
 

Static Public Member Functions

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

std::string url
 
std::map< int, std::string > url_parts
 
archive * ar = 0
 
archive_entry * entry
 
bool plain_text
 

Detailed Description

Definition at line 32 of file Archive.h.

Constructor & Destructor Documentation

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

! LIBARCHIVE_ENABLE_ALL may trigger exception "detect_column_types error: libarchive error: Missing type keyword in mtree specification" ! on ridiculously simple raw data

Definition at line 34 of file Archive.h.

References ar, parse_url(), and url_parts.

37 
38  if (0 == (ar = archive_read_new())) {
39  throw std::runtime_error(std::string("archive_read_new failed!"));
40  }
41 
46 //#define LIBARCHIVE_ENABLE_ALL
47 #ifdef LIBARCHIVE_ENABLE_ALL
48  // this increases ~800kb code size
49  archive_read_support_format_all(ar);
50  archive_read_support_filter_all(ar);
51  archive_read_support_format_raw(ar);
52 #else
53  // list supported formats to bypass the mtree exception
54  archive_read_support_format_ar(ar);
55  archive_read_support_format_cpio(ar);
56  archive_read_support_format_empty(ar);
57  archive_read_support_format_lha(ar);
58  archive_read_support_format_tar(ar);
59  archive_read_support_format_xar(ar);
60  archive_read_support_format_7zip(ar);
61  archive_read_support_format_cab(ar);
62  archive_read_support_format_rar(ar);
63  archive_read_support_format_iso9660(ar);
64  archive_read_support_format_zip(ar);
65 
66  archive_read_support_filter_bzip2(ar);
67  archive_read_support_filter_compress(ar);
68  archive_read_support_filter_gzip(ar);
69  archive_read_support_filter_lzip(ar);
70  archive_read_support_filter_lzma(ar);
71  archive_read_support_filter_xz(ar);
72  archive_read_support_filter_uu(ar);
73  archive_read_support_filter_rpm(ar);
74  archive_read_support_filter_lrzip(ar);
75  archive_read_support_filter_lzop(ar);
76  archive_read_support_filter_grzip(ar);
77 #endif
78  // libarchive assumes archive formats, so without this bzip2 and gzip won't work!
79  // see related issue at https://github.com/libarchive/libarchive/issues/586
80  archive_read_support_format_raw(ar);
81  }
archive * ar
Definition: Archive.h:204
std::map< int, std::string > url_parts
Definition: Archive.h:203
std::string url
Definition: Archive.h:202
bool plain_text
Definition: Archive.h:206
static void parse_url(const std::string url, std::map< int, std::string > &url_parts)
Definition: Archive.h:164

+ Here is the call graph for this function:

virtual Archive::~Archive ( )
inlinevirtual

Definition at line 83 of file Archive.h.

References ar.

83  {
84  if (ar) {
85  archive_read_close(ar);
86  }
87  if (ar) {
88  archive_read_free(ar);
89  }
90  ar = 0;
91  }
archive * ar
Definition: Archive.h:204

Member Function Documentation

virtual std::string Archive::archive_error ( int  err)
inlinevirtual

Definition at line 93 of file Archive.h.

References ar, and to_string().

Referenced by read_data_block(), and read_next_header().

93  {
94  auto cstr = archive_error_string(ar);
95  return std::string("libarchive error: ") +
96  (cstr ? std::string(cstr) : std::to_string(err));
97  }
std::string to_string(char const *&&v)
archive * ar
Definition: Archive.h:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual int Archive::close ( )
inlinevirtual

Definition at line 139 of file Archive.h.

Referenced by heavydb.connection.Connection::__del__(), heavydb.cursor.Cursor::__exit__(), heavydb.connection.Connection::__exit__(), and init_for_read().

139  {
140  return ARCHIVE_OK;
141  } // nop

+ Here is the caller graph for this function:

static int Archive::close ( struct archive *  a,
void *  client_data 
)
inlinestatic

Definition at line 160 of file Archive.h.

Referenced by heavydb.connection.Connection::__del__(), heavydb.cursor.Cursor::__exit__(), and heavydb.connection.Connection::__exit__().

160  {
161  return ((Archive*)client_data)->close();
162  }

+ Here is the caller graph for this function:

std::string Archive::entryName ( )
inline

Definition at line 197 of file Archive.h.

References entry.

197  {
198  return std::string(archive_entry_pathname(entry));
199  }
archive_entry * entry
Definition: Archive.h:205
virtual int64_t Archive::get_position_compressed ( ) const
inlinevirtual

Definition at line 121 of file Archive.h.

References ar.

Referenced by PosixFileArchive::read_data_block().

121  {
122  return archive_filter_bytes(ar, -1);
123  }
archive * ar
Definition: Archive.h:204

+ Here is the caller graph for this function:

virtual void Archive::init_for_read ( )
inlinevirtual

Reimplemented in S3Archive, and PosixFileArchive.

Definition at line 146 of file Archive.h.

References ar, close(), open(), and read().

146  {
147  // set libarchive callbacks
148  archive_read_open(ar, this, Archive::open, Archive::read, Archive::close);
149  }
archive * ar
Definition: Archive.h:204
virtual ptrdiff_t read(const void **buff)
Definition: Archive.h:142
virtual int close()
Definition: Archive.h:139
virtual int open()
Definition: Archive.h:136

+ Here is the call graph for this function:

virtual int Archive::open ( )
inlinevirtual

Definition at line 136 of file Archive.h.

Referenced by init_for_read().

136  {
137  return ARCHIVE_OK;
138  } // nop

+ Here is the caller graph for this function:

static int Archive::open ( struct archive *  a,
void *  client_data 
)
inlinestatic

Definition at line 156 of file Archive.h.

156  {
157  return ((Archive*)client_data)->open();
158  }
static void Archive::parse_url ( const std::string  url,
std::map< int, std::string > &  url_parts 
)
inlinestatic

Definition at line 164 of file Archive.h.

Referenced by Archive(), and import_export::DataStreamSink::import_compressed().

164  {
165  /*
166  input example: http://localhost.com/path\?hue\=br\#cool
167  output should be:
168  0: http://localhost.com/path?hue=br#cool
169  1: http:
170  2: http
171  3: //localhost.com
172  4: localhost.com
173  5: /path
174  6: ?hue=br
175  7: hue=br
176  8: #cool
177  9: cool
178  */
179  std::smatch sm;
180  std::regex url_regex(R"(^(([^:\/?#]+):)?(//([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)",
181  std::regex::extended);
182  if (!std::regex_match(url, sm, url_regex)) {
183  throw std::runtime_error(std::string("malformed url: ") + url);
184  }
185 
186  // sm is only an iterator over local 'url'
187  // so have to copy out matched parts
188  for (size_t i = 0; i < sm.size(); i++) {
189  url_parts[i] = sm[i].str();
190  }
191  }
std::map< int, std::string > url_parts
Definition: Archive.h:203
std::string url
Definition: Archive.h:202

+ Here is the caller graph for this function:

virtual ptrdiff_t Archive::read ( const void **  buff)
inlinevirtual

Definition at line 142 of file Archive.h.

Referenced by init_for_read().

142  {
143  return 0;
144  } // nop

+ Here is the caller graph for this function:

static ptrdiff_t Archive::read ( struct archive *  a,
void *  client_data,
const void **  buff 
)
inlinestatic

Definition at line 152 of file Archive.h.

152  {
153  return ((Archive*)client_data)->read(buff);
154  }
virtual bool Archive::read_data_block ( const void **  buff,
size_t *  size,
int64_t *  offset 
)
inlinevirtual

Reimplemented in PosixFileArchive.

Definition at line 110 of file Archive.h.

References ar, and archive_error().

Referenced by PosixFileArchive::read_data_block().

110  {
111  int rc;
112  switch (rc = archive_read_data_block(ar, buff, size, offset)) {
113  case ARCHIVE_EOF:
114  return false; // signal caller end of stream
115  case ARCHIVE_OK:
116  return true;
117  }
118  throw std::runtime_error(archive_error(rc));
119  }
archive * ar
Definition: Archive.h:204
virtual std::string archive_error(int err)
Definition: Archive.h:93

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual bool Archive::read_next_header ( )
inlinevirtual

Reimplemented in PosixFileArchive.

Definition at line 99 of file Archive.h.

References ar, archive_error(), and entry.

Referenced by PosixFileArchive::read_next_header().

99  {
100  int rc;
101  switch (rc = archive_read_next_header(ar, &entry)) {
102  case ARCHIVE_EOF:
103  return false; // signal caller end of stream
104  case ARCHIVE_OK:
105  return true;
106  }
107  throw std::runtime_error(archive_error(rc));
108  }
archive * ar
Definition: Archive.h:204
archive_entry * entry
Definition: Archive.h:205
virtual std::string archive_error(int err)
Definition: Archive.h:93

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string Archive::url_part ( const int  i)
inline

Definition at line 193 of file Archive.h.

References url_parts.

Referenced by PosixFileArchive::init_for_read(), and PosixFileArchive::PosixFileArchive().

193  {
194  return url_parts[i];
195  }
std::map< int, std::string > url_parts
Definition: Archive.h:203

+ Here is the caller graph for this function:

Member Data Documentation

archive_entry* Archive::entry
protected

Definition at line 205 of file Archive.h.

Referenced by entryName(), and read_next_header().

bool Archive::plain_text
protected
std::string Archive::url
protected

Definition at line 202 of file Archive.h.

std::map<int, std::string> Archive::url_parts
protected

Definition at line 203 of file Archive.h.

Referenced by Archive(), and url_part().


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