OmniSciDB  d2f719934e
 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 43 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 45 of file Archive.h.

References ar, parse_url(), and url_parts.

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

+ Here is the call graph for this function:

virtual Archive::~Archive ( )
inlinevirtual

Definition at line 94 of file Archive.h.

References ar.

94  {
95  if (ar) {
96  archive_read_close(ar);
97  }
98  if (ar) {
99  archive_read_free(ar);
100  }
101  ar = 0;
102  }
archive * ar
Definition: Archive.h:203

Member Function Documentation

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

Definition at line 104 of file Archive.h.

References ar, and to_string().

Referenced by read_data_block(), and read_next_header().

104  {
105  auto cstr = archive_error_string(ar);
106  return std::string("libarchive error: ") +
107  (cstr ? std::string(cstr) : std::to_string(err));
108  }
std::string to_string(char const *&&v)
archive * ar
Definition: Archive.h:203

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual int Archive::close ( )
inlinevirtual

Definition at line 146 of file Archive.h.

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

146 { 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 163 of file Archive.h.

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

163  {
164  return ((Archive*)client_data)->close();
165  }

+ Here is the caller graph for this function:

std::string Archive::entryName ( )
inline

Definition at line 198 of file Archive.h.

References entry.

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

Definition at line 132 of file Archive.h.

References ar.

Referenced by PosixFileArchive::read_data_block().

132 { return archive_filter_bytes(ar, -1); }
archive * ar
Definition: Archive.h:203

+ Here is the caller graph for this function:

virtual void Archive::init_for_read ( )
inlinevirtual

Reimplemented in S3Archive, and PosixFileArchive.

Definition at line 149 of file Archive.h.

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

149  {
150  // set libarchive callbacks
151  archive_read_open(ar, this, Archive::open, Archive::read, Archive::close);
152  }
archive * ar
Definition: Archive.h:203
virtual ptrdiff_t read(const void **buff)
Definition: Archive.h:147
virtual int close()
Definition: Archive.h:146
virtual int open()
Definition: Archive.h:145

+ Here is the call graph for this function:

virtual int Archive::open ( )
inlinevirtual

Definition at line 145 of file Archive.h.

Referenced by init_for_read().

145 { 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 159 of file Archive.h.

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

Definition at line 167 of file Archive.h.

References i.

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

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

+ Here is the caller graph for this function:

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

Definition at line 147 of file Archive.h.

Referenced by init_for_read().

147 { 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 155 of file Archive.h.

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

Reimplemented in PosixFileArchive.

Definition at line 121 of file Archive.h.

References ar, and archive_error().

Referenced by PosixFileArchive::read_data_block().

121  {
122  int rc;
123  switch (rc = archive_read_data_block(ar, buff, size, offset)) {
124  case ARCHIVE_EOF:
125  return false; // signal caller end of stream
126  case ARCHIVE_OK:
127  return true;
128  }
129  throw std::runtime_error(archive_error(rc));
130  }
archive * ar
Definition: Archive.h:203
virtual std::string archive_error(int err)
Definition: Archive.h:104

+ 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 110 of file Archive.h.

References ar, archive_error(), and entry.

Referenced by PosixFileArchive::read_next_header().

110  {
111  int rc;
112  switch (rc = archive_read_next_header(ar, &entry)) {
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:203
archive_entry * entry
Definition: Archive.h:204
virtual std::string archive_error(int err)
Definition: Archive.h:104

+ 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 196 of file Archive.h.

References i, and url_parts.

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

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

+ Here is the caller graph for this function:

Member Data Documentation

archive_entry* Archive::entry
protected

Definition at line 204 of file Archive.h.

Referenced by entryName(), and read_next_header().

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

Definition at line 201 of file Archive.h.

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

Definition at line 202 of file Archive.h.

Referenced by Archive(), and url_part().


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