mirror of https://github.com/kiwix/libkiwix.git
exposed fileExist, getMimeTypeForFile and getFileCoontent functions
This commit is contained in:
parent
b7b385d87b
commit
30e4c549e4
|
@ -167,5 +167,32 @@ std::vector<std::string> split(const std::string& str, const std::string& delims
|
||||||
* @throw std::out_of_range if iso2 code is not known.
|
* @throw std::out_of_range if iso2 code is not known.
|
||||||
*/
|
*/
|
||||||
std::string converta2toa3(const std::string& a2code);
|
std::string converta2toa3(const std::string& a2code);
|
||||||
|
|
||||||
|
/** Extracts content from given file.
|
||||||
|
*
|
||||||
|
* This function provides content of a file provided it's path.
|
||||||
|
*
|
||||||
|
* @param path The absolute path provided in string format.
|
||||||
|
* @return Content of corresponding file in string format.
|
||||||
|
*/
|
||||||
|
std::string getFileContent(const std::string& path);
|
||||||
|
|
||||||
|
/** checks if file exists.
|
||||||
|
*
|
||||||
|
* This function returns boolean stating if file exists or not.
|
||||||
|
*
|
||||||
|
* @param path The absolute path provided in string format.
|
||||||
|
* @return Boolean representing if file exists or not.
|
||||||
|
*/
|
||||||
|
bool fileExists(const std::string& path);
|
||||||
|
|
||||||
|
/** provides mimetype from filename.
|
||||||
|
*
|
||||||
|
* This function provides mimetype from file-name.
|
||||||
|
*
|
||||||
|
* @param filename string containing filename.
|
||||||
|
* @return mimetype from filename in string format.
|
||||||
|
*/
|
||||||
|
std::string getMimeTypeForFile(const std::string& filename);
|
||||||
}
|
}
|
||||||
#endif // KIWIX_TOOLS_H
|
#endif // KIWIX_TOOLS_H
|
||||||
|
|
|
@ -269,7 +269,7 @@ std::string getFileSizeAsString(const std::string& path)
|
||||||
return convert.str();
|
return convert.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getFileContent(const std::string& path)
|
std::string kiwix::getFileContent(const std::string& path)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
auto wpath = Utf8ToWide(path);
|
auto wpath = Utf8ToWide(path);
|
||||||
|
@ -302,7 +302,7 @@ std::string getFileContent(const std::string& path)
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileExists(const std::string& path)
|
bool kiwix::fileExists(const std::string& path)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return PathFileExistsW(Utf8ToWide(path).c_str());
|
return PathFileExistsW(Utf8ToWide(path).c_str());
|
||||||
|
@ -505,7 +505,7 @@ static std::map<std::string, std::string> extMimeTypes = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Try to get the mimeType from the file extension */
|
/* Try to get the mimeType from the file extension */
|
||||||
std::string getMimeTypeForFile(const std::string& filename)
|
std::string kiwix::getMimeTypeForFile(const std::string& filename)
|
||||||
{
|
{
|
||||||
std::string mimeType = "text/plain";
|
std::string mimeType = "text/plain";
|
||||||
auto pos = filename.find_last_of(".");
|
auto pos = filename.find_last_of(".");
|
||||||
|
|
|
@ -29,13 +29,10 @@ std::wstring Utf8ToWide(const std::string& str);
|
||||||
|
|
||||||
unsigned int getFileSize(const std::string& path);
|
unsigned int getFileSize(const std::string& path);
|
||||||
std::string getFileSizeAsString(const std::string& path);
|
std::string getFileSizeAsString(const std::string& path);
|
||||||
std::string getFileContent(const std::string& path);
|
|
||||||
bool fileExists(const std::string& path);
|
|
||||||
bool makeDirectory(const std::string& path);
|
bool makeDirectory(const std::string& path);
|
||||||
std::string makeTmpDirectory();
|
std::string makeTmpDirectory();
|
||||||
bool copyFile(const std::string& sourcePath, const std::string& destPath);
|
bool copyFile(const std::string& sourcePath, const std::string& destPath);
|
||||||
bool writeTextFile(const std::string& path, const std::string& content);
|
bool writeTextFile(const std::string& path, const std::string& content);
|
||||||
std::string getMimeTypeForFile(const std::string& filename);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue