OmniSciDB  ca0c39ec8f
 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:192
std::map< int, std::string > url_parts
Definition: Archive.h:191
std::string url
Definition: Archive.h:190
bool plain_text
Definition: Archive.h:194
static void parse_url(const std::string url, std::map< int, std::string > &url_parts)
Definition: Archive.h:156

+ 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:192

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:192

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual int Archive::close ( )
inlinevirtual

Definition at line 135 of file Archive.h.

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

135 { return ARCHIVE_OK; } // nop

+ Here is the caller graph for this function:

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

Definition at line 152 of file Archive.h.

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

152  {
153  return ((Archive*)client_data)->close();
154  }

+ Here is the caller graph for this function:

std::string Archive::entryName ( )
inline

Definition at line 187 of file Archive.h.

References entry.

187 { return std::string(archive_entry_pathname(entry)); }
archive_entry * entry
Definition: Archive.h:193
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 { return archive_filter_bytes(ar, -1); }
archive * ar
Definition: Archive.h:192

+ Here is the caller graph for this function:

virtual void Archive::init_for_read ( )
inlinevirtual

Reimplemented in S3Archive, and PosixFileArchive.

Definition at line 138 of file Archive.h.

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

138  {
139  // set libarchive callbacks
140  archive_read_open(ar, this, Archive::open, Archive::read, Archive::close);
141  }
archive * ar
Definition: Archive.h:192
virtual ptrdiff_t read(const void **buff)
Definition: Archive.h:136
virtual int close()
Definition: Archive.h:135
virtual int open()
Definition: Archive.h:134

+ Here is the call graph for this function:

virtual int Archive::open ( )
inlinevirtual

Definition at line 134 of file Archive.h.

Referenced by init_for_read().

134 { return ARCHIVE_OK; } // nop

+ Here is the caller graph for this function:

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

Definition at line 148 of file Archive.h.

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

Definition at line 156 of file Archive.h.

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

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

+ Here is the caller graph for this function:

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

Definition at line 136 of file Archive.h.

Referenced by init_for_read().

136 { return 0; } // 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 144 of file Archive.h.

144  {
145  return ((Archive*)client_data)->read(buff);
146  }
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:192
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:192
archive_entry * entry
Definition: Archive.h:193
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 185 of file Archive.h.

References url_parts.

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

185 { return url_parts[i]; }
std::map< int, std::string > url_parts
Definition: Archive.h:191

+ Here is the caller graph for this function:

Member Data Documentation

archive_entry* Archive::entry
protected

Definition at line 193 of file Archive.h.

Referenced by entryName(), and read_next_header().

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

Definition at line 190 of file Archive.h.

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

Definition at line 191 of file Archive.h.

Referenced by Archive(), and url_part().


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