25#ifndef JOIN_CORE_FILESYSTEM_HPP
26#define JOIN_CORE_FILESYSTEM_HPP
41 inline std::string
base (
const std::string& filepath)
43 size_t pos = filepath.rfind (
"/");
45 if (pos == std::string::npos)
48 return filepath.substr (0, pos + 1);
56 inline std::string
filename (
const std::string& filepath)
58 size_t pos = filepath.rfind (
"/");
60 if (pos == std::string::npos)
63 return filepath.substr (pos + 1);
71 inline std::string
extension (
const std::string& filepath)
73 size_t pos = filepath.rfind (
".");
75 if (pos == std::string::npos)
78 return filepath.substr (pos + 1);
86 inline std::string
mime (
const std::string& filepath)
92 else if (suffix ==
"html")
94 else if (suffix ==
"css")
96 else if (suffix ==
"less")
98 else if (suffix ==
"js")
99 mime =
"application/javascript";
100 else if (suffix ==
"xml")
102 else if (suffix ==
"json")
103 mime =
"application/json";
104 else if (suffix ==
"txt")
106 else if (suffix ==
"properties")
107 mime =
"text/x-java-properties";
108 else if (suffix ==
"jpg")
110 else if (suffix ==
"jpeg")
112 else if (suffix ==
"png")
114 else if (suffix ==
"bmp")
116 else if (suffix ==
"gif")
118 else if (suffix ==
"jpe")
120 else if (suffix ==
"xbm")
122 else if (suffix ==
"tiff")
124 else if (suffix ==
"tif")
126 else if (suffix ==
"ico")
127 mime =
"image/x-icon";
128 else if (suffix ==
"svg")
129 mime =
"image/svg+xml";
130 else if (suffix ==
"pdf")
131 mime =
"application/pdf";
132 else if (suffix ==
"mp3")
134 else if (suffix ==
"mp4")
136 else if (suffix ==
"zip")
137 mime =
"application/zip";
138 else if (suffix ==
"bz2")
139 mime =
"application/x-bzip";
140 else if (suffix ==
"tbz2")
141 mime =
"application/x-bzip";
142 else if (suffix ==
"tb2")
143 mime =
"application/x-bzip";
144 else if (suffix ==
"gz")
145 mime =
"application/x-gzip";
146 else if (suffix ==
"gzip")
147 mime =
"application/x-gzip";
148 else if (suffix ==
"tar")
149 mime =
"application/x-tar";
150 else if (suffix ==
"rar")
151 mime =
"application/x-rar-compressed";
152 else if (suffix ==
"tpl")
153 mime =
"application/vnd.groove-tool-template";
154 else if (suffix ==
"woff")
155 mime =
"application/font-woff";
156 else if (suffix ==
"woff2")
157 mime =
"application/font-woff2";
159 mime =
"application/octet-stream";
169 inline bool exists (
const std::string& filepath)
172 return stat (filepath.c_str (), &status) == 0;
Definition acceptor.hpp:32
bool exists(const std::string &filepath)
check if the file specified exists.
Definition filesystem.hpp:169
std::string base(const std::string &filepath)
get base path of the specified file.
Definition filesystem.hpp:41
std::string extension(const std::string &filepath)
get extension of the file specified.
Definition filesystem.hpp:71
std::string filename(const std::string &filepath)
get file name of the specified file.
Definition filesystem.hpp:56
std::string mime(const std::string &filepath)
get mime type of the specified file.
Definition filesystem.hpp:86