From 78de13de299fb569e693c0ff6e208b2423ae70f5 Mon Sep 17 00:00:00 2001 From: Manan Jethwani <2019282@iiitdmj.ac.in> Date: Wed, 6 Oct 2021 17:50:18 +0530 Subject: [PATCH] exposed fileExist, getMimeTypeForFile and getFileCoontent functions --- include/tools.h | 27 +++++++++++++++++++++++++++ src/tools/pathTools.cpp | 6 +++--- src/tools/pathTools.h | 3 --- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/tools.h b/include/tools.h index 150348929..967e22ed3 100644 --- a/include/tools.h +++ b/include/tools.h @@ -167,5 +167,32 @@ std::vector split(const std::string& str, const std::string& delims * @throw std::out_of_range if iso2 code is not known. */ 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 diff --git a/src/tools/pathTools.cpp b/src/tools/pathTools.cpp index d66aa6f8b..b4fabf450 100644 --- a/src/tools/pathTools.cpp +++ b/src/tools/pathTools.cpp @@ -269,7 +269,7 @@ std::string getFileSizeAsString(const std::string& path) return convert.str(); } -std::string getFileContent(const std::string& path) +std::string kiwix::getFileContent(const std::string& path) { #ifdef _WIN32 auto wpath = Utf8ToWide(path); @@ -302,7 +302,7 @@ std::string getFileContent(const std::string& path) return content; } -bool fileExists(const std::string& path) +bool kiwix::fileExists(const std::string& path) { #ifdef _WIN32 return PathFileExistsW(Utf8ToWide(path).c_str()); @@ -505,7 +505,7 @@ static std::map extMimeTypes = { }; /* 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"; auto pos = filename.find_last_of("."); diff --git a/src/tools/pathTools.h b/src/tools/pathTools.h index d8450b83f..82c2a8678 100644 --- a/src/tools/pathTools.h +++ b/src/tools/pathTools.h @@ -29,13 +29,10 @@ std::wstring Utf8ToWide(const std::string& str); unsigned int getFileSize(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); std::string makeTmpDirectory(); bool copyFile(const std::string& sourcePath, const std::string& destPath); bool writeTextFile(const std::string& path, const std::string& content); -std::string getMimeTypeForFile(const std::string& filename); #endif