Skip to content

Commit

Permalink
exposed fileExist, getMimeTypeForFile and getFileCoontent functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MananJethwani committed Oct 6, 2021
1 parent 6e0ddb2 commit fbc8272
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
27 changes: 27 additions & 0 deletions include/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
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
6 changes: 3 additions & 3 deletions src/tools/pathTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -505,7 +505,7 @@ static std::map<std::string, std::string> 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(".");
Expand Down
3 changes: 0 additions & 3 deletions src/tools/pathTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fbc8272

Please sign in to comment.