OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
file_type.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #include <regex>
24 #include <vector>
25 
26 #include <boost/filesystem.hpp>
27 
28 #include "Shared/file_type.h"
29 
30 #include "Shared/misc.h"
31 
32 namespace shared {
33 
34 bool is_compressed_mime_type(const std::string& mime_type) {
35  // strips possible vender (vnd.), personal (prs.) & unregistered (x.) prefixes from the
36  // mime-type
37  static const std::regex mime_prefix("\\/(vnd|prs|x)(\\.|-)");
38  const auto mime_type_no_prefix = std::regex_replace(mime_type, mime_prefix, "/");
39  static const std::vector<std::string> compressed_types = {"application/7z-compressed",
40  "application/bzip",
41  "application/bzip2",
42  "application/gzip",
43  "application/rar",
44  "application/tar",
45  "application/zip"};
46  return shared::contains(compressed_types, mime_type_no_prefix);
47 }
48 
49 bool is_compressed_file_extension(const std::string& location) {
50  static const std::vector<std::string> compressed_exts = {
51  ".7z", ".bz", ".bz2", ".gz", ".rar", ".tar", ".zip", ".tgz"};
52  return shared::contains(compressed_exts,
53  boost::filesystem::path(location).extension().string());
54 }
55 
56 } // namespace shared
bool contains(const T &container, const U &element)
Definition: misc.h:204
bool is_compressed_mime_type(const std::string &mime_type)
Definition: file_type.cpp:34
shared utility for mime-types
bool is_compressed_file_extension(const std::string &location)
Definition: file_type.cpp:49