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

Static Public Member Functions

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

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

Detailed Description

Definition at line 29 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 31 of file Archive.h.

References ar, parse_url(), and url_parts.

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

+ Here is the call graph for this function:

virtual Archive::~Archive ( )
inlinevirtual

Definition at line 80 of file Archive.h.

References ar.

80  {
81  if (ar) {
82  archive_read_close(ar);
83  }
84  if (ar) {
85  archive_read_free(ar);
86  }
87  ar = 0;
88  }
archive * ar
Definition: Archive.h:188

Member Function Documentation

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

Definition at line 90 of file Archive.h.

References ar, and to_string().

Referenced by read_data_block(), and read_next_header().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual int Archive::close ( )
inlinevirtual

Definition at line 133 of file Archive.h.

Referenced by init_for_read().

133 { 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 150 of file Archive.h.

150  {
151  return ((Archive*)client_data)->close();
152  }
virtual int64_t Archive::get_position_compressed ( ) const
inlinevirtual

Definition at line 119 of file Archive.h.

References ar.

Referenced by PosixFileArchive::read_data_block().

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

+ Here is the caller graph for this function:

virtual void Archive::init_for_read ( )
inlinevirtual

Reimplemented in S3Archive, and PosixFileArchive.

Definition at line 136 of file Archive.h.

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

136  {
137  // set libarchive callbacks
138  archive_read_open(ar, this, Archive::open, Archive::read, Archive::close);
139  }
virtual ssize_t read(const void **buff)
Definition: Archive.h:134
archive * ar
Definition: Archive.h:188
virtual int close()
Definition: Archive.h:133
virtual int open()
Definition: Archive.h:132

+ Here is the call graph for this function:

virtual int Archive::open ( )
inlinevirtual

Definition at line 132 of file Archive.h.

Referenced by init_for_read().

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

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

Definition at line 154 of file Archive.h.

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

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

+ Here is the caller graph for this function:

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

Definition at line 134 of file Archive.h.

Referenced by init_for_read().

134 { return 0; } // nop

+ Here is the caller graph for this function:

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

Definition at line 142 of file Archive.h.

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

Reimplemented in PosixFileArchive.

Definition at line 108 of file Archive.h.

References ar, and archive_error().

Referenced by PosixFileArchive::read_data_block().

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

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

References ar, and archive_error().

Referenced by PosixFileArchive::read_next_header().

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

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

References url_parts.

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

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

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 186 of file Archive.h.

Referenced by S3Archive::init_for_read().

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

Definition at line 187 of file Archive.h.

Referenced by Archive(), and url_part().


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