You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

  1. //
  2. // Created by zhaohe on 19-5-31.
  3. //
  4. #pragma once
  5. #include <pthread.h>
  6. #include <unistd.h>
  7. #include <fstream>
  8. #include <iostream>
  9. #include <list>
  10. #include <map>
  11. #include <memory>
  12. #include <set>
  13. #include <sstream>
  14. #include <string>
  15. #include <vector>
  16. #include "iflytopcpp/core/spdlogfactory/logger.hpp"
  17. namespace iflytop {
  18. namespace core {
  19. using namespace std;
  20. class FileUtils {
  21. ENABLE_LOGGER(FileUtils);
  22. public:
  23. // judegefile
  24. bool exist(const string &path);
  25. bool isDirectory(const string &path);
  26. // bool delFile(const string &filePath);
  27. // mkfile
  28. bool makeDirIfNoExist(const string &path);
  29. // readfile
  30. string readFileAsString(const string &filePath);
  31. std::vector<char> readFileAsBuffer(const string &filePath);
  32. // write file
  33. bool writeToFile(const string &fileName, const string &buf);
  34. bool writeToFile(const string &fileName, const char *buf, size_t size);
  35. shared_ptr<ofstream> openTrunc(const string &fileName);
  36. // filename operat
  37. // bool getRepetitionFileName(string fileName, string suffix, string &outfilename, int maxNum = -1);
  38. // bool getRepetitionDirName(string fileName, string &outfilename, int maxNum = -1);
  39. };
  40. } // namespace core
  41. } // namespace iflytop